Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Json\Helper\Data $jsonHelper, Config $taxConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $orderTaxCollectionFactory, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Catalog\Helper\Data $catalogHelper, OrderTaxManagementInterface $orderTaxManagement, PriceCurrencyInterface $priceCurrency, Json $serializer=null)
 
 getPostCodeSubStringLength ()
 
 getConfig ()
 
 priceIncludesTax ($store=null)
 
 applyTaxAfterDiscount ($store=null)
 
 getPriceDisplayType ($store=null)
 
 needPriceConversion ($store=null)
 
 displayFullSummary ($store=null)
 
 displayZeroTax ($store=null)
 
 displayCartPriceInclTax ($store=null)
 
 displayCartPriceExclTax ($store=null)
 
 displayCartBothPrices ($store=null)
 
 displaySalesPriceInclTax ($store=null)
 
 displaySalesPriceExclTax ($store=null)
 
 displaySalesBothPrices ($store=null)
 
 displaySalesSubtotalBoth ($store=null)
 
 displaySalesSubtotalInclTax ($store=null)
 
 displaySalesSubtotalExclTax ($store=null)
 
 getPriceFormat ($store=null)
 
 displayPriceIncludingTax ()
 
 displayPriceExcludingTax ()
 
 displayBothPrices ($store=null)
 
 shippingPriceIncludesTax ($store=null)
 
 getShippingPriceDisplayType ($store=null)
 
 displayShippingPriceIncludingTax ()
 
 displayShippingPriceExcludingTax ()
 
 displayShippingBothPrices ()
 
 getShippingTaxClass ($store)
 
 getShippingPrice ($price, $includingTax=null, $shippingAddress=null, $ctc=null, $store=null)
 
 discountTax ($store=null)
 
 getTaxBasedOn ($store=null)
 
 applyTaxOnCustomPrice ($store=null)
 
 applyTaxOnOriginalPrice ($store=null)
 
 getCalculationSequence ($store=null)
 
 getCalculationAlgorithm ($store=null)
 
 getCalculatedTaxes ($source)
 
 getDefaultCustomerTaxClass ()
 
 getDefaultProductTaxClass ()
 
 isCrossBorderTradeEnabled ($store=null)
 
 isCatalogPriceDisplayAffectedByTax ($store=null)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const CONFIG_DEFAULT_CUSTOMER_TAX_CLASS = 'tax/classes/default_customer_tax_class'
 
const CONFIG_DEFAULT_PRODUCT_TAX_CLASS = 'tax/classes/default_product_tax_class'
 

Protected Member Functions

 _getTaxRateSubtotals ($order)
 
 calculateTaxForOrder (EntityInterface $current)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_config
 
 $_postCodeSubStringLength = 10
 
 $jsonHelper
 
 $_storeManager
 
 $_localeFormat
 
 $_orderTaxCollectionFactory
 
 $_localeResolver
 
 $catalogHelper
 
 $orderTaxManagement
 
 $priceCurrency
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Tax helper

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api

Since
100.0.2

Definition at line 28 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Framework\Json\Helper\Data  $jsonHelper,
Config  $taxConfig,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Locale\FormatInterface  $localeFormat,
\Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory  $orderTaxCollectionFactory,
\Magento\Framework\Locale\ResolverInterface  $localeResolver,
\Magento\Catalog\Helper\Data  $catalogHelper,
OrderTaxManagementInterface  $orderTaxManagement,
PriceCurrencyInterface  $priceCurrency,
Json  $serializer = null 
)

Constructor

Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Framework\Json\Helper\Data$jsonHelper
Config$taxConfig
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Locale\FormatInterface$localeFormat
\Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory$orderTaxCollectionFactory
\Magento\Framework\Locale\ResolverInterface$localeResolver
\Magento\Catalog\Helper\Data$catalogHelper
OrderTaxManagementInterface$orderTaxManagement
PriceCurrencyInterface$priceCurrency
Json$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 117 of file Data.php.

129  {
130  parent::__construct($context);
131  $this->priceCurrency = $priceCurrency;
132  $this->_config = $taxConfig;
133  $this->jsonHelper = $jsonHelper;
134  $this->_storeManager = $storeManager;
135  $this->_localeFormat = $localeFormat;
136  $this->_orderTaxCollectionFactory = $orderTaxCollectionFactory;
137  $this->_localeResolver = $localeResolver;
138  $this->catalogHelper = $catalogHelper;
139  $this->orderTaxManagement = $orderTaxManagement;
140  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
141  }
$storeManager

Member Function Documentation

◆ _getTaxRateSubtotals()

_getTaxRateSubtotals (   $order)
protected

Returns the array of tax rates for the order

Parameters
\Magento\Sales\Model\Order$order
Returns
array

Definition at line 654 of file Data.php.

655  {
656  return $this->_orderTaxCollectionFactory->create()->loadByOrder($order)->toArray();
657  }
$order
Definition: order.php:55

◆ applyTaxAfterDiscount()

applyTaxAfterDiscount (   $store = null)

Check what taxes should be applied after discount

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 185 of file Data.php.

186  {
187  return $this->_config->applyTaxAfterDiscount($store);
188  }

◆ applyTaxOnCustomPrice()

applyTaxOnCustomPrice (   $store = null)

Check if tax can be applied to custom price

Parameters
null | string | bool | int | Store$store
Returns
bool

Definition at line 515 of file Data.php.

516  {
517  return (int) $this->scopeConfig->getValue(
520  $store
521  ) == 0;
522  }
const CONFIG_XML_PATH_APPLY_ON
Definition: Config.php:40

◆ applyTaxOnOriginalPrice()

applyTaxOnOriginalPrice (   $store = null)

Check if tax should be applied just to original price

Parameters
null | string | bool | int | Store$store
Returns
bool

Definition at line 530 of file Data.php.

531  {
532  return (int) $this->scopeConfig->getValue(
535  $store
536  ) == 1;
537  }
const CONFIG_XML_PATH_APPLY_ON
Definition: Config.php:40

◆ calculateTaxForOrder()

calculateTaxForOrder ( EntityInterface  $current)
protected
Parameters
EntityInterface$current
Returns
array

Definition at line 700 of file Data.php.

701  {
702  $taxClassAmount = [];
703 
704  $orderTaxDetails = $this->orderTaxManagement->getOrderTaxDetails($current->getId());
705  $appliedTaxes = $orderTaxDetails->getAppliedTaxes();
706  foreach ($appliedTaxes as $appliedTax) {
707  $taxCode = $appliedTax->getCode();
708  $taxClassAmount[$taxCode]['tax_amount'] = $appliedTax->getAmount();
709  $taxClassAmount[$taxCode]['base_tax_amount'] = $appliedTax->getBaseAmount();
710  $taxClassAmount[$taxCode]['title'] = $appliedTax->getTitle();
711  $taxClassAmount[$taxCode]['percent'] = $appliedTax->getPercent();
712  }
713 
714  return $taxClassAmount;
715  }

◆ discountTax()

discountTax (   $store = null)

Get configuration setting "Apply Discount On Prices Including Tax" value

Parameters
null | string | bool | int | Store$store
Returns
bool

Definition at line 489 of file Data.php.

490  {
491  return $this->_config->discountTax($store);
492  }

◆ displayBothPrices()

displayBothPrices (   $store = null)

Check if we have display in catalog prices including and excluding tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 381 of file Data.php.

382  {
384  }
getPriceDisplayType($store=null)
Definition: Data.php:199

◆ displayCartBothPrices()

displayCartBothPrices (   $store = null)

Check if need display cart prices excluding and including tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 266 of file Data.php.

267  {
268  return $this->_config->displayCartPricesBoth($store);
269  }

◆ displayCartPriceExclTax()

displayCartPriceExclTax (   $store = null)

Check if need display cart prices excluding price

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 255 of file Data.php.

256  {
257  return $this->_config->displayCartPricesExclTax($store);
258  }

◆ displayCartPriceInclTax()

displayCartPriceInclTax (   $store = null)

Check if need display cart prices included tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 244 of file Data.php.

245  {
246  return $this->_config->displayCartPricesInclTax($store);
247  }

◆ displayFullSummary()

displayFullSummary (   $store = null)

Check if need display full tax summary information in totals block

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 222 of file Data.php.

223  {
224  return $this->_config->displayCartFullSummary($store);
225  }

◆ displayPriceExcludingTax()

displayPriceExcludingTax ( )

Check if we have display in catalog prices excluding tax

Returns
bool

Definition at line 370 of file Data.php.

371  {
373  }
const DISPLAY_TYPE_EXCLUDING_TAX
Definition: Config.php:102
getPriceDisplayType($store=null)
Definition: Data.php:199

◆ displayPriceIncludingTax()

displayPriceIncludingTax ( )

Check if we have display in catalog prices including tax

Returns
bool

Definition at line 360 of file Data.php.

361  {
363  }
const DISPLAY_TYPE_INCLUDING_TAX
Definition: Config.php:104
getPriceDisplayType($store=null)
Definition: Data.php:199

◆ displaySalesBothPrices()

displaySalesBothPrices (   $store = null)

Check if need display order prices excluding and including tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 299 of file Data.php.

300  {
301  return $this->_config->displaySalesPricesBoth($store);
302  }

◆ displaySalesPriceExclTax()

displaySalesPriceExclTax (   $store = null)

Check if need display order prices excluding price

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 288 of file Data.php.

289  {
290  return $this->_config->displaySalesPricesExclTax($store);
291  }

◆ displaySalesPriceInclTax()

displaySalesPriceInclTax (   $store = null)

Check if need display order prices included tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 277 of file Data.php.

278  {
279  return $this->_config->displaySalesPricesInclTax($store);
280  }

◆ displaySalesSubtotalBoth()

displaySalesSubtotalBoth (   $store = null)

Check if we need display price include and exclude tax for order/invoice subtotal

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 310 of file Data.php.

311  {
312  return $this->_config->displaySalesSubtotalBoth($store);
313  }

◆ displaySalesSubtotalExclTax()

displaySalesSubtotalExclTax (   $store = null)

Check if we need display price exclude tax for order/invoice subtotal

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 332 of file Data.php.

333  {
334  return $this->_config->displaySalesSubtotalExclTax($store);
335  }

◆ displaySalesSubtotalInclTax()

displaySalesSubtotalInclTax (   $store = null)

Check if we need display price include tax for order/invoice subtotal

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 321 of file Data.php.

322  {
323  return $this->_config->displaySalesSubtotalInclTax($store);
324  }

◆ displayShippingBothPrices()

displayShippingBothPrices ( )

Returns whether the shipping price should display both with and without taxes

Returns
bool

Definition at line 433 of file Data.php.

434  {
436  }
getShippingPriceDisplayType($store=null)
Definition: Data.php:403

◆ displayShippingPriceExcludingTax()

displayShippingPriceExcludingTax ( )

Returns whether the shipping price should display without taxes

Returns
bool

Definition at line 423 of file Data.php.

424  {
426  }
const DISPLAY_TYPE_EXCLUDING_TAX
Definition: Config.php:102
getShippingPriceDisplayType($store=null)
Definition: Data.php:403

◆ displayShippingPriceIncludingTax()

displayShippingPriceIncludingTax ( )

Returns whether the shipping price should display with taxes included

Returns
bool

Definition at line 413 of file Data.php.

414  {
416  }
const DISPLAY_TYPE_INCLUDING_TAX
Definition: Config.php:104
getShippingPriceDisplayType($store=null)
Definition: Data.php:403

◆ displayZeroTax()

displayZeroTax (   $store = null)

Check if need display zero tax in subtotal

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 233 of file Data.php.

234  {
235  return $this->_config->displayCartZeroTax($store);
236  }

◆ getCalculatedTaxes()

getCalculatedTaxes (   $source)

Get calculated taxes for each tax class

This method returns array with format: array( $index => array( 'tax_amount' => $taxAmount, 'base_tax_amount' => $baseTaxAmount, 'title' => $title, 'percent' => $percent ) )

Parameters

Definition at line 581 of file Data.php.

582  {
583  $taxClassAmount = [];
584  if (empty($source)) {
585  return $taxClassAmount;
586  }
587  $current = $source;
588  if ($source instanceof Invoice || $source instanceof Creditmemo) {
589  $source = $current->getOrder();
590  }
591  if ($current == $source) {
592  $taxClassAmount = $this->calculateTaxForOrder($current);
593  } else {
594  $taxClassAmount = $this->calculateTaxForItems($source, $current);
595  }
596 
597  foreach ($taxClassAmount as $key => $tax) {
598  $taxClassAmount[$key]['tax_amount'] = $this->priceCurrency->round($tax['tax_amount']);
599  $taxClassAmount[$key]['base_tax_amount'] = $this->priceCurrency->round($tax['base_tax_amount']);
600  }
601 
602  return array_values($taxClassAmount);
603  }
$source
Definition: source.php:23
calculateTaxForOrder(EntityInterface $current)
Definition: Data.php:700

◆ getCalculationAlgorithm()

getCalculationAlgorithm (   $store = null)

Get tax calculation algorithm code

Parameters
null | string | bool | int | Store$store
Returns
string

Definition at line 559 of file Data.php.

560  {
561  return $this->_config->getAlgorithm($store);
562  }

◆ getCalculationSequence()

getCalculationSequence (   $store = null)

Get taxes/discounts calculation sequence

This sequence depends on "Catalog price include tax", "Apply Tax After Discount" and "Apply Discount On Prices Including Tax" configuration options.

Parameters
null | int | string | Store$store
Returns
string

Definition at line 548 of file Data.php.

549  {
550  return $this->_config->getCalculationSequence($store);
551  }

◆ getConfig()

getConfig ( )

Get tax configuration object

Returns
Config

Definition at line 163 of file Data.php.

164  {
165  return $this->_config;
166  }

◆ getDefaultCustomerTaxClass()

getDefaultCustomerTaxClass ( )

Retrieve default customer tax class from config

Returns
string|null

Definition at line 664 of file Data.php.

665  {
666  return $this->scopeConfig->getValue(
667  self::CONFIG_DEFAULT_CUSTOMER_TAX_CLASS,
669  );
670  }

◆ getDefaultProductTaxClass()

getDefaultProductTaxClass ( )

Retrieve default product tax class from config

Returns
string|null

Definition at line 677 of file Data.php.

678  {
679  return $this->scopeConfig->getValue(
680  self::CONFIG_DEFAULT_PRODUCT_TAX_CLASS,
682  );
683  }

◆ getPostCodeSubStringLength()

getPostCodeSubStringLength ( )

Return max postcode length to create search templates

Returns
int $len

Definition at line 148 of file Data.php.

149  {
150  $len = (int) $this->_postCodeSubStringLength;
151  if ($len <= 0) {
152  $len = 10;
153  }
154 
155  return $len;
156  }

◆ getPriceDisplayType()

getPriceDisplayType (   $store = null)

Get product price display type 1 - Excluding tax 2 - Including tax 3 - Both

Parameters
null | int | string | Store$store
Returns
int

Definition at line 199 of file Data.php.

200  {
201  return $this->_config->getPriceDisplayType($store);
202  }

◆ getPriceFormat()

getPriceFormat (   $store = null)

Get prices javascript format json

Parameters
null | int | string | Store$store
Returns
string

Definition at line 343 of file Data.php.

344  {
345  $this->_localeResolver->emulate($store);
346  $priceFormat = $this->_localeFormat->getPriceFormat();
347  $this->_localeResolver->revert();
348  if ($store) {
349  $priceFormat['pattern'] = $this->_storeManager->getStore($store)->getCurrentCurrency()->getOutputFormat();
350  }
351 
352  return $this->jsonHelper->jsonEncode($priceFormat);
353  }

◆ getShippingPrice()

getShippingPrice (   $price,
  $includingTax = null,
  $shippingAddress = null,
  $ctc = null,
  $store = null 
)

Get shipping price

Parameters
float$price
bool | null$includingTax
Address | null$shippingAddress
int | null$ctc
null | string | bool | int | Store$store
Returns
float

Definition at line 459 of file Data.php.

460  {
461  $pseudoProduct = new \Magento\Framework\DataObject();
462  $pseudoProduct->setTaxClassId($this->getShippingTaxClass($store));
463 
464  $billingAddress = false;
465  if ($shippingAddress && $shippingAddress->getQuote() && $shippingAddress->getQuote()->getBillingAddress()) {
466  $billingAddress = $shippingAddress->getQuote()->getBillingAddress();
467  }
468 
469  $price = $this->catalogHelper->getTaxPrice(
470  $pseudoProduct,
471  $price,
472  $includingTax,
475  $ctc,
476  $store,
478  );
479 
480  return $price;
481  }
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$price
getShippingTaxClass($store)
Definition: Data.php:444
shippingPriceIncludesTax($store=null)
Definition: Data.php:392

◆ getShippingPriceDisplayType()

getShippingPriceDisplayType (   $store = null)

Get shipping price display type

Parameters
null | string | bool | int | Store$store
Returns
int

Definition at line 403 of file Data.php.

404  {
405  return $this->_config->getShippingPriceDisplayType($store);
406  }

◆ getShippingTaxClass()

getShippingTaxClass (   $store)

Get tax class id specified for shipping tax estimation

Parameters
null | string | bool | int | Store$store
Returns
int

Definition at line 444 of file Data.php.

445  {
446  return $this->_config->getShippingTaxClass($store);
447  }

◆ getTaxBasedOn()

getTaxBasedOn (   $store = null)

Get value of "Apply Tax On" custom/original price configuration settings

Parameters
null | string | bool | int | Store$store
Returns
string|null

Definition at line 500 of file Data.php.

501  {
502  return $this->scopeConfig->getValue(
505  $store
506  );
507  }
const CONFIG_XML_PATH_BASED_ON
Definition: Config.php:38

◆ isCatalogPriceDisplayAffectedByTax()

isCatalogPriceDisplayAffectedByTax (   $store = null)

Check whether display price is affected by different tax rates

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 786 of file Data.php.

787  {
788  if ($this->displayBothPrices($store)) {
789  return true;
790  }
791 
792  $priceInclTax = $this->priceIncludesTax($store);
793  if ($priceInclTax) {
794  return ($this->isCrossBorderTradeEnabled($store) xor $this->displayPriceIncludingTax());
795  } else {
796  return $this->displayPriceIncludingTax();
797  }
798  }
displayBothPrices($store=null)
Definition: Data.php:381
priceIncludesTax($store=null)
Definition: Data.php:174
isCrossBorderTradeEnabled($store=null)
Definition: Data.php:691

◆ isCrossBorderTradeEnabled()

isCrossBorderTradeEnabled (   $store = null)

Return whether cross border trade is enabled or not

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 691 of file Data.php.

692  {
693  return (bool) $this->_config->crossBorderTradeEnabled($store);
694  }

◆ needPriceConversion()

needPriceConversion (   $store = null)

Check if necessary do product price conversion If it necessary will be returned conversion type (minus or plus)

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 211 of file Data.php.

212  {
213  return $this->_config->needPriceConversion($store);
214  }

◆ priceIncludesTax()

priceIncludesTax (   $store = null)

Check if product prices inputed include tax

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 174 of file Data.php.

175  {
176  return $this->_config->priceIncludesTax($store) || $this->_config->getNeedUseShippingExcludeTax();
177  }

◆ shippingPriceIncludesTax()

shippingPriceIncludesTax (   $store = null)

Check if shipping prices include tax

Parameters
null | string | bool | int | Store$store
Returns
bool

Definition at line 392 of file Data.php.

393  {
394  return $this->_config->shippingPriceIncludesTax($store);
395  }

Field Documentation

◆ $_config

$_config
protected

Definition at line 45 of file Data.php.

◆ $_localeFormat

$_localeFormat
protected

Definition at line 69 of file Data.php.

◆ $_localeResolver

$_localeResolver
protected

Definition at line 79 of file Data.php.

◆ $_orderTaxCollectionFactory

$_orderTaxCollectionFactory
protected

Definition at line 74 of file Data.php.

◆ $_postCodeSubStringLength

$_postCodeSubStringLength = 10
protected

Definition at line 52 of file Data.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 64 of file Data.php.

◆ $catalogHelper

$catalogHelper
protected

Definition at line 84 of file Data.php.

◆ $jsonHelper

$jsonHelper
protected

Definition at line 59 of file Data.php.

◆ $orderTaxManagement

$orderTaxManagement
protected

Definition at line 89 of file Data.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 94 of file Data.php.

◆ CONFIG_DEFAULT_CUSTOMER_TAX_CLASS

const CONFIG_DEFAULT_CUSTOMER_TAX_CLASS = 'tax/classes/default_customer_tax_class'

Default tax class for customers

Definition at line 33 of file Data.php.

◆ CONFIG_DEFAULT_PRODUCT_TAX_CLASS

const CONFIG_DEFAULT_PRODUCT_TAX_CLASS = 'tax/classes/default_product_tax_class'

Default tax class for products

Definition at line 38 of file Data.php.


The documentation for this class was generated from the following file: