My client needs to make an operation on products custom options.
Using Magento CE, I create a product, and give it some custom options from within the built-in left hand side menu in "Manage products" > "Add new product", such as "mm" (millimeters) and "mt" (meters)
This product will have both radio options and a textbot input.
Let's say we have
Base price: 0
MM:
Radio option A which costs 0,9
Radio option B which costs 1,2
Radio option C which costs 2,3
MT:
Textbox value = unknown yet
Let's say user chooses Radio option B
and enters 10
in the textfield
Price should be updates as such:
1,2 * 10 + 0
Which is
radio value cost * textbox value + base price
Is there any way to tell the code to take the value of the radio button, multiply it for the value of the textbox and sum it all to the base price?
Where could I look to see the current behavior of a product's custom options?
Thanks in advance
Best Answer
In this case,you can use magento
event/observer
. Basically there are two events,by which you can change the cart price of that products:checkout_cart_product_add_after
checkout_cart_update_items_after
checkout_cart_product_update_after
This 3 event is need because of:
Event1:checkout_cart_product_add_after
This event is fire when
first time a product is cart for current session
of current input values from frontendEvent2:checkout_cart_product_update_after
This event is fire when
a current exiting cart item
edited from edit link of cart item.Event3:checkout_cart_update_items_after
This event is fire whenever cart items update from cart page.
As per as magento system, a
cart item price
change usingsetter
functionssetCustomPrice(), setOriginalCustomPrice
of cart item Object.Just like:
And using
events fire an observer
which iscalculate price basic of your input fields
.Suppose: The
radio button
field name isMy Checkbox
and Text Box field Name isMyTestext
.Config.xml code like:
Observer code like this:
Full Module:
As per as your request, i have put full module:
File1: create
config file
at app/code/local/Stackexchange/Magento65569/etc/config.xml
Code:
File2: location
app/code/local/Stackexchange/Magento65569/Model/Observer.php
Code:
File3: Module Main file at
app/etc/modules/Stackexchange_Magento65569.xml
code: