_classesFactory = $classesFactory; $this->_optionFactory = $optionFactory; $this->_taxClassRepository = $taxClassRepository; $this->_filterBuilder = $filterBuilder; $this->_searchCriteriaBuilder = $searchCriteriaBuilder; } /** * Retrieve all product tax class options. * * @param bool $withEmpty * @return array */ public function getAllOptions($withEmpty = true) { if (!$this->_options) { $filter = $this->_filterBuilder ->setField(ClassModel::KEY_TYPE) ->setValue(TaxClassManagementInterface::TYPE_PRODUCT) ->create(); $searchCriteria = $this->_searchCriteriaBuilder->addFilters([$filter])->create(); $searchResults = $this->_taxClassRepository->getList($searchCriteria); foreach ($searchResults->getItems() as $taxClass) { $this->_options[] = [ 'value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName(), ]; } } if ($withEmpty) { if (!$this->_options) { return [['value' => '0', 'label' => __('None')]]; } else { return array_merge([['value' => '0', 'label' => __('None')]], $this->_options); } } return $this->_options; } /** * Get a text for option value * * @param string|integer $value * @return string */ public function getOptionText($value) { $options = $this->getAllOptions(); foreach ($options as $item) { if ($item['value'] == $value) { return $item['label']; } } return false; } /** * Retrieve flat column definition * * @return array */ public function getFlatColumns() { $attributeCode = $this->getAttribute()->getAttributeCode(); return [ $attributeCode => [ 'unsigned' => true, 'default' => null, 'extra' => null, 'type' => Table::TYPE_INTEGER, 'nullable' => true, 'comment' => $attributeCode . ' tax column', ], ]; } /** * Retrieve Select for update attribute value in flat table * * @param int $store * @return \Magento\Framework\DB\Select|null */ public function getFlatUpdateSelect($store) { /** @var $option \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option */ $option = $this->_optionFactory->create(); return $option->getFlatUpdateSelect($this->getAttribute(), $store, false); } }