/** * Convert tax class service data object into tax class model. * * @param TaxClass $taxClass * @return TaxClassModel */ public function createTaxClassModel(TaxClass $taxClass) { /** @var TaxClassModel $taxClassModel */ $taxClassModel = $this->taxClassFactory->create(); $taxClassModel->setId($taxClass->getClassId())->setClassName($taxClass->getClassName())->setClassType($taxClass->getClassType()); return $taxClassModel; }
/** * Creates new tax class. * * @param string $taxClassName * @param AbstractType $productTypeModel * @return integer */ protected function createTaxClass($taxClassName, AbstractType $productTypeModel) { /** @var \Magento\Tax\Model\ClassModelFactory $taxClass */ $taxClass = $this->classModelFactory->create(); $taxClass->setClassType(ClassModel::TAX_CLASS_TYPE_PRODUCT); $taxClass->setClassName($taxClassName); $taxClass->save(); $id = $taxClass->getId(); $productTypeModel->addAttributeOption(self::ATRR_CODE, $id, $id); return $id; }
/** * Retrieve tax class model from the registry * * @param int $taxClassId * @return TaxClassModel * @throws NoSuchEntityException */ public function retrieve($taxClassId) { if (isset($this->taxClassRegistryById[$taxClassId])) { return $this->taxClassRegistryById[$taxClassId]; } /** @var TaxClassModel $taxClassModel */ $taxClassModel = $this->taxClassModelFactory->create()->load($taxClassId); if (!$taxClassModel->getId()) { // tax class does not exist throw NoSuchEntityException::singleField(TaxClass::KEY_ID, $taxClassId); } $this->taxClassRegistryById[$taxClassModel->getId()] = $taxClassModel; return $taxClassModel; }
/** * Get tax class name * * @return string */ public function getTaxClassName() { $taxClassName = $this->getData('tax_class_name'); if ($taxClassName) { return $taxClassName; } $classModel = $this->classModelFactory->create(); $classModel->load($this->getTaxClassId()); $taxClassName = $classModel->getClassName(); $this->setData('tax_class_name', $taxClassName); return $taxClassName; }