Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
- <event name="payment_cart_collect_items_and_amounts">
- <observer name="add_fee_to_paypal" instance="VendorExtensionObserverAddFeeToPaypal" />
- </event>
- </config>
- <?php
- namespace VendorExtensionObserver;
- use MagentoFrameworkEventObserverInterface;
- use MagentoFrameworkEventObserver;
- use MagentoCheckoutModelSession;
- class AddFeeToPaypal implements ObserverInterface
- {
- public $checkout;
- public function __construct(Session $checkout)
- {
- $this->checkout = $checkout;
- }
- public function execute(Observer $observer)
- {
- $cart = $observer->getEvent()->getCart();
- $quote = $this->checkout->getQuote();
- $address = $quote->getIsVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
- if ($fee = $address->getCustomFee())
- {
- $cart->addCustomItem('Paypal Payment Fee', 1, $fee);
- }
- return $this;
- }
- }
Add Comment
Please, Sign In to add comment