cancel
Showing results for 
Search instead for 
Did you mean: 

Facing Issue while creating Order,Cart rule is getting applied

Facing Issue while creating Order,Cart rule is getting applied

A cart price rule is set in the magento ,so when an order is being prepared in an extension a rule is applied on the quote due to which a discount is applied on the final order,I don't want to remove the cart rule,but need to change make some changes in the extension while generating quote,so that no cart-rule can get applied on the final order.
Already Tried
quote->setAppliedRuleIds(' ')
quote->setcouponcode(' ')
quote->setDiscount('0')
removed quote->collecttotal->save()

Discount is getting applied on the final price of the order

1 REPLY 1

Re: Facing Issue while creating Order,Cart rule is getting applied

Try This One :

After Preparing Quote And Before Submitting To Get Order Object

try {
    // Override CartPrice Rules On Quote : 
    $quote->setCouponCode('');
    $quote->setAppliedRuleIds('');
    // end
    
    $quote->collectTotals()->save();
    
    // Setting Discount on items :
    foreach ($quote->getAllItems() as $item) {
         $item->setDiscountAmount(0);
         $item->setBaseDiscountAmount(0);
         $item->save();
     }
    // end
    
    // Submitting Quote To get Order Object
    
    /** @var \Magento\Quote\Api\CartManagementInterface  */
    $order = $this->cartManagementInterface->submit($quote);
    // end
    
    // Override CartPrice Rules On Order : 
    $order->setCouponCode('');
    $order->setAppliedRuleIds('');
    // end 

    // Setting Discount Amount on Order
    $order->setDiscountAmount(0); 
    $order->setBaseDiscountAmount(0);
    // end

    $order->save();

} catch (\Exception $exception) {
    // Silence Or Log The Error/Exception
    
}


Click on 'Kudos' & Accept as Solution to encourage to write more answers !