Subtract two Price input types and display result
-
22-10-2019 - |
문제
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;
}
제휴하지 않습니다 magento.stackexchange