Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxRuleCollection.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Tax\Model;
8 
16 
21 {
25  protected $ruleService;
26 
36  public function __construct(
37  EntityFactory $entityFactory,
42  ) {
43  parent::__construct($entityFactory, $filterBuilder, $searchCriteriaBuilder, $sortOrderBuilder);
44  $this->ruleService = $ruleService;
45  }
46 
50  public function loadData($printQuery = false, $logQuery = false)
51  {
52  if (!$this->isLoaded()) {
53  $searchCriteria = $this->getSearchCriteria();
54  $searchResults = $this->ruleService->getList($searchCriteria);
55  $this->_totalRecords = $searchResults->getTotalCount();
56  foreach ($searchResults->getItems() as $taxRule) {
58  }
59  $this->_setIsLoaded();
60  }
61  return $this;
62  }
63 
71  {
72  $collectionItem = new \Magento\Framework\DataObject();
73  $collectionItem->setTaxCalculationRuleId($taxRule->getId());
74  $collectionItem->setCode($taxRule->getCode());
75  /* should cast to string so that some optional fields won't be null on the collection grid pages */
76  $collectionItem->setPriority((string)$taxRule->getPriority());
77  $collectionItem->setPosition((string)$taxRule->getPosition());
78  $collectionItem->setCalculateSubtotal($taxRule->getCalculateSubtotal() ? '1' : '0');
79  $collectionItem->setCustomerTaxClasses($taxRule->getCustomerTaxClassIds());
80  $collectionItem->setProductTaxClasses($taxRule->getProductTaxClassIds());
81  $collectionItem->setTaxRatesCodes($taxRule->getTaxRatesCodes());
82  $collectionItem->setTaxRates($taxRule->getTaxRateIds());
83  return $collectionItem;
84  }
85 }
$searchCriteria
$taxRule
Definition: tax_rule.php:35
createTaxRuleCollectionItem(TaxRuleInterface $taxRule)
__construct(EntityFactory $entityFactory, FilterBuilder $filterBuilder, SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderBuilder $sortOrderBuilder, TaxRuleRepositoryInterface $ruleService)
loadData($printQuery=false, $logQuery=false)