I want to add product with custom price in cart/checkout only but the original price of product should not get any affect.
So far I've achieved this.I'm adding product programmatically based on some condition. Not using any observer or something I'm just passing product id to my custom controller and adding that product into cart.
public function execute(){
 ....
 $productObj->setData('_edit_mode', true);
 $productObj->setPrice(8000);
 $productObj->setFinalPrice(8000);
 $productObj->save();
 $this->cart->addProduct($productObj, $product);
 ....
 $this->cart->save();
}
Using above function only product original price get changed but not in cart so what can be done to do so?
- 
 hi @suthar did u get the solution for the above question?Nagaraju Kasa– Nagaraju Kasa2017年06月22日 10:43:49 +00:00Commented Jun 22, 2017 at 10:43
- 
 @NAGARAJUKASA: Check my answer...Kaushal Suthar– Kaushal Suthar2017年06月22日 11:42:42 +00:00Commented Jun 22, 2017 at 11:42
- 
 could you please suggest me or help me what i did mistake ?Nagaraju Kasa– Nagaraju Kasa2017年06月22日 11:48:23 +00:00Commented Jun 22, 2017 at 11:48
1 Answer 1
I've resolved by following
public function execute(){
 ....
 $finalPrice = $totalQty * $product->getKrat() * $price;
 $item->setCustomPrice($product->getKrat() * $price);
 $item->setOriginalCustomPrice($finalPrice);
 $item->getProduct()->setIsSuperMode(true);
 $item->setQty(0);
 $item->save();
}
- 
 hi kaushal please let me know how can use $item in my controllerNagaraju Kasa– Nagaraju Kasa2017年06月22日 13:34:54 +00:00Commented Jun 22, 2017 at 13:34
- 
 @NAGARAJUKASA: $item = $observer->getEvent()->getQuoteItem();Kaushal Suthar– Kaushal Suthar2017年06月22日 13:50:31 +00:00Commented Jun 22, 2017 at 13:50
- 
 i am adding the product to cart from the custom controller but u have given the observer code. please suggest me.Nagaraju Kasa– Nagaraju Kasa2017年06月22日 13:54:17 +00:00Commented Jun 22, 2017 at 13:54
- 
 @NagarajuKasa Did you manage to do the same using controller?manini– manini2017年11月23日 06:03:36 +00:00Commented Nov 23, 2017 at 6:03
- 
 @manini yes manini we can able to add a product through controller. but please confirm me whether you want to add same product price or custom price?Nagaraju Kasa– Nagaraju Kasa2017年11月23日 06:40:09 +00:00Commented Nov 23, 2017 at 6:40