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)
-   -   Override XCart class from Includes folder? (https://forum.x-cart.com/showthread.php?t=73765)

Joel Erickson 03-25-2016 06:32 AM

Override XCart class from Includes folder?
 
I have learned how to add module classes to override and/or depend on other modules and the classes in the classes/XLite directory, per the instructions in the knowledge base:
http://kb.x-cart.com/display/XDD/Step+3+-+applying+logic+changes
http://kb.x-cart.com/display/XDD/Making+one+module+depend+on+another+one+--+creating+a+menu+in+the+customer+area

For example, I have successfully overridden \XLite\View functionality such as:
PHP Code:

namespace XLite\Module\MB\Override\View\ItemsList\Product\Customer;

abstract class 
ACustomer extends \XLite\View\ItemsList\Product\Customer\ACustomer implements \XLite\Base\IDecorator
{
    
/**
     * Return true if quick-look is enabled on the items list
     *
     * @return boolean
     */
    
protected function isQuickLookEnabled()
    {
        return 
false;
    }



However, I have not been able to figure out how to override classes in the Includes/Utils directory. For example, I have tried something like this:

PHP Code:

namespace XLite\Module\MB\Override\Includes\Utils;

abstract class 
Converter extends \Includes\Utils\Converter implements \XLite\Base\IDecorator
{
    public static function 
buildURL($target ''$action '', array $params = array(), $interface null)
    {
        
$result strval($interface);
        
$urlParams = array();

        if (!empty(
$target)) {
            
$urlParams['target'] = $target;
        }

        if (!empty(
$action)) {
            
$urlParams['action'] = $action;
        }

        
$params $urlParams $params;

        if (!empty(
$params)) {
            
$result .= '?' http_build_query($params'''&');
        }

        if (
$interface == 'cart.php') {
            
$result .= '#testing'// <--------- no effect yet
        
}
        return 
$result;
    }



But it has no effect on the storefront, so this class function is apparently not being called.

seyfin 03-28-2016 06:17 AM

Re: Override XCart class from Includes folder?
 
Could you please explain in details what customization you are trying to implement?

Joel Erickson 03-28-2016 10:14 AM

Re: Override XCart class from Includes folder?
 
I'm trying to modify the storefront url structure, as the default cleanUrl feature doesn't suit my needs. I've managed to created a working solution by hacking the \Includes\Utils\Converter class function buildURL() itself, but I figured a more sustainable approach should be to try to override the function.

Now I see that function is only directly called from \XLite\Core\Converter.php, so I'll try overwriting that class.

qualiteam 03-31-2016 03:27 AM

Re: Override XCart class from Includes folder?
 
XC5 allows you to "decorate" classes in the "classes" directory only. You're right - it doesn't work with classes inside the Includes directory.

The \XLite\Core\Converter class will likely work in your case.

Joel Erickson 03-31-2016 05:00 AM

Re: Override XCart class from Includes folder?
 
Yes, thanks, decorating that class did the trick. :-)


All times are GMT -8. The time now is 09:01 PM.

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