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\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Stdlib\StringUtils $string, Category $catalogCategory, Product $catalogProduct, \Magento\Framework\Registry $coreRegistry, \Magento\Catalog\Model\Template\Filter\Factory $templateFilterFactory, $templateFilterModel, \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyFactory, \Magento\Tax\Model\Config $taxConfig, \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsFactory, \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemFactory, \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService, CustomerSession $customerSession, PriceCurrencyInterface $priceCurrency, ProductRepositoryInterface $productRepository, CategoryRepositoryInterface $categoryRepository, \Magento\Customer\Api\GroupRepositoryInterface $customerGroupRepository, \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory, \Magento\Customer\Api\Data\RegionInterfaceFactory $regionFactory)
 
 setStoreId ($store)
 
 getBreadcrumbPath ()
 
 getCategory ()
 
 getProduct ()
 
 getLastViewedUrl ()
 
 splitSku ($sku, $length=30)
 
 getAttributeHiddenFields ()
 
 getPriceScope ()
 
 isPriceGlobal ()
 
 isUsingStaticUrlsAllowed ()
 
 isUrlDirectivesParsingAllowed ()
 
 getPageTemplateProcessor ()
 
 shouldDisplayProductCountOnLayer ($storeId=null)
 
 getTaxPrice ( $product, $price, $includingTax=null, $shippingAddress=null, $billingAddress=null, $ctc=null, $store=null, $priceIncludesTax=null, $roundPrice=true)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const PRICE_SCOPE_GLOBAL = 0
 
const PRICE_SCOPE_WEBSITE = 1
 
const XML_PATH_PRICE_SCOPE = 'catalog/price/scope'
 
const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog'
 
const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives'
 
const XML_PATH_DISPLAY_PRODUCT_COUNT = 'catalog/layered_navigation/display_product_count'
 
const CONTEXT_CATALOG_SORT_DIRECTION = 'catalog_sort_direction'
 
const CONTEXT_CATALOG_SORT_ORDER = 'catalog_sort_order'
 
const CONTEXT_CATALOG_DISPLAY_MODE = 'catalog_mode'
 
const CONTEXT_CATALOG_LIMIT = 'catalog_limit'
 

Protected Member Functions

 _isCategoryLink ($categoryId)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_categoryPath
 
 $_storeId
 
 $_coreRegistry
 
 $_catalogProduct
 
 $_catalogCategory
 
 $string
 
 $_templateFilterModel
 
 $_catalogSession
 
 $_storeManager
 
 $_templateFilterFactory
 
 $_taxClassKeyFactory
 
 $_taxConfig
 
 $_quoteDetailsFactory
 
 $_quoteDetailsItemFactory
 
 $_customerSession
 
 $_taxCalculationService
 
 $priceCurrency
 
 $productRepository
 
 $categoryRepository
 
 $customerGroupRepository
 
 $addressFactory
 
 $regionFactory
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Catalog data helper

@api

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

Since
100.0.2

Definition at line 25 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Catalog\Model\Session  $catalogSession,
\Magento\Framework\Stdlib\StringUtils  $string,
Category  $catalogCategory,
Product  $catalogProduct,
\Magento\Framework\Registry  $coreRegistry,
\Magento\Catalog\Model\Template\Filter\Factory  $templateFilterFactory,
  $templateFilterModel,
\Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory  $taxClassKeyFactory,
\Magento\Tax\Model\Config  $taxConfig,
\Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory  $quoteDetailsFactory,
\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory  $quoteDetailsItemFactory,
\Magento\Tax\Api\TaxCalculationInterface  $taxCalculationService,
CustomerSession  $customerSession,
PriceCurrencyInterface  $priceCurrency,
ProductRepositoryInterface  $productRepository,
CategoryRepositoryInterface  $categoryRepository,
\Magento\Customer\Api\GroupRepositoryInterface  $customerGroupRepository,
\Magento\Customer\Api\Data\AddressInterfaceFactory  $addressFactory,
\Magento\Customer\Api\Data\RegionInterfaceFactory  $regionFactory 
)
Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Catalog\Model\Session$catalogSession
\Magento\Framework\Stdlib\StringUtils$string
Category$catalogCategory
Product$catalogProduct
\Magento\Framework\Registry$coreRegistry
\Magento\Catalog\Model\Template\Filter\Factory$templateFilterFactory
string$templateFilterModel
\Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory$taxClassKeyFactory
Config$taxConfig
\Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory$quoteDetailsFactory
\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory$quoteDetailsItemFactory
\Magento\Tax\Api\TaxCalculationInterface$taxCalculationService
CustomerSession$customerSession
PriceCurrencyInterface$priceCurrency
ProductRepositoryInterface$productRepository
CategoryRepositoryInterface$categoryRepository
\Magento\Customer\Api\GroupRepositoryInterface$customerGroupRepository
\Magento\Customer\Api\Data\AddressInterfaceFactory$addressFactory
\Magento\Customer\Api\Data\RegionInterfaceFactory$regionFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 216 of file Data.php.

238  {
239  $this->_storeManager = $storeManager;
240  $this->_catalogSession = $catalogSession;
241  $this->_templateFilterFactory = $templateFilterFactory;
242  $this->string = $string;
243  $this->_catalogCategory = $catalogCategory;
244  $this->_catalogProduct = $catalogProduct;
245  $this->_coreRegistry = $coreRegistry;
246  $this->_templateFilterModel = $templateFilterModel;
247  $this->_taxClassKeyFactory = $taxClassKeyFactory;
248  $this->_taxConfig = $taxConfig;
249  $this->_quoteDetailsFactory = $quoteDetailsFactory;
250  $this->_quoteDetailsItemFactory = $quoteDetailsItemFactory;
251  $this->_taxCalculationService = $taxCalculationService;
252  $this->_customerSession = $customerSession;
253  $this->priceCurrency = $priceCurrency;
254  $this->productRepository = $productRepository;
255  $this->categoryRepository = $categoryRepository;
256  $this->customerGroupRepository = $customerGroupRepository;
257  $this->addressFactory = $addressFactory;
258  $this->regionFactory = $regionFactory;
259  parent::__construct($context);
260  }
$storeManager

Member Function Documentation

◆ _isCategoryLink()

_isCategoryLink (   $categoryId)
protected

Check is category link

Parameters
int$categoryId
Returns
bool

Definition at line 317 of file Data.php.

318  {
319  if ($this->getProduct()) {
320  return true;
321  }
322  if ($categoryId != $this->getCategory()->getId()) {
323  return true;
324  }
325  return false;
326  }

◆ getAttributeHiddenFields()

getAttributeHiddenFields ( )

Retrieve attribute hidden fields

Returns
array

Definition at line 401 of file Data.php.

402  {
403  if ($this->_coreRegistry->registry('attribute_type_hidden_fields')) {
404  return $this->_coreRegistry->registry('attribute_type_hidden_fields');
405  } else {
406  return [];
407  }
408  }

◆ getBreadcrumbPath()

getBreadcrumbPath ( )

Return current category path or get it from current category and creating array of categories|product paths for breadcrumbs

Returns
array

Definition at line 280 of file Data.php.

281  {
282  if (!$this->_categoryPath) {
283  $path = [];
284  $category = $this->getCategory();
285  if ($category) {
286  $pathInStore = $category->getPathInStore();
287  $pathIds = array_reverse(explode(',', $pathInStore));
288 
289  $categories = $category->getParentCategories();
290 
291  // add category path breadcrumb
292  foreach ($pathIds as $categoryId) {
293  if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
294  $path['category' . $categoryId] = [
295  'label' => $categories[$categoryId]->getName(),
296  'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
297  ];
298  }
299  }
300  }
301 
302  if ($this->getProduct()) {
303  $path['product'] = ['label' => $this->getProduct()->getName()];
304  }
305 
306  $this->_categoryPath = $path;
307  }
308  return $this->_categoryPath;
309  }
_isCategoryLink($categoryId)
Definition: Data.php:317
$categories

◆ getCategory()

getCategory ( )

Return current category object

Returns
\Magento\Catalog\Model\Category|null

Definition at line 333 of file Data.php.

334  {
335  return $this->_coreRegistry->registry('current_category');
336  }

◆ getLastViewedUrl()

getLastViewedUrl ( )

Retrieve Visitor/Customer Last Viewed URL

Returns
string

Definition at line 353 of file Data.php.

354  {
355  $productId = $this->_catalogSession->getLastViewedProductId();
356  if ($productId) {
357  try {
358  $product = $this->productRepository->getById($productId);
359  } catch (NoSuchEntityException $e) {
360  return '';
361  }
362  /* @var $product \Magento\Catalog\Model\Product */
363  if ($this->_catalogProduct->canShow($product, 'catalog')) {
364  return $product->getProductUrl();
365  }
366  }
367  $categoryId = $this->_catalogSession->getLastViewedCategoryId();
368  if ($categoryId) {
369  try {
370  $category = $this->categoryRepository->get($categoryId);
371  } catch (NoSuchEntityException $e) {
372  return '';
373  }
374  /* @var $category \Magento\Catalog\Model\Category */
375  if (!$this->_catalogCategory->canShow($category)) {
376  return '';
377  }
378  return $category->getCategoryUrl();
379  }
380  return '';
381  }

◆ getPageTemplateProcessor()

getPageTemplateProcessor ( )

Retrieve template processor for catalog content

Returns
\Magento\Framework\Filter\Template
Exceptions

Definition at line 468 of file Data.php.

469  {
470  return $this->_templateFilterFactory->create($this->_templateFilterModel);
471  }

◆ getPriceScope()

getPriceScope ( )

Retrieve Catalog Price Scope

Returns
int

Definition at line 415 of file Data.php.

416  {
417  return $this->scopeConfig->getValue(
418  self::XML_PATH_PRICE_SCOPE,
420  );
421  }

◆ getProduct()

getProduct ( )

Retrieve current Product object

Returns
\Magento\Catalog\Model\Product|null

Definition at line 343 of file Data.php.

344  {
345  return $this->_coreRegistry->registry('current_product');
346  }

◆ getTaxPrice()

getTaxPrice (   $product,
  $price,
  $includingTax = null,
  $shippingAddress = null,
  $billingAddress = null,
  $ctc = null,
  $store = null,
  $priceIncludesTax = null,
  $roundPrice = true 
)

Get product price with all tax settings processing

Parameters
\Magento\Catalog\Model\Product$product
float$priceinputted product price
bool$includingTaxreturn price include tax flag
null | \Magento\Customer\Model\Address\AbstractAddress$shippingAddress
null | \Magento\Customer\Model\Address\AbstractAddress$billingAddress
null | int$ctccustomer tax class
null | string | bool | int | \Magento\Store\Model\Store$store
bool$priceIncludesTaxflag what price parameter contain tax
bool$roundPrice
Returns
float @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 524 of file Data.php.

534  {
535  if (!$price) {
536  return $price;
537  }
538 
539  $store = $this->_storeManager->getStore($store);
540  if ($this->_taxConfig->needPriceConversion($store)) {
541  if ($priceIncludesTax === null) {
542  $priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
543  }
544 
546  if ($shippingAddress === null) {
548  $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxShippingAddress());
549  } elseif ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
551  }
552 
554  if ($billingAddress === null) {
556  $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxBillingAddress());
557  } elseif ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
558  $billingAddressDataObject = $billingAddress->getDataModel();
559  }
560 
561  $taxClassKey = $this->_taxClassKeyFactory->create();
562  $taxClassKey->setType(TaxClassKeyInterface::TYPE_ID)
563  ->setValue($product->getTaxClassId());
564 
565  if ($ctc === null && $this->_customerSession->getCustomerGroupId() != null) {
566  $ctc = $this->customerGroupRepository->getById($this->_customerSession->getCustomerGroupId())
567  ->getTaxClassId();
568  }
569 
570  $customerTaxClassKey = $this->_taxClassKeyFactory->create();
571  $customerTaxClassKey->setType(TaxClassKeyInterface::TYPE_ID)
572  ->setValue($ctc);
573 
574  $item = $this->_quoteDetailsItemFactory->create();
575  $item->setQuantity(1)
576  ->setCode($product->getSku())
577  ->setShortDescription($product->getShortDescription())
578  ->setTaxClassKey($taxClassKey)
579  ->setIsTaxIncluded($priceIncludesTax)
580  ->setType('product')
581  ->setUnitPrice($price);
582 
583  $quoteDetails = $this->_quoteDetailsFactory->create();
584  $quoteDetails->setShippingAddress($shippingAddressDataObject)
585  ->setBillingAddress($billingAddressDataObject)
586  ->setCustomerTaxClassKey($customerTaxClassKey)
587  ->setItems([$item])
588  ->setCustomerId($this->_customerSession->getCustomerId());
589 
590  $storeId = null;
591  if ($store) {
592  $storeId = $store->getId();
593  }
594  $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId, $roundPrice);
595  $items = $taxDetails->getItems();
596  $taxDetailsItem = array_shift($items);
597 
598  if ($includingTax !== null) {
599  if ($includingTax) {
600  $price = $taxDetailsItem->getPriceInclTax();
601  } else {
602  $price = $taxDetailsItem->getPrice();
603  }
604  } else {
605  switch ($this->_taxConfig->getPriceDisplayType($store)) {
608  $price = $taxDetailsItem->getPrice();
609  break;
611  $price = $taxDetailsItem->getPriceInclTax();
612  break;
613  default:
614  break;
615  }
616  }
617  }
618 
619  if ($roundPrice) {
620  return $this->priceCurrency->round($price);
621  } else {
622  return $price;
623  }
624  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$price
const DISPLAY_TYPE_EXCLUDING_TAX
Definition: Config.php:102
const DISPLAY_TYPE_INCLUDING_TAX
Definition: Config.php:104
$items

◆ isPriceGlobal()

isPriceGlobal ( )

Is Global Price

Returns
bool

Definition at line 428 of file Data.php.

429  {
430  return $this->getPriceScope() == self::PRICE_SCOPE_GLOBAL;
431  }

◆ isUrlDirectivesParsingAllowed()

isUrlDirectivesParsingAllowed ( )

Check if the parsing of URL directives is allowed for the catalog

Returns
bool
Deprecated:
See also
\Magento\Catalog\Helper\Output::isDirectivesExists

Definition at line 453 of file Data.php.

454  {
455  return $this->scopeConfig->isSetFlag(
456  self::CONFIG_PARSE_URL_DIRECTIVES,
458  $this->_storeId
459  );
460  }

◆ isUsingStaticUrlsAllowed()

isUsingStaticUrlsAllowed ( )

Check if the store is configured to use static URLs for media

Returns
bool

Definition at line 438 of file Data.php.

439  {
440  return $this->scopeConfig->isSetFlag(
441  self::CONFIG_USE_STATIC_URLS,
443  );
444  }

◆ setStoreId()

setStoreId (   $store)

Set a specified store ID value

Parameters
int$store
Returns
$this

Definition at line 268 of file Data.php.

269  {
270  $this->_storeId = $store;
271  return $this;
272  }

◆ shouldDisplayProductCountOnLayer()

shouldDisplayProductCountOnLayer (   $storeId = null)

Whether to display items count for each filter option

Parameters
int$storeIdStore view ID
Returns
bool

Definition at line 478 of file Data.php.

479  {
480  return $this->scopeConfig->isSetFlag(
481  self::XML_PATH_DISPLAY_PRODUCT_COUNT,
483  $storeId
484  );
485  }

◆ splitSku()

splitSku (   $sku,
  $length = 30 
)

Split SKU of an item by dashes and spaces Words will not be broken, unless this length is greater than $length

Parameters
string$sku
int$length
Returns
string[]

Definition at line 391 of file Data.php.

392  {
393  return $this->string->split($sku, $length, true, false, '[\-\s]');
394  }

Field Documentation

◆ $_catalogCategory

$_catalogCategory
protected

Definition at line 87 of file Data.php.

◆ $_catalogProduct

$_catalogProduct
protected

Definition at line 80 of file Data.php.

◆ $_catalogSession

$_catalogSession
protected

Definition at line 104 of file Data.php.

◆ $_categoryPath

$_categoryPath
protected

Definition at line 59 of file Data.php.

◆ $_coreRegistry

$_coreRegistry
protected

Definition at line 73 of file Data.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 151 of file Data.php.

◆ $_quoteDetailsFactory

$_quoteDetailsFactory
protected

Definition at line 139 of file Data.php.

◆ $_quoteDetailsItemFactory

$_quoteDetailsItemFactory
protected

Definition at line 146 of file Data.php.

◆ $_storeId

$_storeId
protected

Definition at line 66 of file Data.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 111 of file Data.php.

◆ $_taxCalculationService

$_taxCalculationService
protected

Definition at line 158 of file Data.php.

◆ $_taxClassKeyFactory

$_taxClassKeyFactory
protected

Definition at line 125 of file Data.php.

◆ $_taxConfig

$_taxConfig
protected

Definition at line 132 of file Data.php.

◆ $_templateFilterFactory

$_templateFilterFactory
protected

Definition at line 118 of file Data.php.

◆ $_templateFilterModel

$_templateFilterModel
protected

Definition at line 97 of file Data.php.

◆ $addressFactory

$addressFactory
protected

Definition at line 185 of file Data.php.

◆ $categoryRepository

$categoryRepository
protected

Definition at line 175 of file Data.php.

◆ $customerGroupRepository

$customerGroupRepository
protected

Definition at line 180 of file Data.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 165 of file Data.php.

◆ $productRepository

$productRepository
protected

Definition at line 170 of file Data.php.

◆ $regionFactory

$regionFactory
protected

Definition at line 190 of file Data.php.

◆ $string

$string
protected

Definition at line 92 of file Data.php.

◆ CONFIG_PARSE_URL_DIRECTIVES

const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives'
Deprecated:
See also
\Magento\Catalog\Helper\Output::isDirectivesExists

Definition at line 39 of file Data.php.

◆ CONFIG_USE_STATIC_URLS

const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog'

Definition at line 33 of file Data.php.

◆ CONTEXT_CATALOG_DISPLAY_MODE

const CONTEXT_CATALOG_DISPLAY_MODE = 'catalog_mode'

Definition at line 50 of file Data.php.

◆ CONTEXT_CATALOG_LIMIT

const CONTEXT_CATALOG_LIMIT = 'catalog_limit'

Definition at line 52 of file Data.php.

◆ CONTEXT_CATALOG_SORT_DIRECTION

const CONTEXT_CATALOG_SORT_DIRECTION = 'catalog_sort_direction'

Cache context

Definition at line 46 of file Data.php.

◆ CONTEXT_CATALOG_SORT_ORDER

const CONTEXT_CATALOG_SORT_ORDER = 'catalog_sort_order'

Definition at line 48 of file Data.php.

◆ PRICE_SCOPE_GLOBAL

const PRICE_SCOPE_GLOBAL = 0

Definition at line 27 of file Data.php.

◆ PRICE_SCOPE_WEBSITE

const PRICE_SCOPE_WEBSITE = 1

Definition at line 29 of file Data.php.

◆ XML_PATH_DISPLAY_PRODUCT_COUNT

const XML_PATH_DISPLAY_PRODUCT_COUNT = 'catalog/layered_navigation/display_product_count'

Definition at line 41 of file Data.php.

◆ XML_PATH_PRICE_SCOPE

const XML_PATH_PRICE_SCOPE = 'catalog/price/scope'

Definition at line 31 of file Data.php.


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