2

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 K Jun 22 '17 at 10:43
  • @NAGARAJUKASA: Check my answer... – Kaushal Suthar Jun 22 '17 at 11:42
  • could you please suggest me or help me what i did mistake ? – Nagaraju K Jun 22 '17 at 11:48
0

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 controller – Nagaraju K Jun 22 '17 at 13:34
  • @NAGARAJUKASA: $item = $observer->getEvent()->getQuoteItem(); – Kaushal Suthar Jun 22 '17 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 K Jun 22 '17 at 13:54
  • @NagarajuKasa Did you manage to do the same using controller? – manini Nov 23 '17 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 K Nov 23 '17 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.