I have some products that can be custumized by the costumer. Naturally, the price must based on the costumization.
For instance, I sell rugs. The dimensions of the rugs can be, sometimes, chosen by the costumer. In order to accomplish that, I created 3 custom options in all the customized products: square_meter_price, width and height.
After clicking on 'add to cart', the customer can choose width and height. After that, on the checkout/cart url, the costumer reads on the 'Product Name' column the correct product name, width and height. The only think that is needed here is to get the correct price out of it.
I am trying to do that by overriding Mage_Catalog_Model_Product_Type_Price::getPrice() method. The problem is I can't get the width/height values input by the costumer so I can do the math.
Note: I already tried iterating through $product->getOptions(). I was able to get the custom options width/height but I wasn't able to get the values input by the customer.
I also tried $product->getCollection()->getAttribute('width') and $product->g开发者_JAVA百科etAttribute('width'), but I got null.
Thank you in advance.
class My_Catalog_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{
public function getPrice(Mage_Catalog_Model_Product $product)
{
// get the width provided by the user
$width = $this->howToGet('width');
// get the height provided by the user
$height = $this->howToGet('height');
if ($width && $height) {
return $width * $height * $product->getAttribute('square_meters_price');
}
return parent::getPrice($product);
}
}
You should be able to do this by modifying the function _applyOptionsPrice
in Mage_Catalog_Model_Product_Type_Price
. This function loops through the options, adding the option prices one by one. Instead of adding, you just need to multiply. Try something like this:
//$finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice);
$finalPrice *= $group->getOptionPrice($quoteItemOption->getValue(), $finalPrice);
精彩评论