0

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.

1

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

  • Gave you the accepted as its more complete. Thanks! SR – SR_Magento Mar 5 '14 at 11:38
1

Assuming $_product is a valid product object...

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

if ($savingValue >= 0) {
    echo "Save: " . $savingValue;
}
  • Gave you +1 for correct answer, but was not as complete a Helphin. Thanks! SR – SR_Magento Mar 5 '14 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.