I'd like have a product that is basically a calculator, which I will build in Javascript. I want the add to cart process to grab the generated price from the page and submit it to the cart - which is as far as I have got.
I've created an observer to hook into the checkout_cart_product_add_after event and update the quote item price based on a field value in the submitted form, which works.
The problem I have is that, if you add a second or multiple versions of the item with different prices, it updates all the other versions in the cart to the same price - so you can never have multiples of the same item in the cart with different prices.
Anyone have any ideas? Here's the code in my observer:
public function modifyPrice(Varien_Event_Observer $observer) {
$customprice = $_POST["customprice"];
$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
if ($customprice > 0) {
$item->setCustomPrice($customprice);
$item->setOriginalCustomPrice($customprice);
$item->getProduct()->setIsSuperMode(true);
}
}