コード例 #1
0
ファイル: Converter.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function updateTaxClass($taxClassId, TaxClassDataObject $taxClass)
 {
     if ($taxClass->getClassId()) {
         throw new InputException(self::CLASS_ID_NOT_ALLOWED);
     }
     $this->validateTaxClassData($taxClass);
     if (!$taxClassId) {
         throw InputException::invalidFieldValue('taxClassId', $taxClassId);
     }
     $originalTaxClassModel = $this->classModelRegistry->retrieve($taxClassId);
     $taxClassModel = $this->converter->createTaxClassModel($taxClass);
     $taxClassModel->setId($taxClassId);
     /* should not be allowed to switch the tax class type */
     if ($originalTaxClassModel->getClassType() !== $taxClassModel->getClassType()) {
         throw new InputException('Updating classType is not allowed.');
     }
     try {
         $taxClassModel->save();
     } catch (\Exception $e) {
         return false;
     }
     $this->classModelRegistry->registerTaxClass($taxClassModel);
     return true;
 }