Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxClass.php
Go to the documentation of this file.
1 <?php
7 
11 class TaxClass extends \Magento\Framework\App\Config\Value
12 {
16  protected $resourceConfig;
17 
21  protected $attributeFactory;
22 
34  public function __construct(
35  \Magento\Framework\Model\Context $context,
36  \Magento\Framework\Registry $registry,
38  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
40  \Magento\Eav\Model\Entity\AttributeFactory $attributeFactory,
41  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
42  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
43  array $data = []
44  ) {
45  $this->resourceConfig = $resourceConfig;
46  $this->attributeFactory = $attributeFactory;
47  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
48  }
49 
55  public function afterSave()
56  {
57  $attributeCode = "tax_class_id";
58 
59  $attribute = $this->attributeFactory->create();
60  $attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
61  if (!$attribute->getId()) {
62  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid attribute %1', $attributeCode));
63  }
64  $attribute->setData("default_value", $this->getData('value'));
65  $attribute->save();
66 
67  return parent::afterSave();
68  }
69 }
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Config\Model\ResourceModel\Config $resourceConfig, \Magento\Eav\Model\Entity\AttributeFactory $attributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: TaxClass.php:34
getData($key='', $index=null)
Definition: DataObject.php:119
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$attributeCode
Definition: extend.phtml:12