| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Class / method precedence in X-Cart 5 | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Class / method precedence in X-Cart 5
I am currently looking into migrating a number of custom modules and features from existing 4.* X-Cart installs into 5.2.
Using the Wholesale pricing module as an example, it has the following method defined: ./classes/XLite/Module/CDev/Wholesale/Model/Product.php Code:
I have created a second test module and within it defined the same method: ./classes/XLite/Module/MyDev/MyModule/Model/Product.php Code:
After redeploying the store the result from my getWholesalePrice() method from my test module is what is being called on the front end. How does X-Cart decide which class override should be used? Is there any way to control the precedence? Cheers, Ron PS: my initial post seemed to go off into the ether (silent moderation?)
__________________
multiple versions (4 and 5) |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Class / method precedence in X-Cart 5
Quote:
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey XcartGuru X-cart Tutorials | X-cart 5 Tutorials Check out the responsive template for X-cart. |
|||||||||
|
#3
|
|||||||||
|
|||||||||
Re: Class / method precedence in X-Cart 5
Quote:
The classes are built by dev name/module alphabetically. module/MyDev classes will be called before module/YourDev classes so YourDev will be built on top of MyDev. To properly overwrite them you should always call parent::method first and manipulate the result the way you need it to be. Also you should use "implements \XLite\Base\IDecorator" when extending existing classes and overwriting their methods. If you have not seen it - .http://kb.x-cart.com/display/XDD/Developer+docs
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
#4
|
|||||||
|
|||||||
Re: Class / method precedence in X-Cart 5
Quote:
Thanks for that, at least it is predictable. X-Cart should expect a run on the Dev namespace starting with "Z". =) This will almost immediately be an concern for any module that needs to manipulate pricing (especially if you want a "best price" to apply) or override similar core methods that get called a lot. I don't know if there is any magic solution but I think some sort of user specified precedence would be better than hoping alphabetical works out for all cases.
__________________
multiple versions (4 and 5) |
|||||||
#5
|
|||||||||
|
|||||||||
Re: Class / method precedence in X-Cart 5
Old one but I believe it is same now - https://forum.x-cart.com/showthread.php?t=69010
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#6
|
|||||||||
|
|||||||||
Re: Class / method precedence in X-Cart 5
Yes, classes are built by dev name/module alphabetically.
Plus if you use the @LC_Dependencies tag to put your module after another one that yours depends on.
__________________
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 |
|||||||||
|
|||
X-Cart forums © 2001-2020
|