I am using Magento 2.2.5 Enterprise Edition. I need to pass Custom Discount to Paypal express. That is My warranty discount. For this I am using payment_cart_collect_items_and_amounts Observer.
<event name="payment_cart_collect_items_and_amounts"> <observer name="warranty_paypal_express" instance="Vendor\Module\Observer\Addamounttopaypal" /> </event>
This is my Observer code
public function execute(Observer $observer) { /** @var \Magento\Payment\Model\Cart $cart */ $cart = $observer->getEvent()->getCart(); $customAmount = $this->helper->getBaseWarrantyAmt(); $handlingfee = $this->extafeehelper->getExtrafee(); $discounntWarranty = $this->helper->getWarrayDiscountAmt(); if($customAmount && $customAmount>0){ $cart->addCustomItem(__('Warranty Amount'), 1, $customAmount, 'basewarranty'); } if($discounntWarranty){ $cart->setDiscount($discounntWarranty); $discountnamt = -1.00 * $discounntWarranty; $cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount'); } if($handlingfee){ $cart->addCustomItem(__('Environment Handling Fees'), 1, $handlingfee, 'fee'); } }
Custom Amount is adding fine. But the issue is with Discount. For the Discount i am adding negative value.
'$cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount');'
But the Amount is getting passed. and got error for total mismatch. Then I add the following code
'$cart->setDiscount($discounntWarranty); $discountnamt = -1.00 * $discounntWarranty; $cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount');'
Now Warranty Discount and discount is adding. But i only need Warranty Discount. Custom Discount is not adding without $cart->setDiscount($discounntWarranty);
@ankurkinex - did you manage to resolve this problem?
@Saggitator Yes
Can you please share how did you manage to solve?
Can you please share your code?