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)
-   -   Replacing templates from common skins (https://forum.x-cart.com/showthread.php?t=77847)

The Knotty Celt 06-10-2020 01:17 PM

Replacing templates from common skins
 
I am working on a module which replaces the invoice templates. Following the guide here, I created the following template file:
Code:

skins/common/modules/LBS/OrderNumber/order/invoice/parts/title.twig
Since it is a part of the invoice.head viewList, I added the following to the end of my module's Main.php.
Code:

protected static function moveTemplatesInLists()
{
    $templates = [
        'order/invoice/parts/title.twig' => [
            static::TO_DELETE => [
                ['invoice.head', \XLite\Model\ViewList::INTERFACE_CUSTOMER],
            ],
        ],
    ];


    return $templates;
}



This results in both the original title.twig and my title.twig being rendered side-by-side on the invoice header. Since the original title.twig is located under the common skins, that INTERFACE_CUSTOMER is not correct. I looked in XLite\Model\ViewList.php for a possible INTERFACE_COMMON definition. Since there was none, I saw that INTERFACE_CUSTOMER returns the string 'customer', and INTERFACE_ADMIN returns the string 'admin', so I tried changing the line,
Code:

['invoice.head', \XLite\Model\ViewList::INTERFACE_CUSTOMER]
to,
Code:

['invoice.head', 'common']
which produced the same result.


What is the proper way to replace a template found within skins/common? Or is it it that the viewList 'invoice.head' is part of another viewList? Do I need to specify all the parents and grandparents of the viewList? I shall try something along those lines to see if it works in the meantime while waiting for some much appreciated feedback.

Ed B. 07-04-2020 11:43 AM

Re: Replacing templates from common skins
 
This may be a "dirty" work around, but should work: instead of bothering with viewlist, just override the viewer. So override XLite/View/Invoice.php to change
getDefaultTemplate() or XLite/View/InvoicePage.php to modify getDir(), getBody() or getHead(), whichever is appropriate.

The Knotty Celt 07-12-2020 11:07 AM

Re: Replacing templates from common skins
 
Quote:

Originally Posted by Ed B.
This may be a "dirty" work around, but should work: instead of bothering with viewlist, just override the viewer. So override XLite/View/Invoice.php to change
getDefaultTemplate() or XLite/View/InvoicePage.php to modify getDir(), getBody() or getHead(), whichever is appropriate.





I have since tried that, by implementing IDecorator on both Invoice and InvoicePage View classes, and updating the getDir(), getBody() and getHead(), among other functions referring to various template files. Now, everything is duplicated. I also copied the template files into the appropriate modules' locations. The result is that both the original templates and module templates are appearing side-by-side. It's as though both sets of Invoice and InvoicePage classes are being loaded, rather than the module replacing the original view.

The Knotty Celt 07-16-2020 07:56 AM

Re: Replacing templates from common skins
 
SOLUTION

I was able to resolve my issue quite simply by amending the getSkins() function of my module's Main.php file as follows:


Code:

public static function getskins()
{
    return array(
        \XLite::CUSTOMER_INTERFACE => array(
            'customer/modules/LBS/OrderReference',
        ),
        'common' => array(
            'common/modules/LBS/OrderReference',
        ),
    );
}



All times are GMT -8. The time now is 02:14 PM.

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