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?

3
  • hi @suthar did u get the solution for the above question? Jun 22, 2017 at 10:43
  • @NAGARAJUKASA: Check my answer... Jun 22, 2017 at 11:42
  • could you please suggest me or help me what i did mistake ? Jun 22, 2017 at 11:48

1 Answer 1

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();
}
7
  • hi kaushal please let me know how can use $item in my controller Jun 22, 2017 at 13:34
  • @NAGARAJUKASA: $item = $observer->getEvent()->getQuoteItem(); 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. Jun 22, 2017 at 13:54
  • @NagarajuKasa Did you manage to do the same using controller?
    – manini
    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? Nov 23, 2017 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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