2

I need to multiply the custom option value into the product base price. In which file i need to add my function to change this.

I've added one additional field into the option table with value "yes" or "No". If the option is to be "no" the options value is added and if it is "yes" the option value will be multiplied.

Example:
Product Price: $50
Option 1 Value in Textbox: 5
Option 2 Value Selected: $50 

Total Product Price: $500

Thanks in advance.

  • Did you got any solutions for this? – Syed Ibrahim Jun 20 at 13:52
1

I can't give you a full functioning code, but I think you have to rewrite the method Mage_Catalog_Model_Product_Type_Price::_applyOptionsPrice.
You can see in there this line that adds the prices of custom options to the main price:

 $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);

I think you need to insert here your logic. See if your flag is yes or no.
If it's no then add the price, like magento does by default, otherwise remember the price values in an array or a single value by multiplying them and multiply the final price in the end with your value.

Something like this (untested code):

protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
    if ($optionIds = $product->getCustomOption('option_ids')) {
        $basePrice = $finalPrice;
        //init multiplication factor
        $factor = 1;
        foreach (explode(',', $optionIds->getValue()) as $optionId) {
            if ($option = $product->getOptionById($optionId)) {
                $confItemOption = $product->getCustomOption('option_'.$option->getId());

                $group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setConfigurationItemOption($confItemOption);
                //your logic here
                if (your flag == 0) {
                    $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
                }
                else {
                    $factor = $factor * $group->getOptionPrice($confItemOption->getValue(), $basePrice);
                }
            }
        }
        //multiply the final price with the factor
        $finalPrice = $finalPrice * $factor;
    }

    return $finalPrice;
}

You may also need to add some javascript changes for the client side price changing.

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.