/** * Convert a rate model to a TaxRate data object * * @param TaxRuleModel $ruleModel * @return TaxRuleDataObject */ public function createTaxRuleDataObjectFromModel(TaxRuleModel $ruleModel) { if (!is_null($ruleModel->getId())) { $this->taxRuleDataObjectBuilder->setId($ruleModel->getId()); } if (!is_null($ruleModel->getCode())) { $this->taxRuleDataObjectBuilder->setCode($ruleModel->getCode()); } if (!is_null($ruleModel->getCustomerTaxClasses())) { $this->taxRuleDataObjectBuilder->setCustomerTaxClassIds($this->_getUniqueValues($ruleModel->getCustomerTaxClasses())); } if (!is_null($ruleModel->getProductTaxClasses())) { $this->taxRuleDataObjectBuilder->setProductTaxClassIds($this->_getUniqueValues($ruleModel->getProductTaxClasses())); } if (!is_null($ruleModel->getRates())) { $this->taxRuleDataObjectBuilder->setTaxRateIds($this->_getUniqueValues($ruleModel->getRates())); } if (!is_null($ruleModel->getPriority())) { $this->taxRuleDataObjectBuilder->setPriority($ruleModel->getPriority()); } if (!is_null($ruleModel->getPosition())) { $this->taxRuleDataObjectBuilder->setSortOrder($ruleModel->getPosition()); } if (!is_null($ruleModel->getCalculateSubtotal())) { $this->taxRuleDataObjectBuilder->setCalculateSubtotal($ruleModel->getCalculateSubtotal()); } return $this->taxRuleDataObjectBuilder->create(); }
/** * Initialize tax rule service object with form data. * * @param array $postData * @return \Magento\Tax\Service\V1\Data\TaxRule */ protected function populateTaxRule($postData) { if (isset($postData['tax_calculation_rule_id'])) { $this->ruleBuilder->setId($postData['tax_calculation_rule_id']); } if (isset($postData['code'])) { $this->ruleBuilder->setCode($postData['code']); } if (isset($postData['tax_rate'])) { $this->ruleBuilder->setTaxRateIds($postData['tax_rate']); } if (isset($postData['tax_customer_class'])) { $this->ruleBuilder->setCustomerTaxClassIds($postData['tax_customer_class']); } if (isset($postData['tax_product_class'])) { $this->ruleBuilder->setProductTaxClassIds($postData['tax_product_class']); } if (isset($postData['priority'])) { $this->ruleBuilder->setPriority($postData['priority']); } if (isset($postData['calculate_subtotal'])) { $this->ruleBuilder->setCalculateSubtotal($postData['calculate_subtotal']); } if (isset($postData['position'])) { $this->ruleBuilder->setSortOrder($postData['position']); } return $this->ruleBuilder->create(); }