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)
-   -   Overiding CDev Module css (https://forum.x-cart.com/showthread.php?t=64867)

Cpt.Crashtastic 09-17-2012 04:17 AM

Overiding CDev Module css
 
Stumped on this one!

Ok so I create a skin module and replicate the directory structure. In this case mine becomes

CorbyWebWorx/CwwSkin/ProductOptions/View

as I want to override the product_options.css

So I create Product.php too look like this

Code:

namespace XLite\Module\CorbyWebWorx\CwwSkin\ProductOptions\View;

/**
 * Product widget
 *
 */
abstract class Product extends \XLite\View\Product\Details\Customer\ACustomer implements \XLite\Base\IDecorator
{

    /**
    * Register CSS files
    *
    * @return array
    */
    public function getCSSFiles()
    {
        $list = parent::getCSSFiles();
        $list[] = 'modules/CorbyWebWorx/ProductOptions/cww_product_details.css';

        return $list;
    }
}


Then add the css file as per the $list variable.

The css file is then called BUT the CDev module css still takes precedence over the overiding css. It doesn't matter whether the css file is named identically you still get the same result. Of course you could edit the css file directly, but thats wrong. There is obviously a simple solution to this, but I can't see it.

Any ideas?

xplorer 09-17-2012 11:38 PM

Re: Overiding CDev Module css
 
Quote:

namespace XLite\Module\CorbyWebWorx\CwwSkin\ProductOptions\V iew;

Your developer ID is "CorbyWebWorx", and your module ID is "CwwSkin". Since XCN loads modules in the alphabet order, "CwwSkin" files get loaded before the original files from "ProductOptions" module.

However, you can force your module to be loaded first by adding "ProductOptions" to the list of modules which you module depends on: in your module's "Main.php" file add "getDependencies()" method as follows:
PHP Code:

public static function getDependencies()
{
    return array(
'CDev\ProductOptions');




Now discard the above because the right way to get what you want is different :-)

If you want to add some custom CSS files to an existing widget, you should find the widget class, "decorate" it in your module and add your custom CSS files by overriding the "getCSSFiles()" method. If you want to drop some existing CSS files, you do the same, but instead of adding new values you look through the array and drop the entries which you don't need anymore.

Does this help?

Cpt.Crashtastic 09-18-2012 12:20 AM

Re: Overiding CDev Module css
 
Yes, I can now figure out what to do I think!

When I have I'll post up how to do more fully.

Cpt.Crashtastic 09-18-2012 01:17 PM

Re: Overiding CDev Module css
 
Right I figured out how to call the list and created a bit of rough and ready code to remove the item from the list as follows.

Code:

  public static function runBuildCacheHandler() {
    $list = \XLite\Module\CDev\ProductOptions\View\Product::getCSSFiles();

    $key = array_search('modules/CDev/ProductOptions/product_details.css', $list);
   
    unset($list[$key]);
   
    return $list;
  }


I followed this code through and it appears to call the getCSSFiles() functions from CDev and CWW for a second time, removes product_details.css from the list as expected.

I don't think I'm doing this in the right place as product_details.css is still being called when the page loads.

Changing the Dev ID would be far easier:roll:

Could you give me a clue please xplorer?

xplorer 09-18-2012 11:15 PM

Re: Overiding CDev Module css
 
First of all we search throuhg all the files for the widget class that adds the "product_details.css" file.

It is \XLite\Module\CDev\ProductOptions\View\Product. Here is it: https://github.com/litecommerce/core/blob/1.0-master/src/classes/XLite/Module/CDev/ProductOptions/View/Product.php

As you see the class "decorates" \XLite\View\Product\Details\Customer\ACustomer class. "Decoration" means that after the cache rebuild process there will be no ProductOptions\View\Product class anymore, but the changes will be included into the class being decorated. That's why if you want to "decorate" it further, you should extend the base \XLite\View\Product\Details\Customer\ACustomer class, not the ProductOptions\View\Product one.

So, we create a module, specify "Cdev\ProductOptions" in its dependencies, add a new class that decorates the \XLite\View\Product\Details\Customer\ACustomer class and declare getCSSFiles() method that parses the array returned by parent::getCSSFiles() and removes "product_class.css" from the list.

Cpt.Crashtastic 09-19-2012 01:45 AM

Re: Overiding CDev Module css
 
Quote:

Originally Posted by xplorer
Your developer ID is "CorbyWebWorx", and your module ID is "CwwSkin". Since XCN loads modules in the alphabet order, "CwwSkin" files get loaded before the original files from "ProductOptions" module.

However, you can force your module to be loaded first by adding "ProductOptions" to the list of modules which you module depends on: in your module's "Main.php" file add "getDependencies()" method as follows:
PHP Code:

public static function getDependencies()
{
    return array(
'CDev\ProductOptions');




Now discard the above because the right way to get what you want is different :-)


Thats what threw me. Everything else I had done but I removed the array within the public static function runBuildCacheHandler(). I understand this now

Thankyou very much.

Cpt.Crashtastic 09-19-2012 02:53 AM

Re: Overiding CDev Module css
 
I have written this up in what is an easy to understand manner

here

xplorer 09-19-2012 05:46 AM

Re: Overiding CDev Module css
 
Quote:

Originally Posted by Cpt.Crashtastic
I have written this up in what is an easy to understand manner

here


Hm, you can replace a CSS file from your skin module.

1. You want to add your custom CSS file to a widget - you decorate the widget and add your file to getCSSFiles()

2. You want to remove an existing CSS file at all - you decorate the widget and parse the parent::getCSSFiles() result

3. You want to replace an existing CSS file with your custom one - you create a skin module and place your modified version of the file inside your skin directory (just make sure that the relative path to the file is exactly the same that the original file has).

Cpt.Crashtastic 09-19-2012 08:38 AM

Re: Overiding CDev Module css
 
Edit : Maybe I didn't understand you correctly. This code was for the skin module.

End Edit

For some reason even though I could get the skin module css to load the CDev was always overiding the ADev modules css. Only way around it I could see as an alternative was to create a tpl with different css id's

3: Do you mean within default/en/modules/ADev

we should have CDev/ProductOptions/product_options.css

I didn't try that. It would be easier. My way worked andI guess it may even have reduced the load as the product_options.css was dropped altogether.

xplorer 09-19-2012 10:55 PM

Re: Overiding CDev Module css
 
To completely replace skins/default/en/modules/CDev/ProductOptions/product_details.css file with your custom one, just put your file here: skins/[your-skin-name]/en/modules/CDev/ProductOptions/product_details.css

Just make sure that Product Options module is loaded before yours (add it to your module dependencies).

P.S. although you can replace template files this way, we recommend you to keep as much "default" templates as possible - some of the templates which you replace may be modified in future versions, and the changes won't get into your custom versions of the files during upgrade.

cflsystems 09-19-2012 11:22 PM

Re: Overiding CDev Module css
 
I've been following this thread to see how far it will go and how easy it is to do something like this with XCN but your reply here brings the question (which I have even for XC4 though):

Quote:

P.S. although you can replace template files this way, we recommend you to keep as much "default" templates as possible - some of the templates which you replace may be modified in future versions, and the changes won't get into your custom versions of the files during upgrade.

How XCN works for soemthing like this? To compare with XC4 - I always advice clients to modify existing skin and not create new skin directory - for that same reason - XC upgrade doesn't care about anything non-XC. So custom skin in non-XC directory does not get upgraded. So if there are bugs in the XC skin (not to talk about new features) simply by copying that skin to a new one will copy the bugs and they will not get fixed with an upgrade.

From your answer here I get it it is the same with XCN. To me is sounds way better to just modify existing XC skin instead of trying to create new one

Cpt.Crashtastic 09-19-2012 11:50 PM

Re: Overiding CDev Module css
 
XPlorer's methos was a lot easier and the one I did not try before doing it programatically.

This is an interesting debate.

Which method would make it easier to identify where the problem was if this or any other template was altered during the upgrade process?

Replacing a skin completely may make it easier to identify quicker.

I need to do some testing on what would happen if you have multiple skins themes installed. If this is the case, altering the CDev css is not an option, in my opinion, as you would have nothing working to go back to.

What happens if we have multiple modules altering a CDev modules CSS? It could get proper messy :-)

If you are gong to sell skins you need some element of control.

If there was a notification process for developers that gave them say a weeks notice for an impending upgrade it would make life easier.

I've just got an x-cart next test site up and running with Drupal if you are interested. It took a suprisingly long time to get there.

http://www.thesuitstore.co.uk

xplorer 09-19-2012 11:51 PM

Re: Overiding CDev Module css
 
In XCN there are many improvements which allow you to modify the design without duplicating-modifying-replacing template files:

1. First of all, you can add your html snippets into existing templates by adding @ListChild directive. This is what Cpt.Crashtastic named "russian dolls": http://forum.x-cart.com/showpost.php?p=345355&postcount=5

2. Most of the design tweaks can be done from CSS without hacking into the html templates.

3. The template engine prohibits the use of a complex logic in template files. All complex presentation logic is isolated in widget classes which you can extend/"decorate" from custom modules without copying the files (and duplicating the bugs, if any).


You may replace a couple of templates in your skin module - just be more careful when installing upgrades. If something goes wrong you always can temporarily disable the skin module and check how a new feature/change looks like in the "default" version (and then adapt your modified templates to reflect the change).

But you should never edit core files (including templates) - the next upgrade will drop them and replace with unmodified versions from the new version.

xplorer 09-19-2012 11:55 PM

Re: Overiding CDev Module css
 
Quote:

Originally Posted by Cpt.Crashtastic
If there was a notification process for developers that gave them say a weeks notice for an impending upgrade it would make life easier.


This is what we are going to do: we will release RC versions a couple of weeks prior to the final release so that all developers could test their modules/modifications and adapt them to the upcoming changes.

Cpt.Crashtastic 09-20-2012 12:10 AM

Re: Overiding CDev Module css
 
Dare I ask when the release version of XCN is coming?

xplorer 09-20-2012 01:49 AM

Re: Overiding CDev Module css
 
Quote:

Originally Posted by Cpt.Crashtastic
Dare I ask when the release version of XCN is coming?


In a couple of months. The second beta will be released in about a month (we are certifying our integration with PayPal).

cflsystems 09-20-2012 09:35 AM

Re: Overiding CDev Module css
 
Quote:

Originally Posted by xplorer
But you should never edit core files (including templates) - the next upgrade will drop them and replace with unmodified versions from the new version.


This answers my question about XCN and upgrades, thanks


All times are GMT -8. The time now is 03:31 AM.

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