/** * 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; }
/** * 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; }