12 use Magento\Tax\Api\Data\TaxRateInterfaceFactory;
14 use Magento\Tax\Api\Data\TaxRuleInterfaceFactory;
18 use Magento\Tax\Model\ResourceModel\Calculation\Rate\CollectionFactory;
43 Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX => 1,
44 Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX => 1,
45 Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT => 1,
46 Config::XML_PATH_DISPLAY_SALES_PRICE => Config::DISPLAY_TYPE_INCLUDING_TAX,
47 Config::XML_PATH_DISPLAY_SALES_SUBTOTAL => Config::DISPLAY_TYPE_INCLUDING_TAX,
48 Config::XML_PATH_DISPLAY_SALES_SHIPPING => Config::DISPLAY_TYPE_INCLUDING_TAX,
49 Config::XML_PATH_DISPLAY_SALES_DISCOUNT => Config::DISPLAY_TYPE_INCLUDING_TAX,
50 Config::XML_PATH_DISPLAY_SALES_GRANDTOTAL => Config::DISPLAY_TYPE_INCLUDING_TAX,
51 Config::XML_PATH_DISPLAY_SALES_FULL_SUMMARY => Config::DISPLAY_TYPE_INCLUDING_TAX,
52 Config::CONFIG_XML_PATH_DISPLAY_SHIPPING => Config::DISPLAY_TYPE_INCLUDING_TAX,
53 Config::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE => Config::DISPLAY_TYPE_INCLUDING_TAX,
54 Config::XML_PATH_DISPLAY_CART_PRICE => Config::DISPLAY_TYPE_INCLUDING_TAX,
55 Config::XML_PATH_DISPLAY_CART_SUBTOTAL => Config::DISPLAY_TYPE_INCLUDING_TAX,
56 Config::XML_PATH_DISPLAY_CART_SHIPPING => Config::DISPLAY_TYPE_INCLUDING_TAX,
69 private $taxRuleRepository;
74 private $taxRuleFactory;
79 private $taxRateFactory;
84 private $taxRateCollectionFactory;
89 private $taxRateRepository;
94 private $configWriter;
108 TaxRuleInterfaceFactory $taxRuleFactory,
109 CollectionFactory $taxRateCollectionFactory,
110 TaxRateInterfaceFactory $taxRateFactory,
112 ConfigWriter $configWriter
116 $this->taxRuleRepository = $taxRuleRepository;
117 $this->taxRuleFactory = $taxRuleFactory;
118 $this->taxRateCollectionFactory = $taxRateCollectionFactory;
119 $this->taxRateFactory = $taxRateFactory;
120 $this->taxRateRepository = $taxRateRepository;
130 $taxMode = $this->fixtureModel->getValue(
'tax_mode',
null);
131 $taxRules = $this->fixtureModel->getValue(
'tax_rules', 0);
133 if ($taxMode && in_array($taxMode, array_keys($this->configs))) {
134 $this->setTaxMode($taxMode);
137 $taxRateIds = $this->taxRateCollectionFactory->create()->getAllIds();
138 $taxRatesCount = count($taxRateIds);
142 $taxRuleDataObject = $this->taxRuleFactory->create();
143 $taxRuleDataObject->setCode(
'Tax_Rule_' .
$taxRules)
144 ->setTaxRateIds([$taxRateIds[
$taxRules % $taxRatesCount]])
145 ->setCustomerTaxClassIds([self::DEFAULT_CUSTOMER_TAX_CLASS_ID])
146 ->setProductTaxClassIds([self::DEFAULT_PRODUCT_TAX_CLASS_ID])
150 $this->taxRuleRepository->save($taxRuleDataObject);
162 private function setTaxMode($taxMode)
166 $taxRate = $this->taxRateFactory->create();
168 ->setRate(self::DEFAULT_TAX_RATE)
169 ->setTaxCountryId(self::DEFAULT_TAX_COUNTRY)
170 ->setTaxPostcode(
'*');
172 $taxRateData = $this->taxRateRepository->save(
$taxRate);
176 $taxRuleDataObject = $this->taxRuleFactory->create();
177 $taxRuleDataObject->setCode($taxMode)
178 ->setTaxRateIds([$taxRateData->getId()])
179 ->setCustomerTaxClassIds([self::DEFAULT_CUSTOMER_TAX_CLASS_ID])
180 ->setProductTaxClassIds([self::DEFAULT_PRODUCT_TAX_CLASS_ID])
184 $this->taxRuleRepository->save($taxRuleDataObject);
187 $this->setConfigByTaxMode($taxMode);
196 private function setConfigByTaxMode(
$mode = self::DEFAULT_TAX_MODE)
198 if (isset($this->configs[
$mode]) && is_array($this->configs[
$mode])) {
199 foreach ($this->configs[
$mode] as $configPath =>
$value) {
200 $this->configWriter->save(
213 return 'Generating tax rules';
222 'tax_rules' =>
'Tax Rules Count',
223 'tax_mode' =>
'Tax Mode',
const DEFAULT_PRODUCT_TAX_CLASS_ID
const XML_PATH_TAX_WEEE_ENABLE
const DEFAULT_CUSTOMER_TAX_CLASS_ID
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
const DEFAULT_TAX_COUNTRY
__construct(FixtureModel $fixtureModel, TaxRuleRepositoryInterface $taxRuleRepository, TaxRuleInterfaceFactory $taxRuleFactory, CollectionFactory $taxRateCollectionFactory, TaxRateInterfaceFactory $taxRateFactory, TaxRateRepositoryInterface $taxRateRepository, ConfigWriter $configWriter)