AmazonCustomerFactory.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Core\Domain;
  17. use Amazon\Core\Api\Data\AmazonCustomerInterface;
  18. use Amazon\Core\Api\Data\AmazonNameInterface;
  19. use Magento\Framework\Exception\LocalizedException;
  20. use Magento\Framework\ObjectManagerInterface;
  21. use Magento\Store\Model\StoreManagerInterface;
  22. use Magento\Framework\Escaper;
  23. class AmazonCustomerFactory
  24. {
  25. /**
  26. * @var ObjectManagerInterface
  27. */
  28. private $objectManager = null;
  29. /**
  30. * @var AmazonNameFactory
  31. */
  32. private $amazonNameFactory;
  33. /**
  34. * @var Escaper
  35. */
  36. private $escaper;
  37. /**
  38. * AmazonCustomerFactory constructor.
  39. *
  40. * @param ObjectManagerInterface $objectManager
  41. * @param AmazonNameFactory $amazonNameFactory
  42. * @param Escaper $escaper
  43. */
  44. public function __construct(
  45. ObjectManagerInterface $objectManager,
  46. AmazonNameFactory $amazonNameFactory,
  47. Escaper $escaper
  48. ) {
  49. $this->objectManager = $objectManager;
  50. $this->amazonNameFactory = $amazonNameFactory;
  51. $this->escaper = $escaper;
  52. }
  53. /**
  54. * @param array $data
  55. * @return AmazonCustomer
  56. */
  57. public function create(array $data = [])
  58. {
  59. $amazonName = $this->amazonNameFactory
  60. ->create(['name' => $this->escaper->escapeHtml($data['name']), 'country' => $this->escaper->escapeHtml($data['country'])]);
  61. $data[AmazonNameInterface::FIRST_NAME] = $amazonName->getFirstName();
  62. $data[AmazonNameInterface::LAST_NAME] = $amazonName->getLastName();
  63. return $this->objectManager->create(AmazonCustomer::class, ['data' => $data]);
  64. }
  65. }