1

I'm currently working on a Magento extension where I need help in getting the total price of all products having the same attribute when they are added to the cart.

Here is my code for a better explanation @ the shipping's carrier page:

foreach ($this->_quote->getAllItems() as $item) {


        $productid = $item->getProductId();

        $product = Mage::getModel('catalog/product')->load($productid);


     $chilledFood = $product->getData('is_chilled_food'); // the custom attribute 'is_chilled' added to product backend, so if the product is chilled, the value will be 'yes' 
        if ($chilledFood) {  // need help from here?
            return $this->_price = ' ';
        }


    }

So I need help on knowing if the customer selects chilled food in the cart. If yes, the shipping price will be an additional $5 from other types of food category. BUT there will be free shipping cost if the total chilled food amounts to $50 and above.

Thank you.

1 Answer 1

0

Hope this help:

foreach ($this->_quote->getAllItems() as $item) {


    $productid = $item->getProductId();

    $product = Mage::getModel('catalog/product')->load($productid);


 $chilledFood = $product->getData('is_chilled_food'); // the custom attribute 'is_chilled' added to product backend, so if the product is chilled, the value will be 'yes' 
    if ($chilledFood == 1 ) {  // need help from here?
        $totalPrice += $product->getFinalPrice()*$item->getQty();
    }


}
echo $totalPrice;
3
  • I see, thanks for your help! After adding getFinalPrice(), the $totalPrice did increase when an item of the chilled food category is added to the cart (pdt A, pdt B, pdt C...). But the $totalPrice is not computed when the quantity per item (Eg. 2 x pdt A) is increased at Cart page. Any idea how to resolve this? Thanks Mohit Commented Mar 26, 2019 at 8:04
  • Edited my answer Commented Mar 26, 2019 at 8:56
  • Please mark answer as correct if your issue solved. Thanks Commented Mar 26, 2019 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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