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)
-   -   Overriding a skin module with my DropDown Module (https://forum.x-cart.com/showthread.php?t=69856)

totaltec 08-20-2014 04:59 PM

Overriding a skin module with my DropDown Module
 
Hi all posting this here so I can understand and others can learn.

Here is a video explaining the problem, and it is outlined again below.

http://youtu.be/ThJlxRRxQac

The module needs to unset the default Category List, and replace it with the DropDown Menu.

I have correctly assigned my template to the appropriate list using:
Code:

/**
 * @ListChild (list="layout.header.bar", zone="customer", weight="140")
 */

In my XLite\Module\Baby\DropDown\View\DropDown.php class

I now need to unset the template default/en/categories/list/body.tpl called by class XLite\View\TopCategories

I have tried using both:
Code:

        \XLite\Core\Layout::getInstance()->removeTemplateFromLists('categories/list/body.tpl');

        \XLite\Core\Layout::getInstance()->removeClassFromLists(
            '\XLite\View\TopCategories'
        );

In my XLite\Module\Baby\DropDown\Main.php, but neither work.

This is due to the class being reassigned to the list by the QSL/WatchWorld module/skin.
In XLite\Module\QSL\WatchWorld\Main.php there is this code:
Code:

        \XLite\Core\Layout::getInstance()->addClassToList(
            'XLite\View\TopCategories',
            'layout.header.bar',
            array(
                'zone'  => \XLite\Model\ViewList::INTERFACE_CUSTOMER,
                'weight' => 140,
            )
        );


I believe this code is overriding the removeClassFromLists function call in my class. It takes precedence I believe because QSL comes alphabetically after Baby.
To overcome this, I tried decorating \XLite\View\TopCategories and adding this code:
Code:

    protected function getDir()
    {
            return '/modules/Baby/DropDown/menu';       
    }

Hoping that it would simply use my template instead. But this causes an error because functions called in my template like getMenu()
Are not relative to the TopCategories Class.

So I overcame it by setting the getDir() function of my decorated TopCategories class to
Code:

    protected function getDir()
    {
        if ($this->getParam(self::PARAM_DISPLAY_MODE) == 'list'){
            return '/modules/Baby/DropDown/blank';
        } else {
            return 'categories/' . $this->getParam(self::PARAM_DISPLAY_MODE);   
        }
       
    }

And then created a blank body.tpl in that directory.

This feels wrong. I need to go about this in a better way. Perhaps I can use my decorated TopCategories class and just import the module functions from the DropDown class?
Or should I redefine the functions in the TopCategories class? Or is there something else, that would override the QSL module and allow me to remove that class or template?

How would I do this properly, can you provide a code example please?

qualiteam 08-20-2014 09:06 PM

Re: Overriding a skin module with my DropDown Module
 
I would decorate the TopCategories class and make it display the drop-down list instead of the regular one.

Actually, it can render the drop-down menu already, but is missing necessary CSS files.

So, what you need to make it drop down:

1. Decorate the TopCategories class in your module.

2. In the defineWindgetParams() methods, after executing the parent one, change the value of the static::PARAM_DISPLAY_MODE widget parameter to static:: DISPLAY_MODE_TREE.

3. Add necessary styles through the getCSSFiles() method.

JannieB 08-22-2014 02:45 AM

Re: Overriding a skin module with my DropDown Module
 
Hi can you explain this a bit more fully ... I need to do a similar thing...

That is, I want to have a horizontal category menu in the header area, with the ability to show the subcategories in a drop-down type panel.

I have tried using addClassToList in my custom skin main.php to add the topcategories class to the layout.header.bar list and have set up a category menu template there which was getting displayed OK ... but when I try and add code to display the categories I get an error. I am assuming I need to assign the data to the template in some way?

I am also not sure how to get the subcategories available ....

Have only been working on XC5 for a few days, so forgive my ignorance of the new architecture... but any help would be greatly appreciated!

Jan

Jan

tony_sologubov 08-22-2014 04:56 AM

Re: Overriding a skin module with my DropDown Module
 
Hi Jan!

Thank you for the question. I will come to it next week, when I will be preparing an answer for Mike.
Stay tuned!

Tony.

tony_sologubov 08-27-2014 06:10 AM

Re: Overriding a skin module with my DropDown Module
 
Hi Mike!

I am not sure whether qualiteam's solution works for you, although it is quite good, but if you want to get rid of TopCategories viewer at all, you can decorate it and redefine its isVisible() method, so it would return false. Once you do this, the categories block will go away.

Method isVisible() exists in every single viewer, so it is pretty easy to get rid of any of them.

If you need to decorate the class after certain module, you can use the approach described here:
http://kb.x-cart.com/pages/viewpage.action?pageId=7504837#Webinar2-10Apr2014-DesignchangesinX-Cart5(Custom...thmyownme nu?

Look at point 7 there.

@Jan
Again, please have a look at the real working example here: http://kb.x-cart.com/pages/viewpage.action?pageId=7504837#Webinar2-10Apr2014-DesignchangesinX-Cart5(Custom...thmyownme nu?

If you still get an error after applying this solution, please send me what error you are getting.

Again, guys, if there is any other question, just let me know.

Tony.


All times are GMT -8. The time now is 03:00 PM.

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