当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::getCustomerTaxClassId方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\Session::getCustomerTaxClassId方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getCustomerTaxClassId方法的具体用法?PHP Session::getCustomerTaxClassId怎么用?PHP Session::getCustomerTaxClassId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\Session的用法示例。


在下文中一共展示了Session::getCustomerTaxClassId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeGenerateXml

 /**
  * Before generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @return array
  */
 public function beforeGenerateXml(\Magento\Framework\View\LayoutInterface $subject)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->defaultTaxBillingAddress = $this->customerSession->getDefaultTaxBillingAddress();
         $this->defaultTaxShippingAddress = $this->customerSession->getDefaultTaxShippingAddress();
         $this->customerTaxClassId = $this->customerSession->getCustomerTaxClassId();
     }
     return [];
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:DepersonalizePlugin.php

示例2: aroundDispatch

 /**
  * @param \Magento\Framework\App\ActionInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->customerSession->isLoggedIn() || !$this->moduleManager->isEnabled('Magento_PageCache') || !$this->cacheConfig->isEnabled() || !$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         return $proceed($request);
     }
     $defaultBillingAddress = $this->customerSession->getDefaultTaxBillingAddress();
     $defaultShippingAddress = $this->customerSession->getDefaultTaxShippingAddress();
     $customerTaxClassId = $this->customerSession->getCustomerTaxClassId();
     if (!empty($defaultBillingAddress) || !empty($defaultShippingAddress)) {
         $taxRates = $this->taxCalculation->getTaxRates($defaultBillingAddress, $defaultShippingAddress, $customerTaxClassId);
         $this->httpContext->setValue('tax_rates', $taxRates, 0);
     }
     return $proceed($request);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:ContextPlugin.php

示例3: getProductWeeeAttributes

 /**
  * @param Product $product
  * @param null|false|\Magento\Quote\Model\Quote\Address $shipping
  * @param null|false|\Magento\Quote\Model\Quote\Address $billing
  * @param Website $website
  * @param bool $calculateTax
  * @param bool $round
  * @return \Magento\Framework\DataObject[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $round = true)
 {
     $result = [];
     $websiteId = $this->_storeManager->getWebsite($website)->getId();
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
     $allWeee = $this->getWeeeTaxAttributeCodes($store);
     if (!$allWeee) {
         return $result;
     }
     /** @var \Magento\Tax\Model\Calculation $calculator */
     $calculator = $this->_calculationFactory->create();
     $customerId = $this->_customerSession->getCustomerId();
     if ($shipping && $shipping->getCountryId()) {
         $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId();
     } else {
         // if customer logged use it default shipping and billing address
         if ($customerId) {
             $shipping = $this->accountManagement->getDefaultShippingAddress($customerId);
             $billing = $this->accountManagement->getDefaultBillingAddress($customerId);
             $customerTaxClass = null;
         } else {
             $shippingAddressArray = $this->_customerSession->getDefaultTaxShippingAddress();
             $billingAddressArray = $this->_customerSession->getDefaultTaxBillingAddress();
             if (!empty($billingAddressArray)) {
                 $billing = new \Magento\Framework\DataObject($billingAddressArray);
             }
             if (!empty($shippingAddressArray)) {
                 $shipping = new \Magento\Framework\DataObject($shippingAddressArray);
             }
             $customerTaxClass = $this->_customerSession->getCustomerTaxClassId();
         }
     }
     $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store, $customerId);
     $defaultRateRequest = $calculator->getDefaultRateRequest($store);
     $productAttributes = $this->getResource()->fetchWeeeTaxCalculationsByEntity($rateRequest->getCountryId(), $rateRequest->getRegionId(), $websiteId, $store->getId(), $product->getId());
     foreach ($productAttributes as $attribute) {
         $value = $attribute['weee_value'];
         if ($value) {
             $taxAmount = $amount = 0;
             $amount = $value;
             $amountExclTax = $value;
             if ($calculateTax && $this->weeeConfig->isTaxable($store)) {
                 /** @var \Magento\Tax\Model\Calculation $calculator */
                 $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId()));
                 $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId()));
                 if ($this->_taxData->priceIncludesTax($store)) {
                     $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent);
                     if ($round) {
                         $amountInclTax = $this->priceCurrency->round($amountInclTax);
                     }
                     $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100;
                     if ($round) {
                         $taxAmount = $this->priceCurrency->round($taxAmount);
                     }
                     $amountExclTax = $amountInclTax - $taxAmount;
                 } else {
                     $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest);
                     if (count($appliedRates) > 1) {
                         $taxAmount = 0;
                         foreach ($appliedRates as $appliedRate) {
                             $taxRate = $appliedRate['percent'];
                             if ($round) {
                                 $taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
                             } else {
                                 $taxAmount += $value * $taxRate / 100;
                             }
                         }
                     } else {
                         if ($round) {
                             $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                         } else {
                             $taxAmount = $value * $currentPercent / 100;
                         }
                     }
                 }
             }
             $one = new \Magento\Framework\DataObject();
             $one->setName($attribute['label_value'] ? __($attribute['label_value']) : __($attribute['frontend_label']))->setAmount($amount)->setTaxAmount($taxAmount)->setAmountExclTax($amountExclTax)->setCode($attribute['attribute_code']);
             $result[] = $one;
         }
     }
     return $result;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:96,代码来源:Tax.php

示例4: getProductWeeeAttributes

 /**
  * @param Product $product
  * @param null|false|\Magento\Quote\Model\Quote\Address $shipping
  * @param null|false|\Magento\Quote\Model\Quote\Address $billing
  * @param Website $website
  * @param bool $calculateTax
  * @return \Magento\Framework\Object[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null)
 {
     $result = [];
     $websiteId = $this->_storeManager->getWebsite($website)->getId();
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
     $allWeee = $this->getWeeeTaxAttributeCodes($store);
     if (!$allWeee) {
         return $result;
     }
     /** @var \Magento\Tax\Model\Calculation $calculator */
     $calculator = $this->_calculationFactory->create();
     if ($shipping && $shipping->getCountryId()) {
         $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId();
     } else {
         // if customer logged use it default shipping and billing address
         if ($customerId = $this->_customerSession->getCustomerId()) {
             $shipping = $this->accountManagement->getDefaultShippingAddress($customerId);
             $billing = $this->accountManagement->getDefaultBillingAddress($customerId);
             $customerTaxClass = null;
         } else {
             $shippingAddressArray = $this->_customerSession->getDefaultTaxShippingAddress();
             $billingAddressArray = $this->_customerSession->getDefaultTaxBillingAddress();
             if (!empty($billingAddressArray)) {
                 $billing = new \Magento\Framework\Object($billingAddressArray);
             }
             if (!empty($shippingAddressArray)) {
                 $shipping = new \Magento\Framework\Object($shippingAddressArray);
             }
             $customerTaxClass = $this->_customerSession->getCustomerTaxClassId();
         }
     }
     $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store);
     $defaultRateRequest = $calculator->getDefaultRateRequest($store);
     $productAttributes = $product->getTypeInstance()->getSetAttributes($product);
     foreach ($productAttributes as $code => $attribute) {
         if (in_array($code, $allWeee)) {
             $attributeSelect = $this->getResource()->getReadConnection()->select();
             $attributeSelect->from($this->getResource()->getTable('weee_tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', [$websiteId, 0])->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', [$rateRequest->getRegionId(), 0])->where('entity_id = ?', (int) $product->getId())->limit(1);
             $order = ['state ' . \Magento\Framework\DB\Select::SQL_DESC, 'website_id ' . \Magento\Framework\DB\Select::SQL_DESC];
             $attributeSelect->order($order);
             $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect);
             if ($value) {
                 $taxAmount = $amount = 0;
                 $amount = $value;
                 if ($calculateTax && $this->weeeConfig->isTaxable($store)) {
                     /** @var \Magento\Tax\Model\Calculation $calculator */
                     $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId()));
                     $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId()));
                     if ($this->_taxData->priceIncludesTax($store)) {
                         $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent);
                         //round the "golden price"
                         $amountInclTax = $this->priceCurrency->round($amountInclTax);
                         $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100;
                         $taxAmount = $this->priceCurrency->round($taxAmount);
                     } else {
                         $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest);
                         if (count($appliedRates) > 1) {
                             $taxAmount = 0;
                             foreach ($appliedRates as $appliedRate) {
                                 $taxRate = $appliedRate['percent'];
                                 $taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
                             }
                         } else {
                             $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                         }
                         $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                     }
                 }
                 $one = new \Magento\Framework\Object();
                 $one->setName(__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode());
                 $result[] = $one;
             }
         }
     }
     return $result;
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:87,代码来源:Tax.php


注:本文中的Magento\Customer\Model\Session::getCustomerTaxClassId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。