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? Commented Jun 22, 2017 at 10:43
  • @NAGARAJUKASA: Check my answer... Commented Jun 22, 2017 at 11:42
  • could you please suggest me or help me what i did mistake ? Commented 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 Commented Jun 22, 2017 at 13:34
  • @NAGARAJUKASA: $item = $observer->getEvent()->getQuoteItem(); Commented 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. Commented Jun 22, 2017 at 13:54
  • @NagarajuKasa Did you manage to do the same using controller?
    – manini
    Commented 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? Commented Nov 23, 2017 at 6:40

Your Answer

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

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