In Magento product view page,
I need to call 3rd party API with product option to get product price, and I need to change the product price dynamically.
How can I update the product price in view page so that I can pass right price to cart?
I tried adding this input tag in options.phtml,
<input type='text' name='price' value='999' />
and I click 'Add to cart' button, but the price is not changed in cart page.
please advise me,
You will not be able to set custom price in this way because when magento add a products to cart it does not take price from the form post data.
In magento,there is option of setting custom price of product at run time.So you have to call a observer on checkout_cart_product_add_after event and in that observe,get the custom price from the form post data and set the product custom price in following way:
$request=$observer->getRequestParam();
$price=$request->getPrice();
$qty=1;
$item = $observer->getQuoteItem();
$item->setCustomPrice($price*$qty);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments