Exemple #1
0
 /**
  * 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();
 }
Exemple #2
0
 /**
  * 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();
 }
Exemple #3
0
 /**
  * @param array $dataArray
  * @return TaxRuleSearchResults
  */
 protected function generateDataObjectWithSetters($dataArray)
 {
     $this->builder->populateWithArray([]);
     if (array_key_exists(TaxRuleSearchResults::KEY_ITEMS, $dataArray)) {
         $items = [];
         foreach ($dataArray[TaxRuleSearchResults::KEY_ITEMS] as $itemArray) {
             $items[] = $this->taxRuleBuilder->populateWithArray($itemArray)->create();
         }
         $this->builder->setItems($items);
     }
     if (array_key_exists(TaxRuleSearchResults::KEY_TOTAL_COUNT, $dataArray)) {
         $this->builder->setTotalCount($dataArray[TaxRuleSearchResults::KEY_TOTAL_COUNT]);
     }
     if (array_key_exists(TaxRuleSearchResults::KEY_SEARCH_CRITERIA, $dataArray)) {
         $this->builder->setSearchCriteria($this->searchCriteriaBuilder->populateWithArray($dataArray[TaxRuleSearchResults::KEY_SEARCH_CRITERIA])->create());
     }
     return $this->builder->create();
 }
Exemple #4
0
 /**
  * Creates Tax Rule Data Object
  *
  * @return \Magento\Tax\Service\V1\Data\TaxRule
  */
 private function createTaxRuleDataObject()
 {
     return $this->taxRuleBuilder->setCode('code')->setCustomerTaxClassIds([3])->setProductTaxClassIds([2])->setTaxRateIds([2])->setPriority(0)->setSortOrder(1)->create();
 }