14 use Magento\Tax\Setup\TaxSetupFactory;
25 private $taxSetupFactory;
30 private $directoryRegionFactory;
35 private $moduleDataSetup;
44 TaxSetupFactory $taxSetupFactory,
48 $this->taxSetupFactory = $taxSetupFactory;
49 $this->directoryRegionFactory = $directoryRegionFactory;
50 $this->moduleDataSetup = $moduleDataSetup;
56 public function apply()
59 $taxSetup = $this->taxSetupFactory->create([
'resourceName' =>
'tax_setup',
'setup' => $this->moduleDataSetup]);
64 $taxSetup->addAttribute(
65 \
Magento\Catalog\Model\Product::ENTITY,
68 'group' =>
'Product Details',
73 'label' =>
'Tax Class',
76 'source' => \
Magento\Tax\Model\TaxClass\Source\Product::class,
77 'global' => \
Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
80 'user_defined' =>
false,
83 'filterable' =>
false,
84 'comparable' =>
false,
85 'visible_on_front' =>
false,
86 'visible_in_advanced_search' =>
false,
87 'used_in_product_listing' =>
true,
89 'apply_to' => implode(
',', $taxSetup->getTaxableItems()),
90 'is_used_in_grid' =>
true,
91 'is_visible_in_grid' =>
false,
92 'is_filterable_in_grid' =>
true,
101 'class_name' =>
'Taxable Goods',
106 'class_name' =>
'Retail Customer',
111 $this->moduleDataSetup->getConnection()->insertForce(
112 $this->moduleDataSetup->getTable(
'tax_class'),
120 $region = $this->directoryRegionFactory->create();
123 'tax_calculation_rate_id' => 1,
124 'tax_country_id' =>
'US',
125 'tax_region_id' => $region->loadByCode(
'CA',
'US')->getRegionId(),
126 'tax_postcode' =>
'*',
127 'code' =>
'US-CA-*-Rate 1',
131 'tax_calculation_rate_id' => 2,
132 'tax_country_id' =>
'US',
133 'tax_region_id' => $region->loadByCode(
'NY',
'US')->getRegionId(),
134 'tax_postcode' =>
'*',
135 'code' =>
'US-NY-*-Rate 1',
140 $this->moduleDataSetup->getConnection()->insertForce(
141 $this->moduleDataSetup->getTable(
'tax_calculation_rate'),
const TAX_CLASS_TYPE_CUSTOMER
__construct(TaxSetupFactory $taxSetupFactory, RegionFactory $directoryRegionFactory, \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)
const TAX_CLASS_TYPE_PRODUCT