DisableAmazonPaymentMethod.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: miche
  5. * Date: 7/24/2018
  6. * Time: 9:53 AM
  7. */
  8. namespace Amazon\Payment\Plugin;
  9. use Magento\Checkout\Model\Session;
  10. /**
  11. * Class DisableAmazonPaymentMethod
  12. * Plugin removes Amazon Payment Method if cart contains only virtual products.
  13. */
  14. class DisableAmazonPaymentMethod
  15. {
  16. /**
  17. * @var Session
  18. */
  19. private $checkoutSession;
  20. /**
  21. * DisableAmazonPaymentMethod constructor.
  22. * @param Session $checkoutSession
  23. */
  24. public function __construct(
  25. Session $checkoutSession
  26. ) {
  27. $this->checkoutSession = $checkoutSession;
  28. }
  29. /**
  30. * @param \Amazon\Payment\Model\Method\AmazonLoginMethod $subject
  31. * @param $result
  32. * @return bool
  33. */
  34. public function afterIsAvailable(
  35. \Amazon\Payment\Model\Method\AmazonLoginMethod $subject,
  36. $result
  37. ) {
  38. /** @var \Magento\Quote\Model\Quote $quote */
  39. $quote = $this->checkoutSession->getQuote();
  40. if ($quote->isVirtual()) {
  41. return false;
  42. }
  43. return $result; // return default result
  44. }
  45. }