TaxClassBuilder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Test\Integration\Builder;
  7. use Magento\Tax\Api\Data\TaxClassInterface;
  8. use Magento\Tax\Api\Data\TaxClassInterfaceFactory;
  9. use Magento\Tax\Api\TaxClassRepositoryInterface;
  10. /**
  11. * Build a Tax Class
  12. */
  13. class TaxClassBuilder
  14. {
  15. /** @var TaxClassInterfaceFactory */
  16. private $factory;
  17. /** @var TaxClassRepositoryInterface */
  18. private $repository;
  19. /**
  20. * @param TaxClassInterfaceFactory $factory
  21. * @param TaxClassRepositoryInterface $repository
  22. */
  23. public function __construct(TaxClassInterfaceFactory $factory, TaxClassRepositoryInterface $repository)
  24. {
  25. $this->factory = $factory;
  26. $this->repository = $repository;
  27. }
  28. /**
  29. * Create and save a new tax class
  30. *
  31. * @param string $taxClassName
  32. * @param string $taxClassType One of PRODUCT or CATEGORY
  33. * @return string Tax Class ID
  34. * @throws \Magento\Framework\Exception\InputException
  35. * @throws \Magento\Framework\Exception\LocalizedException
  36. */
  37. public function createTaxClass($taxClassName, $taxClassType = 'PRODUCT')
  38. {
  39. /** @var TaxClassInterface $taxClass */
  40. $taxClass = $this->factory->create();
  41. $taxClass->setClassType($taxClassType);
  42. $taxClass->setClassName($taxClassName);
  43. return $this->repository->save($taxClass);
  44. }
  45. }