View Single Post
  #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