enRai
enRai

Reputation: 681

Grouped product getFinalPrice behavior in Magento

How can I change getFinalPrice behavior for grouped product in Magento? I want to get final price for grouped product which not using children products with specific attribute value in result calculation

Upvotes: 1

Views: 1157

Answers (1)

Jim OHalloran
Jim OHalloran

Reputation: 5908

If you call the getFinalPrice() method on a grouped product's price model (Mage_Catalog_Model_Product_Type_Grouped_Price) without supplying a quantity, getFinalPrice() will return the previously calculated final price for the product. i.e.

return $product->getCalculatedFinalPrice();

The getCalculatedFinalPrice() method is essentially just a wrapper around the magic getter....

return $this->_getData('calculated_final_price');

The corresponding setCalculatedFinalPrice call is found in the product collection class (Mage_Catalog_Model_Resource_Product_Collection), in the _addFinalPrice() method.

When you dig into the implementation of the method, you'll find it defers to the calculatePrice() method in the product's own price model. Because Mage_Catalog_Model_Product_Type_Grouped_Price doesn't provide an implementation for this method, the version from the parent Mage_Catalog_Model_Product_Type_Price is used. Essentially this encapsulates all of the logic for dealing with base price/spacial price, price rules, etc.

Which leads to the conclusion that without any quantity, options, etc specified, calling getFinalPrice() on a grouped product will return the price of the grouped product itself.

Upvotes: 1

Related Questions