Guest User

Untitled

a guest
Oct 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  3. <event name="payment_cart_collect_items_and_amounts">
  4. <observer name="add_fee_to_paypal" instance="VendorExtensionObserverAddFeeToPaypal" />
  5. </event>
  6. </config>
  7.  
  8. <?php
  9. namespace VendorExtensionObserver;
  10.  
  11. use MagentoFrameworkEventObserverInterface;
  12. use MagentoFrameworkEventObserver;
  13. use MagentoCheckoutModelSession;
  14.  
  15. class AddFeeToPaypal implements ObserverInterface
  16. {
  17. public $checkout;
  18.  
  19. public function __construct(Session $checkout)
  20. {
  21. $this->checkout = $checkout;
  22. }
  23.  
  24. public function execute(Observer $observer)
  25. {
  26. $cart = $observer->getEvent()->getCart();
  27. $quote = $this->checkout->getQuote();
  28. $address = $quote->getIsVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
  29.  
  30. if ($fee = $address->getCustomFee())
  31. {
  32. $cart->addCustomItem('Paypal Payment Fee', 1, $fee);
  33. }
  34.  
  35. return $this;
  36. }
  37. }
Add Comment
Please, Sign In to add comment