Example #1
0
 public function testCreateCheckout()
 {
     $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods([])->getMock();
     $instance = $this->getMockBuilder('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface')->getMock();
     $this->objectManagerMock->expects($this->once())->method('create')->with(Factory::CHECKOUT_VALIDATOR)->will($this->returnValue($instance));
     $this->assertInstanceOf('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface', $this->factory->create($checkoutMock));
 }
 /**
  * Add PayPal shortcut buttons
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
     $shortcutButtons = $observer->getEvent()->getContainer();
     $blocks = ['Magento\\Paypal\\Block\\Express\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsExpress\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\PayflowExpress\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS, 'Magento\\Paypal\\Block\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsBml\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\Payflow\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS];
     foreach ($blocks as $blockInstanceName => $paymentMethodCode) {
         if (!$this->paypalConfig->isMethodAvailable($paymentMethodCode)) {
             continue;
         }
         $params = ['shortcutValidator' => $this->shortcutFactory->create($observer->getEvent()->getCheckoutSession())];
         if (!in_array('Bml', explode('\\', $blockInstanceName))) {
             $params['checkoutSession'] = $observer->getEvent()->getCheckoutSession();
         }
         // we believe it's \Magento\Framework\View\Element\Template
         $shortcut = $shortcutButtons->getLayout()->createBlock($blockInstanceName, '', $params);
         $shortcut->setIsInCatalogProduct($observer->getEvent()->getIsCatalogProduct())->setShowOrPosition($observer->getEvent()->getOrPosition());
         $shortcutButtons->addShortcut($shortcut);
     }
 }
Example #3
0
 /**
  * Add PayPal shortcut buttons
  *
  * @param EventObserver $observer
  * @return void
  */
 public function addPaypalShortcuts(EventObserver $observer)
 {
     /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
     $shortcutButtons = $observer->getEvent()->getContainer();
     $blocks = ['Magento\\Paypal\\Block\\Express\\Shortcut', 'Magento\\Paypal\\Block\\PayflowExpress\\Shortcut', 'Magento\\Paypal\\Block\\Bml\\Shortcut', 'Magento\\Paypal\\Block\\Payflow\\Bml\\Shortcut'];
     foreach ($blocks as $blockInstanceName) {
         $params = ['shortcutValidator' => $this->_shortcutFactory->create($observer->getEvent()->getCheckoutSession())];
         if (!in_array('Bml', explode('/', $blockInstanceName))) {
             $params['checkoutSession'] = $observer->getEvent()->getCheckoutSession();
         }
         // we believe it's \Magento\Framework\View\Element\Template
         $shortcut = $shortcutButtons->getLayout()->createBlock($blockInstanceName, '', $params);
         $shortcut->setIsInCatalogProduct($observer->getEvent()->getIsCatalogProduct())->setShowOrPosition($observer->getEvent()->getOrPosition())->setTemplate(self::SHORTCUT_TEMPLATE);
         $shortcutButtons->addShortcut($shortcut);
     }
 }