Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Replacing templates from common skins

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 06-10-2020, 01:17 PM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default 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.
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote
  #2  
Old 07-04-2020, 11:43 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default 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.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #3  
Old 07-12-2020, 11:07 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default 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.
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote
  #4  
Old 07-16-2020, 07:56 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default 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', ), ); }
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote

The following user thanks The Knotty Celt for this useful post:
Ed B. (07-16-2020)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:20 AM.

   

 
X-Cart forums © 2001-2020