コード例 #1
0
ファイル: Customer.php プロジェクト: shabbirvividads/magento2
 /**
  * Retrieve all customer tax classes as an options array.
  *
  * @return array
  * @throws StateException
  */
 public function getAllOptions()
 {
     if (empty($this->_options)) {
         $options = [];
         $filter = $this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_CUSTOMER)->create();
         $searchCriteria = $this->searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->taxClassRepository->getList($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()];
         }
         $this->_options = $options;
     }
     return $this->_options;
 }
コード例 #2
0
ファイル: Product.php プロジェクト: shabbirvividads/magento2
 /**
  * Retrieve all product tax class options.
  *
  * @param bool $withEmpty
  * @return array
  */
 public function getAllOptions($withEmpty = true)
 {
     if (!$this->_options) {
         $filter = $this->_filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_PRODUCT)->create();
         $searchCriteria = $this->_searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->_taxClassRepository->getList($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $this->_options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()];
         }
     }
     if ($withEmpty) {
         if (!$this->_options) {
             return [['value' => '0', 'label' => __('None')]];
         } else {
             return array_merge([['value' => '0', 'label' => __('None')]], $this->_options);
         }
     }
     return $this->_options;
 }
コード例 #3
0
ファイル: Calculation.php プロジェクト: nja78/magento2
 /**
  * @param array $billingAddress
  * @param array $shippingAddress
  * @param int $customerTaxClassId
  * @return array
  */
 public function getTaxRates($billingAddress, $shippingAddress, $customerTaxClassId)
 {
     $billingAddressObj = null;
     $shippingAddressObj = null;
     if (!empty($billingAddress)) {
         $billingAddressObj = new \Magento\Framework\Object($billingAddress);
     }
     if (!empty($shippingAddress)) {
         $shippingAddressObj = new \Magento\Framework\Object($shippingAddress);
     }
     $rateRequest = $this->getRateRequest($shippingAddressObj, $billingAddressObj, $customerTaxClassId);
     $searchCriteria = $this->searchCriteriaBuilder->addFilters([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_PRODUCT)->create()])->create();
     $ids = $this->taxClassRepository->getList($searchCriteria)->getItems();
     $productRates = [];
     $idKeys = array_keys($ids);
     foreach ($idKeys as $idKey) {
         $rateRequest->setProductClassId($idKey);
         $rate = $this->getRate($rateRequest);
         $productRates[$idKey] = $rate;
     }
     return $productRates;
 }