QuotePlugin.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Express;
  7. use Magento\Quote\Model\QuoteRepository\SaveHandler;
  8. use Magento\Quote\Api\Data\CartInterface;
  9. use Magento\Quote\Model\Quote\ProductOptionFactory;
  10. /**
  11. * Plugin for Magento\Quote\Model\QuoteRepository\SaveHandler
  12. * replaces cart item product options for disabled quote
  13. * which prevents it to be processed after placement of order
  14. * via PayPal Express payment solution.
  15. */
  16. class QuotePlugin
  17. {
  18. /**
  19. * @var ProductOptionFactory
  20. */
  21. private $productOptionFactory;
  22. /**
  23. * @param ProductOptionFactory $productOptionFactory
  24. */
  25. public function __construct(
  26. ProductOptionFactory $productOptionFactory
  27. ) {
  28. $this->productOptionFactory = $productOptionFactory;
  29. }
  30. /**
  31. * Replace cart item product options for disabled quote.
  32. *
  33. * @param SaveHandler $subject
  34. * @param CartInterface $quote
  35. * @return array
  36. * @see MAGETWO-70500
  37. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  38. */
  39. public function beforeSave(SaveHandler $subject, CartInterface $quote)
  40. {
  41. if (!$quote->getIsActive()) {
  42. $items = $quote->getItems();
  43. if ($items) {
  44. foreach ($items as $item) {
  45. /** @var \Magento\Quote\Model\Quote\Item $item */
  46. if (!$item->isDeleted()) {
  47. $item->setProductOption($this->productOptionFactory->create());
  48. }
  49. }
  50. }
  51. }
  52. return [$quote];
  53. }
  54. }