View Single Post
  #5  
Old 09-03-2012, 02:05 AM
 
Cpt.Crashtastic Cpt.Crashtastic is offline
 

eXpert
  
Join Date: Jan 2006
Posts: 219
 

Default Re: Creating a skin module

Now for a really useful function.

The page layout is constructed from lists. A bit like the Russian dolls in concept. Each list consists of templates which are ordered by a weight attribute. The higher the weight the lower down the list the template will appear.



So roughly we have this structure

The main page which is ⌠layout.main■

The main page contains list contains

A header list
A Sidebar list
A content list
A footer list

The header list contains

A left list
A centre list
A right list

And so on....


Now as an example we currently have the minicart in the top right corner of the main page and we want to move it to the sidebar. It resides in the ⌠layout.header.right■ list. If you check this in under xlite_view_lists in your database you will see that it is defined in XLite\View\Minicart.php.

Hint : There is a quick way of figuring out which list you need to find in the database. Check the HTML of the generated page and for each main block of code, check the class. It should give you a good idea what you are looking for

Looking at XLite\View\Minicart.php

The DocBloc contains the directive

@ListChild (list="layout.header.right", weight="100")


How do we change this? Its not possible to override the class and re-declare this as the @ListChild directive is outside the class declaration. You would end up with two minicarts or a mess! It's all done in the Main.php that was created for the skin module earlier. Of course you could create a module to do this all on its own but thats unecessary duplication of code just for this. There is a built in function which will do this job for you. All we have to do is provide it with the correct paramaters to find the list and the parameters that needs to be changed.

Code:
/** * This method runs at the end of the cache rebuilding process and relocates the lists. * * @return void */ public static function runBuildCacheHandler() { /** * @return $string List */ $item1 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy( array( //The parameters to find our list 'list' => 'layout.header.right', 'child' => 'XLite\View\Minicart', ) ); if ($item1) { // Move the widget to another "view list" $item1->setList('sidebar.first'); } // At this point the list has been changed but the database has not been updated. // The next section of code is another example where the list and the weight are changed of the main menu /** * @return $string List */ $item2 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy( array( 'list' => 'layout.main', 'child' => 'XLite\View\Menu\Customer\Top', ) ); if ($item2) { $item2->setList('layout.header.bar'); // Adjust the menu weight" $item2->setWeight('150'); } //Here the data is pushed to the database if ($item1 || $item2) { // Push the changes into the database \XLite\Core\Database::getEM()->flush(); } }

Hopefully this is clear to those that read but feel free to ask questions. This piece of code really opens the door to understanding how XCN skins work under the hood. It's a massive leap in the right direction but it's a bit of a learning curve for us die hard xcart users.

This is only a simple example and it is necessary to do a little more work to make it work perfectly. When I have a moment I will atttach a complete module.


If you are familiar with TWIG, SYMPHONY, DOCBLOCK and DOCTRINE2 then you will be well on your way to understanding XCN! A bit of bed time reading
__________________
Xcart 4.4.?
Xcart Next
Litecommerce with Drupal
http://www.corbywebworx.com

Custom Mods, Hosting and Support for Xcart-Next and LiteCommerce
Reply With Quote