QuoteLinkManagement.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Model;
  17. use Amazon\Payment\Api\QuoteLinkManagementInterface;
  18. use Amazon\Payment\Api\Data\QuoteLinkInterfaceFactory;
  19. use Magento\Quote\Api\Data\CartExtensionFactory;
  20. use Magento\Quote\Api\Data\CartInterface;
  21. class QuoteLinkManagement implements QuoteLinkManagementInterface
  22. {
  23. /**
  24. * @var CartExtensionFactory
  25. */
  26. private $cartExtensionFactory;
  27. /**
  28. * @var QuoteLinkInterfaceFactory
  29. */
  30. private $quoteLinkFactory;
  31. /**
  32. * @param CartExtensionFactory $cartExtensionFactory
  33. * @param QuoteLinkInterfaceFactory $quoteLinkFactory
  34. */
  35. public function __construct(
  36. CartExtensionFactory $cartExtensionFactory,
  37. QuoteLinkInterfaceFactory $quoteLinkFactory
  38. ) {
  39. $this->cartExtensionFactory = $cartExtensionFactory;
  40. $this->quoteLinkFactory = $quoteLinkFactory;
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function setAmazonOrderReferenceIdExtensionAttribute(CartInterface $cart)
  46. {
  47. $cartExtension = ($cart->getExtensionAttributes()) ?: $this->cartExtensionFactory->create();
  48. $amazonQuote = $this->quoteLinkFactory->create();
  49. $amazonQuote->load($cart->getId(), 'quote_id');
  50. if ($amazonQuote->getId()) {
  51. $cartExtension->setAmazonOrderReferenceId($amazonQuote);
  52. }
  53. $cart->setExtensionAttributes($cartExtension);
  54. }
  55. }