2

I'm having an real issue with Custom Options that incorporate the "percent" price-type.

On Simple products, percent-based custom options work as expected, but on Configurable or Bundled, the final price is determined from the base price, and not the base price + additional options (which is what biz requirements dictate):

Config/Bundle Product

base price = $1000
option 1 + $100 
option 2 + 5%
_____________________________
= $1150 (instead of $1155);

I haven't been able to find much of anything dealing with this otherwise big problem.

I did find and implement this Answer, but the $finalPrice returned in Mage_Catalog_Model_Product_Type_Price -> _applyOptionsPrice is not correctly evaluating the baseprice + upcharge of custom options. Additionally, on the front end, in Products.Options the solution is not incorporating the base price in the calculation either. I'm assuming the fix is for prior versions of magento (I'm on v1.11).

I suspect the strategy for the fix is correct, but its a highly complex interchange, and I'm not entirely clear what needs to be altered to deal with this issue.

Any thoughts would be most welcome.

Cheers


update

I've had a bit of success on the front end (getting the javascript to update option values and pricing correctly).These changes, however are not getting written in to the price model. When the shopping cart goes to render, for example, the final price is incorporating not the fully loaded price, but a percentage of the parent product:

Here's what I have on the back end (which is not changing any behavior. I'll note that I've just got them copied into the app/local directory atm, but I'll override them properly once I get this logic worked out.

Mage_Catalog_Model_Product_Type_Price

    public function getFinalPrice($qty=null, $product)
    {
        //... aggregate tier and special pricing, then apply custom options

        $finalPrice = $product->getData('final_price');
        $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);

        return max(0, $finalPrice);
    }

    protected function _applyOptionsPrice($product, $qty, $finalPrice)
    {
        if ($optionIds = $product->getCustomOption('option_ids')) {
            $basePrice = $finalPrice;
            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);
                    // grab option value based on finalprice 
                    $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $finalPrice);
                }
            };
        }

        Mage::log('base price :'.$basePrice.'  final price :'.$finalPrice); 

        return $finalPrice;
    }

As far as I can tell, in Mage_Catalog_Model_Product_Type_Configurable_Price, and Mage_Catalog_Model_Product_Type_Grouped_Price, there is nothing to override, because they each call on the Parent::getFinalPrice to determine values at each step...

The question remains - how do i modify the pricing models to accommodate a percentage based custom option ??

50 points to someone who can help me work this out. ...

Anyone?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Bosworth99
  • 4,206
  • 5
  • 37
  • 52
  • What you have applied in javascript to get things worked in front end? – Syed Ibrahim Apr 30 '19 at 10:40
  • no idea, to be honest. This is an old project (almost 7 years), I don't have a clue what the details are anymore. This appears to not be solved. Not sure what I did to satisfy business needs. good luck – Bosworth99 Apr 30 '19 at 15:56

1 Answers1

0

If I got you right, you need for configurable and grouped products each next option price modification should be applied to the value, calculated on previous (after applying previous option price modification). In this case you should override _applyOptionsPrice() method in both Mage_Catalog_Model_Product_Type_Configurable_Price and Mage_Catalog_Model_Product_Type_Grouped_Price classes in a next way:

protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
    if ($optionIds = $product->getCustomOption('option_ids')) {
        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);
                $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $finalPrice);
            }
        }
    }

    return $finalPrice;
}
Dmytro Zavalkin
  • 5,265
  • 1
  • 30
  • 34
  • Zyava == thanks for the reply, but I've already attempted this solution (its in my question...). I've applied this change to both the standard `Price.php` and `configurable/Price.php`. Grouped uses its child products to determine the cost of custom options (so `Price.php` should be the fix). However... prices are **not** successfully updating prices (in, for example, the shopping cart). Don't know what I'm missing, but I really need to get this figured out. – Bosworth99 Oct 01 '12 at 15:06