Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
tax_classes_rollback.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 
12  'Test Rule',
13  'Test Rule Duplicate',
14 ];
16  'ProductTaxClass1',
17  'ProductTaxClass2',
18  'ProductTaxClass3',
19  'CustomerTaxClass1',
20  'CustomerTaxClass2',
21 ];
22 
23 
24 $taxRuleResource = $objectManager->get(\Magento\Tax\Model\ResourceModel\Calculation\Rule::class);
25 foreach ($taxRules as $taxRuleCode) {
26  $taxRule = $objectManager->create(\Magento\Tax\Model\Calculation\Rule::class);
27  $taxRuleResource->load($taxRule, $taxRuleCode, 'code');
28  $taxRuleResource->delete($taxRule);
29 }
30 
32 $resourceModel = $objectManager->get(\Magento\Tax\Model\ResourceModel\TaxClass::class);
33 
34 foreach ($taxClasses as $taxClass) {
35  try {
37  $taxClassEntity = $objectManager->create(\Magento\Tax\Model\ClassModel::class);
38  $resourceModel->load($taxClassEntity, $taxClass, 'class_name');
39  $resourceModel->delete($taxClassEntity);
40  } catch (\Magento\Framework\Exception\CouldNotDeleteException $couldNotDeleteException) {
41  // It's okay if the entity already wiped from the database
42  }
43 }
$taxRule
Definition: tax_rule.php:35