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)
-   -   How to get a global attribute and handle its value (https://forum.x-cart.com/showthread.php?t=74049)

FactorInteractivo 06-06-2016 11:55 AM

How to get a global attribute and handle its value
 
We are working on a module in X-Cart 5 which according to the value of a global attribute must show an Icon next to a product in the "On sale" products list.

In the route classes/xlite/module/developerID/moduleID/view/price.php we have the following code

Code:


/**
    * Return sale participation flag
    *
    * @return boolean
    */
    protected function participateSale()
    { 
        return $this->getProduct()->getParticipateSale();
    }


and my product TPL is like the following:

Code:


{* vim: set ts=2 sw=2 sts=2 et: *}
 
{**
* Product price value
*
* @author    Qualiteam software Ltd <info@x-cart.com>
* @copyright Copyright (c) 2011-2015 Qualiteam software Ltd <info@x-cart.com>. All rights reserved
* @license  http://www.x-cart.com/license-agreement.html X-Cart 5 License Agreement
* @link      http://www.x-cart.com/
*
* @ListChild (list="product.plain_price", weight="10")
*}
 
<li IF="participateSale()" class="sale-banner">
  <div class="sale-banner-block">
    <div class="text">{t(#sale#)}</div>
    <div class="percent">{t(#percent X off#,_ARRAY_(#percent#^getSalePercent())):h}</div>
  </div>
</li>


At the same time, we have a Global Attribute called "sale" which contains a value of 0 or 1.

I need the function "participateSale" to return "True" if the "sale" attribute value for a product is 1.

My problem is that I don´t know how to access to that attribute from the current folder I´m working.

Any ideas ? Thanks in advance !!

X-Cart 5.2.15

FactorInteractivo 06-07-2016 11:38 AM

Re: How to get a global attribute and handle its value
 
I have advanced with this problem, now i created a new file in "XLite\Module\DeveloperID\ModuleID\View\Product\De tails\Customer" called "Atribute.php"

have the following code:

Code:

<?php
// vim: set ts=4 sw=4 sts=4 et:
 
namespace XLite\Module\FactorInteractivo\FooterCasaJorge\View\Product\Details\Customer;
 
/**
 * Product attributes
 */
abstract class Attributes extends \XLite\View\Product\Details\Customer\Attributes implements \XLite\Base\IDecorator
{
    public static function getAttrBullet()
    {
        $attributes = parent::getAttrList();
        $return= false;

        foreach($attributes as $attr){
            if(strtoupper($attr['name']) == "SALE" && $attr['value'] == '1'){
                $return= true;
            }
        }

        return $retorno;
    }
}


In my file Price.php (XLite\Module\FactorInteractivo\FooterCasaJorge\Vi ew) I use this function and call it:

Code:

protected function participateSale()
    { 
        $atr = Details\Customer\Attributes::getAttrBullet();
        return $atr;
    }


But this return an error related with the use of $this when is not a object.

¿They understand my objetive? I need a urgent answer :(

FactorInteractivo 06-13-2016 07:51 AM

Re: How to get a global attribute and handle its value
 
Anybody any clue on this subject, or is this a "Top secret" subject ;-)


All times are GMT -8. The time now is 11:01 PM.

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