SellerBuilder.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Api\Data;
  7. use Vertex\Data\SellerInterface;
  8. use Vertex\Data\SellerInterfaceFactory;
  9. use Vertex\Tax\Model\Config;
  10. /**
  11. * Create a {@see SellerInterface} from store configuration
  12. */
  13. class SellerBuilder
  14. {
  15. /** @var AddressBuilder */
  16. private $addressBuilder;
  17. /** @var Config */
  18. private $config;
  19. /** @var SellerInterfaceFactory */
  20. private $sellerFactory;
  21. /** @var string */
  22. private $scopeCode;
  23. /** @var string */
  24. private $scopeType;
  25. /**
  26. * @param SellerInterfaceFactory $sellerFactory
  27. * @param Config $config
  28. * @param AddressBuilder $addressBuilder
  29. */
  30. public function __construct(SellerInterfaceFactory $sellerFactory, Config $config, AddressBuilder $addressBuilder)
  31. {
  32. $this->sellerFactory = $sellerFactory;
  33. $this->config = $config;
  34. $this->addressBuilder = $addressBuilder;
  35. }
  36. /**
  37. * Create a {@see SellerInterface} from store configuration
  38. *
  39. * @return SellerInterface
  40. */
  41. public function build()
  42. {
  43. /** @var SellerInterface $seller */
  44. $seller = $this->sellerFactory->create();
  45. $street = [
  46. $this->config->getCompanyStreet1($this->scopeCode, $this->scopeType),
  47. $this->config->getCompanyStreet2($this->scopeCode, $this->scopeType)
  48. ];
  49. $address = $this->addressBuilder
  50. ->setStreet($street)
  51. ->setCity($this->config->getCompanyCity($this->scopeCode, $this->scopeType))
  52. ->setRegionId($this->config->getCompanyRegionId($this->scopeCode, $this->scopeType))
  53. ->setPostalCode($this->config->getCompanyPostalCode($this->scopeCode, $this->scopeType))
  54. ->setCountryCode($this->config->getCompanyCountry($this->scopeCode, $this->scopeType))
  55. ->build();
  56. $seller->setPhysicalOrigin($address);
  57. if ($this->config->getCompanyCode($this->scopeCode, $this->scopeType)) {
  58. $seller->setCompanyCode($this->config->getCompanyCode($this->scopeCode, $this->scopeType));
  59. }
  60. return $seller;
  61. }
  62. /**
  63. * Set the Scope Code
  64. *
  65. * @param string|null $scopeCode
  66. * @return SellerBuilder
  67. */
  68. public function setScopeCode($scopeCode)
  69. {
  70. $this->scopeCode = $scopeCode;
  71. return $this;
  72. }
  73. /**
  74. * Set the Scope Type
  75. *
  76. * @param string|null $scopeType
  77. * @return SellerBuilder
  78. */
  79. public function setScopeType($scopeType)
  80. {
  81. $this->scopeType = $scopeType;
  82. return $this;
  83. }
  84. }