CustomerRepository.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\Login\Plugin;
  17. use Amazon\Core\Helper\Data as AmazonHelper;
  18. use Amazon\Login\Api\CustomerManagementInterface;
  19. use Magento\Customer\Api\CustomerRepositoryInterface;
  20. use Magento\Customer\Api\Data\CustomerInterface;
  21. class CustomerRepository
  22. {
  23. /**
  24. * @var CustomerManagementInterface
  25. */
  26. private $customerManagement;
  27. /**
  28. * @var AmazonHelper
  29. */
  30. private $amazonHelper;
  31. /**
  32. * CustomerRepository constructor.
  33. *
  34. * @param CustomerManagementInterface $customerManagement
  35. * @param AmazonHelper $amazonHelper
  36. */
  37. public function __construct(
  38. CustomerManagementInterface $customerManagement,
  39. AmazonHelper $amazonHelper
  40. ) {
  41. $this->customerManagement = $customerManagement;
  42. $this->amazonHelper = $amazonHelper;
  43. }
  44. /**
  45. * Add amazon id extension attribute to customer
  46. *
  47. * @param CustomerRepositoryInterface $customerRepository
  48. * @param CustomerInterface $customer
  49. *
  50. * @return CustomerInterface
  51. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  52. */
  53. public function afterGetById(CustomerRepositoryInterface $customerRepository, CustomerInterface $customer)
  54. {
  55. if ($this->amazonHelper->isEnabled()) {
  56. $this->customerManagement->setAmazonIdExtensionAttribute($customer);
  57. }
  58. return $customer;
  59. }
  60. /**
  61. * Add amazon id extension attribute to customer
  62. *
  63. * @param CustomerRepositoryInterface $customerRepository
  64. * @param CustomerInterface $customer
  65. *
  66. * @return CustomerInterface
  67. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  68. */
  69. public function afterGet(CustomerRepositoryInterface $customerRepository, CustomerInterface $customer)
  70. {
  71. if ($this->amazonHelper->isEnabled()) {
  72. $this->customerManagement->setAmazonIdExtensionAttribute($customer);
  73. }
  74. return $customer;
  75. }
  76. }