AddPaypalShortcuts.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Observer;
  7. use Magento\Framework\Event\Observer;
  8. use Magento\Catalog\Block\ShortcutButtons;
  9. use Magento\Framework\Event\ObserverInterface;
  10. /**
  11. * Class AddPaypalShortcuts
  12. */
  13. class AddPaypalShortcuts implements ObserverInterface
  14. {
  15. /**
  16. * Block class
  17. */
  18. const PAYPAL_SHORTCUT_BLOCK = \Magento\Braintree\Block\Paypal\Button::class;
  19. /**
  20. * Add Braintree PayPal shortcut buttons
  21. *
  22. * @param Observer $observer
  23. * @return void
  24. */
  25. public function execute(Observer $observer)
  26. {
  27. // Remove button from catalog pages
  28. if ($observer->getData('is_catalog_product')) {
  29. return;
  30. }
  31. /** @var ShortcutButtons $shortcutButtons */
  32. $shortcutButtons = $observer->getEvent()->getContainer();
  33. $shortcut = $shortcutButtons->getLayout()->createBlock(self::PAYPAL_SHORTCUT_BLOCK);
  34. $shortcutButtons->addShortcut($shortcut);
  35. }
  36. }