X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   XC5 Problem overriding class with a module (https://forum.x-cart.com/showthread.php?t=71589)

zychen 03-10-2015 11:14 AM

XC5 Problem overriding class with a module
 
Hi everyone,

I'm having problems with overriding the class \XLite\View\ItemsList\Product\Customer\Search with the function getData().

The original class and function still gets called.

What are the usual things I should check? Is there a restriction on certain classes that cannot be overridden?

Code:

class Search extends \XLite\View\ItemsList\Product\Customer\Search implements \XLite\Base\IDecorator
{
    /**
    * Return products list
    *
    * @param \XLite\Core\CommonCell $cnd      Search condition
    * @param boolean                $countOnly Return items list or only its size OPTIONAL
    *
    * @return array|integer
    */
    protected function getData(\XLite\Core\CommonCell $cnd, $countOnly = false)
    {
        return \XLite\Core\Database::getRepo('\XLite\Model\Product')->search(
            $cnd,
            $countOnly
        );
    }
}


totaltec 03-11-2015 03:49 AM

Re: XC5 Problem overriding class with a module
 
What is your name space? Is your file being put in the run directory after redeployment?

zychen 03-11-2015 05:30 AM

Re: XC5 Problem overriding class with a module
 
Hey Mike, thanks for replying.

This is my namespace
Code:

namespace XLite\Module\<Company>\<Module>\View\ItemsList\Product\Customer;
And the file is being put into the run directory after redeployment with the correct contents.

And function code-wise, there shouldn't be a problem there as I can get the code to work temporary by replacing the actual search function in the run directory.

totaltec 03-11-2015 06:30 AM

Re: XC5 Problem overriding class with a module
 
There is a possibility that another module is also decorating this class, and it may come alphabetically after yours.

In this case you need to make your module depend on the other, and you do this via module dependencies in your main.php I believe.

Check the class that you are decorating in the run directory. It should be extending your class after deployment, or it could be that it is extending another, you can chase through which class depends on which by seeing how they reference each other in the run directory.

zychen 03-11-2015 08:07 AM

Re: XC5 Problem overriding class with a module
 
Thanks Mike!

Your answer helped me realize that the bundled CloudSearch Module must have been doing some overriding to the Search class somehow.

Although the class in the run folder didn't specifically point to CloudSearch, my module worked perfectly after disabling CloudSearch :D

Cheers!
-Niboon


All times are GMT -8. The time now is 07:53 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.