/**
  * Creates a collection item that represents a tax rule for the tax rules grid.
  *
  * @param TaxRuleInterface $taxRule Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a tax rule
  */
 protected function createTaxRuleCollectionItem(TaxRuleInterface $taxRule)
 {
     $collectionItem = new \Magento\Framework\Object();
     $collectionItem->setTaxCalculationRuleId($taxRule->getId());
     $collectionItem->setCode($taxRule->getCode());
     /* should cast to string so that some optional fields won't be null on the collection grid pages */
     $collectionItem->setPriority((string) $taxRule->getPriority());
     $collectionItem->setPosition((string) $taxRule->getPosition());
     $collectionItem->setCalculateSubtotal($taxRule->getCalculateSubtotal() ? '1' : '0');
     $collectionItem->setCustomerTaxClasses($taxRule->getCustomerTaxClassIds());
     $collectionItem->setProductTaxClasses($taxRule->getProductTaxClassIds());
     $collectionItem->setTaxRates($taxRule->getTaxRateIds());
     return $collectionItem;
 }
Example #2
0
 /**
  * Extract tax rule data in a format which is
  *
  * @param \Magento\Tax\Api\Data\TaxRuleInterface $taxRule
  * @return array
  */
 protected function extractTaxRuleData($taxRule)
 {
     $taxRuleData = ['code' => $taxRule->getCode(), 'tax_customer_class' => $taxRule->getCustomerTaxClassIds(), 'tax_product_class' => $taxRule->getProductTaxClassIds(), 'tax_rate' => $taxRule->getTaxRateIds(), 'priority' => $taxRule->getPriority(), 'position' => $taxRule->getPosition(), 'calculate_subtotal' => $taxRule->getCalculateSubtotal()];
     return $taxRuleData;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function delete(TaxRuleInterface $rule)
 {
     $ruleId = $rule->getId();
     $this->resource->delete($rule);
     $this->taxRuleRegistry->removeTaxRule($ruleId);
     return true;
 }