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)
-   -   Custom skins hierarchy (https://forum.x-cart.com/showthread.php?t=64646)

totaltec 08-21-2012 09:40 PM

Custom skins hierarchy
 
How is the hierarchy of skins defined? If I want to create a custom skin for XCN, do I have to disable the XCNSkin module? Or can I create a new skin that will overridethe XCNSkin? How would priority be determined between skins?

Cpt.Crashtastic 08-22-2012 12:45 AM

Re: Custom skins hierarchy
 
Totaltec,

If you have the version where the xcart skin is a module, you need to install the latest version. The skin named default is xcn in this version. http://next.x-cart.com/download/trial

Priority is always with the default skin and the template engine overrides the default skin with yours. This way you only have to replace the parts you require.

It would be useful to look at the xcn skin to get an idea of how it all works. There two places where replacement skins are placed currently. (odd to me)

skins/default/modules/<Your DevId>/<Your Module>

this is for your modules obviously. Notice that XLite\Module\ where you place your module does not have an 's' on the end but the default/modules does. Just pointing it out as when you type a namespace in it's easy to make a mistake and wonder for hour or so as to whats wrong:lol:

and

skins/<your skin name>

If you go litecommerce.com and follow the link through to the wiki you will find some useful if not confusing information.

Skinning the Drupal version is much easier believe it or not.

totaltec 08-22-2012 05:53 AM

Re: Custom skins hierarchy
 
Thank you Captain! I have skinned the Drupal version of LC, I agree it is easier. I have also successfully skinned the stand alone version now (just last night). I am still confused though, for a while I had my new skin enabled, and the XCN skin enabled, and my skin seemed to be overwriting the XCN skin. Not sure if it is because it initialized first, or what.

I am still curious if there is a hierarchical order of skins, and how that is determined if it exists. This would be pretty important, if you wanted to sell an XCN skin, you would want to know if you should instruct users to disable their existing skin, or if you could code it to put your custom skin first in priority.

I'll download the latest version soon, I am still working on the extremely old beta version that was released 2 whole weeks ago. :-)

Cpt.Crashtastic 08-23-2012 12:56 AM

Re: Custom skins hierarchy
 
It looks like you could have several skins loaded so you would have to tell customers to disable existing skins. It would be handy if there was an Appearance setting like in Drupal. CDev I guess would have some priority but any others I don't know without experimenting. Maybe I'll find time to try today.

xplorer 08-23-2012 04:19 AM

Re: Custom skins hierarchy
 
Hi!

Let me explain how this works.

Think of a pie made of multiple layers. Each layer is a skin directory added by an X-Cart Next module.

First of all, X-Cart Next loads enabled modules. When it finds a module registering a skin directory it puts the directory on top of the previous one.

Then, when loading a template or a resource file, X-Cart Next goes through all the layers from the top. When it finds the file it stops and doesn't look in "lower" directories.

So, the order in which X-Cart Next goes through skin directories when looking for a "skin" file is the reverse order in which it loads modules registered the directories.

What is the order in which it loads modules? First of all X-Cart Next loads modules which other modules depend on. Then it loads the rest alphabetically.

An example:

Quote:

Let's say you have three modules that register their skin directories: Clean (skins/clean), Fancy (skins/fancy) and Zen (skins/zen). Clean module states (in Main.php) that it depends on Zen module.

X-Cart Next will load the modules as follows:
Zen -> Clean -> Fancy.

That means that the order in which it looks through registered skin directories will be as follows:
skins/fancy -> skins/clean -> skins/zen -> skins/default

Now let me explain the difference between "skins/[custom]/" and "skins/default/en/modules/[dev]/[module]/" directories:
- when you create a new widget or a template, you place its files into the "skins/default/en/modules/[dev]/[module]/" directory
- when you want to replace an existing template, you place your file into the "skins/[custom]/" directory.

Take a look at the following example and you'll understand the idea behind this:

Quote:

Let's say you want to display currency exchange rates in a sidebar.

You create a custom module that adds the new template file:
skins/default/en/modules/Totaltec/CurrencyRates/sidebar-block.tpl

Now you realise that you need the same feature on another website, but with a different template.

You copy the module and install it there. To alter the template file you:
- create another module that registers the new skin directory (skins/myskin)
- put the modified template file into skins/myskin/en/modules/Totaltec/CurrencyRates/sidebar-block.tpl

Now you can fix bugs in the original Totaltec/CurrencyRates module and upload it to both the websites without having to adapt it for your website skins.

Cpt.Crashtastic 08-23-2012 05:19 AM

Re: Custom skins hierarchy
 
Thanks V

Now i understand. Thats really useful information.

Cpt.Crashtastic 08-23-2012 06:19 AM

Re: Custom skins hierarchy
 
Continueing this hierarchy discussion further

If we take for example Minicart.php the list position is specified before the class declaration.

We can extend this class and change the position of the list, for example to the sidebar, in the same way as the original, but this results in there being two positions. The original position and the new position.

Is it just a simple matter of including a blank template (header.right.tpl) within our new skins or is the better way to deal with this? Having a blank template doesn't seem right to me.

xplorer 08-24-2012 03:47 AM

Re: Custom skins hierarchy
 
You can move and replace existing widgets and templates by declaring runBuildCacheHandler() method in your Main.php file as follows:

HTML Code:


/**
 * This method runs at the end of the cache rebuilding process.
 *
 * @return void
 */
public static function runBuildCacheHandler()
{
    /*
    * Items in XLite\Model\ViewList have the following attributes:
    * - 'list' - the full identifier of the "view list" in which
    * the item is to be displayed
    * - 'child' - the full class name of the widget to be displayed
    * - 'tpl' - the template file to be displayed (path to the
    * file inside the "skins/[skin-name]/[language-id]/" directory)
    */

    $item1 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy(
        array(
            'list' => '[current_view_list]',
            'child' => '[widget_class]',
        )
    );
    if ($item1) {
        // Now you can move the widget to another "view list"
        $item1->setList('[new_view_list]');
        // ... or replace it with a custom widget class
        $item1->setChild('[custom_widget_class]');
    }

    $item2 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy(
        array(
            'list' => '[current_view_list]',
            'tpl' => '[relative_path_to_template]',
        )
    );
    if ($item2) {
        // Move the template to another "view list"
        $item2->setList('[new_view_list]');
        // Replace the item with a custom template file
        $item2->setTpl('[custom_template_path]');
    }

    if ($item1 || $item2) {
        // Push the changes into the database
        \XLite\Core\Database::getEM()->flush();
    }
}


Cpt.Crashtastic 08-24-2012 03:54 AM

Re: Custom skins hierarchy
 
Now that is really useful. Thanks Vyacheslav


All times are GMT -8. The time now is 10:15 AM.

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