Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Module extend module

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-14-2018, 11:23 PM
 
Grempels Grempels is offline
    
Join Date: Aug 2015
Location: Bucharest, Romania
Posts: -1
 

Question Module extend module

Hi, is it possible to create a module that extend another module?
I wanna extend ProductVariant model from ProductVariants module and i keep getting :

Class "XLite\Module\Grempels\Restfully\Model\ProductVari ant" sub class of "XLite\Module\XC\ProductVariants\Model\ProductVari antAbstract" is not a valid entity or mapped super class.

PHP Code:
namespace XLite\Module\Grempels\Restfully\Model;

class 
ProductVariant extends \XLite\Module\XC\ProductVariants\Model\ProductVariant implements \XLite\Base\IDecorator
{
    public function 
getProductId()
    {
        return 
$this->getProduct()->getProductId();
    }


And why ProductVariantAbstract ? I extend ProductVariant.
__________________
xcart 4.6.4
Reply With Quote
  #2  
Old 05-18-2018, 09:00 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Module extend module

Yes, it is possible, and you are doing it almost right.

Since your class depends on another module, you must mention this in the class declaration as follows:
PHP Code:
namespace XLite\Module\Grempels\Restfully\Model/** * @Decorator\Depend("XC\ProductVariants")*/class ProductVariant extends \XLite\Module\XC\ProductVariants\Model\ProductVariant implements \XLite\Base\IDecorator{    public function getProductId() {        return $this->getProduct()->getProductId();    }} 


Quote:
And why ProductVariantAbstract ? I extend ProductVariant.


When re-deploying the site X-Cart finds all classes that "decorate" (the "implements \XLite\Base\IDecorator" thing) core classes or other modules and then rewrite the source code to make them extend each other in the correct order.

The resulting code ends up in the var/run/classes/ directory, and this is where all PHP scripts are executed from (not from the original classes/ directory).

For each class decorated by other modules X-Cart creates an empty class having the same name, but with "Abstract" suffix. This class is the latest in the inheritance tree, so it inherits all methods and properties added by modules. And this class is then used in the rest of the source code instead of the original one (which becomes the top one in the inheritance tree for that class).
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions

Last edited by qualiteam : 05-18-2018 at 09:10 AM.
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:26 AM.

   

 
X-Cart forums © 2001-2020