Example #1
0
 /**
  * Helper function that sets up some default rules
  */
 private function setUpDefaultRules()
 {
     $this->taxClasses = $this->taxRuleFixtureFactory->createTaxClasses([['name' => 'DefaultCustomerClass', 'type' => ClassModel::TAX_CLASS_TYPE_CUSTOMER], ['name' => 'DefaultProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT], ['name' => 'HigherProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT]]);
     $this->taxRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 7.5, 'country' => 'US', 'region' => 42], ['percentage' => 7.5, 'country' => 'US', 'region' => 12]]);
     $higherRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 22, 'country' => 'US', 'region' => 42], ['percentage' => 10, 'country' => 'US', 'region' => 12]]);
     $this->taxRules = $this->taxRuleFixtureFactory->createTaxRules([['code' => 'Default Rule', 'customer_tax_class_ids' => [$this->taxClasses['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClasses['DefaultProductClass']], 'tax_rate_ids' => array_values($this->taxRates), 'sort_order' => 0, 'priority' => 0], ['code' => 'Higher Rate Rule', 'customer_tax_class_ids' => [$this->taxClasses['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClasses['HigherProductClass']], 'tax_rate_ids' => array_values($higherRates), 'sort_order' => 0, 'priority' => 0]]);
     // For cleanup
     $this->taxRates = array_merge($this->taxRates, $higherRates);
 }
Example #2
0
 /**
  *
  * @param \Magento\Framework\Service\V1\Data\Filter[] $filters
  * @param \Magento\Framework\Service\V1\Data\Filter[] $filterGroup
  * @param $expectedRateCodes
  *
  * @magentoDbIsolation enabled
  * @dataProvider searchTaxRatesDataProvider
  */
 public function testSearchTaxRates($filters, $filterGroup, $expectedRateCodes)
 {
     $taxRates = $this->taxRateFixtureFactory->createTaxRates([['percentage' => 7.5, 'country' => 'US', 'region' => '42'], ['percentage' => 7.5, 'country' => 'US', 'region' => '12'], ['percentage' => 22.0, 'country' => 'US', 'region' => '42'], ['percentage' => 10.0, 'country' => 'US', 'region' => '12']]);
     /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchBuilder */
     $searchBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Service\\V1\\Data\\SearchCriteriaBuilder');
     foreach ($filters as $filter) {
         $searchBuilder->addFilter([$filter]);
     }
     if (!is_null($filterGroup)) {
         $searchBuilder->addFilter($filterGroup);
     }
     $searchCriteria = $searchBuilder->create();
     $searchResults = $this->taxRateService->searchTaxRates($searchCriteria);
     $items = [];
     foreach ($expectedRateCodes as $rateCode) {
         $rateId = $taxRates[$rateCode];
         $items[] = $this->taxRateService->getTaxRate($rateId);
     }
     $resultsBuilder = Bootstrap::getObjectManager()->create('Magento\\Tax\\Service\\V1\\Data\\TaxRateSearchResultsBuilder');
     $expectedResult = $resultsBuilder->setItems($items)->setTotalCount(count($items))->setSearchCriteria($searchCriteria)->create();
     $this->assertEquals($expectedResult, $searchResults);
 }