I am building a store, which sells flowers. And there is a functionality I am trying to implement, where I want to have a custom option, which allows customers to add a bit more grass on the bouquet.

The problem is that, if I am on the rose page, I want to select 5 roses, each of which cost 3.00. And I choose that extra grass option for 2.00. Magento calculates it as (2.00 + 3.00) * 5.

What I need is to append that price only once, like 3.00 * 5 + 2.00.

I am trying to find the code, which does the calculation but struggling due to the Magento complexity.

Currently I have found a javascript reloadPrice function in the options.phtml file, but I think it doesn't actually change the price of the product itself, but just the visual representation on the frontend, when an option is selected on the product page. I have also found this bit of code: public function getCalculationPrice() { $price = $this->_getData('calculation_price'); if (is_null($price)) { if ($this->hasCustomPrice()) { $price = $this->getCustomPrice(); } else { $price = $this->getConvertedPrice(); } $this->setData('calculation_price', $price); } return $price; } in the Sales/Model/Quote/Item/Abstract.php file. But I still can't find where it sets the calculation_price. The only place where Magento sets the value: public function setCustomPrice($value) { $this->setCalculationPrice($value); $this->setBaseCalculationPrice(null); return $this->setData('custom_price', $value); } is located in the same file as the previous function. But the break point is never hit there when I am choosing an option or adding it to the cart.

I have also found a different syntax like setData('calculation_price'). But the thing is, after digging up further, it still calling the getPrice function which just returns the 2.00 + 3.00 as a unit price.

I am starting to feel that the value (as a sum) is retrieved from the database (I didn't check though yet). In that case, how to implement that functionality? Will I have to play with prices by subtracting the custom option part from it and append it only once after it fetches the the price as a sum? Ideally, I would like to amend the logic of how that unit price is calculated by having a little flag in the admin in the custom option menu something like a checkbox with "Is Global?" label.

Can you help me please with that?

  • What type of product are you doing this in? Jul 3 '16 at 15:44
  • I am currently trying to implement that functionality with simple products. I was thinking about bundle ones, but it's logically incorrect. The shop should be able to sell a single rose if the customer wishes with extra grass. But grass isn't actually a product at all, so it is nothing but a custom option. I have actually found a function, where the price is changed when you add a product to cart after you have chosen the extra grass option. When I am done I will post it here, but it's tricky since the logic of calculating total price is complex and I need to amend several functions.
    – pro100tom
    Jul 4 '16 at 8:53
  • @pro100tom Kindly let me know, How to fix this issue ..?
    – VijayS91
    Nov 2 '16 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.