jquery - Magento php add to cart with Custom price -
i have following issue: make calculations via jquery in frontend , want add product cart price calculated in frontend.
i wrote custom module ajaxcontroller achieve adding cart part, know struggle setting custom price.
my script looks this:
$_prod = json_decode(mage::app()->getrequest()->getpost('zapfsaeule_product')); $id = 347; // there 1 bundle product added cart viar scipt, static id enough. $params = array( 'product' => $id, 'related_product' => null, 'bundle_option' => array( 6 => 17, // static options testing purpouses 5 => 13), // 'qty' => 1 // static qty testing ); $cart = mage::getsingleton('checkout/cart'); $product = new mage_catalog_model_product(); $product->load($id); $cart->addproduct($product, $params); $cart->save(); mage::getsingleton('checkout/session')->setcartwasupdated(true); $this->getresponse()->setbody('true'); // setting response true, because ajax request. $this->getresponse()->setheader('content-type', 'text/plain'); that's code adding product. setting price tried approach mentioned in thread on stackexchange: https://magento.stackexchange.com/questions/4318/dynamically-calculated-prices-save-before-add-to-cart
but didn't work. guess event observed here doesn't occur in case, because wrote custom script.
but there still problem, if observer approach work, how pass calculated price observer?
i hope understand problem , can me solve it.
thanks in advance!
best regards, martin
reading through mage_checkout_model_cart::addproduct(), there doesn't appear way set item's price parameters. instead, you'll need add product, grab resulting item, , set price:
$cart->addproduct($product, $params) ->save(); // grab corresponding item $item = $cart->getquote()->getitembyproduct($product); // set custom price $item->setoriginalcustomprice($customprice) ->save(); haven't had time try out, should right idea. make sure set original_custom_price field (using setoriginalcustomprice()), not 1 of other prices. other prices recalculated during totals process.
Comments
Post a Comment