View Single Post
  #1  
Old 08-20-2014, 04:59 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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?
__________________
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.
Reply With Quote