سؤال

I'd like to show visitors to my website an instant savings based on subtracting 2 attributes costnopromo and cost.

If the attributes are the same, then I do not want to display the text, "Save:"

I know I can do this with an if statement, but I do not know how to subtract the 2 attributes.

How do can achieve the following:

costnopromo - cost = savings_value

NOTE: I've searched and came across the method to show a savings based on MSRP and PRICE but this does not meet my requirements as the costnopromo is a custom value.

هل كانت مفيدة؟

المحلول

The product collection output get from,

$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();

to get the costnopromo and cost values by,

echo $_product->getCostnopromo();
echo $_product->getCost();

To substract,

$savings_value = intval($_product->getCostnopromo()) - intval($_product->getCost());

by checking the condition,

 if($savings_value >= 0){
    echo 'save :'.$savings_value;
 }

this may help you

نصائح أخرى

Assuming $_product is a valid product object...

$savingValue = $_product->getCostnopromo() - $_product->getCost();

if ($savingValue >= 0) {
    echo "Save: " . $savingValue;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top