View Single Post
  #2  
Old 06-02-2015, 10:56 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Math IF/ELSE in version 5

Hello Richard,

Here is how I would do this to retain the compatibility with future X-Cart 5 versions:

1. Create a custom module

2. Copy the skins/default/en/product/details/stock/body.tpl file to skins/default/en/modules/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/product/details/stock/body.tpl and change it as follows:
HTML Code:
... <span class="product-items-available" IF="isItemsAvailableVisible()">({t(#X items available#,_ARRAY_(#count#^getAvailableAmount()))})</span> ...

3. Decorate \XLite\View\Product\Details\Customer\Stock class as follows:

classes/XLite/Module/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/View/Product/Details/Customer/Stock.php

PHP Code:
namespace XLite\Module\[YOUR_DEV_ID]\[YOUR_MODULE_ID]\View\Product\Details\Customer;

abstract class 
Stock  extends \XLite\View\Product\Details\Customer\Stock implements \XLite\Base\IDecorator
{
  protected function 
isItemsAvailableVisible()
  {
    
// Add your logic here and set $flag to TRUE when the stock level is to be displayed
    
return $flag;
  }

  protected function 
getDefaultTemplate()
  {
    return 
'modules/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/product/details/stock/body.tpl';
  }



Haven't tested the code, but it should work as is.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote