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 Rss

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Customer\Model\Session $customerSession, \Magento\Wishlist\Model\WishlistFactory $wishlistFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, \Magento\Customer\Helper\View $customerViewHelper, WishlistProviderInterface $wishlistProvider, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository)
 
 setCustomer (\Magento\Customer\Api\Data\CustomerInterface $customer)
 
 getCustomer ()
 
 getWishlist ()
 
 getItemCount ()
 
 getWishlistItemCollection ()
 
 getRemoveParams ($item, $addReferer=false)
 
 getConfigureUrl ($item)
 
 getAddParams ($item, array $params=[])
 
 getMoveFromCartParams ($itemId)
 
 getUpdateParams ($item)
 
 getAddToCartUrl ($item)
 
 getAddToCartParams ($item, $addReferer=false)
 
 addRefererToParams (array $params)
 
 getSharedAddToCartUrl ($item)
 
 getSharedAddAllToCartUrl ()
 
 getListUrl ($wishlistId=null)
 
 isAllow ()
 
 isAllowInCart ()
 
 getCustomerName ()
 
 getRssUrl ($wishlistId=null)
 
 defaultCommentString ()
 
 getDefaultWishlistName ()
 
 calculate ()
 
 isDisplayQty ()
 
 getProductUrl ($item, $additional=[])
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const XML_PATH_WISHLIST_LINK_USE_QTY = 'wishlist/wishlist_link/use_qty'
 
const XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock'
 

Protected Member Functions

 _isCustomerLogIn ()
 
 _getCurrentCustomer ()
 
 _createWishlistItemCollection ()
 
 _getUrlStore ($item)
 
 _getCartUrlParameters ($item)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_currentCustomer
 
 $_wishlist
 
 $_productCollection
 
 $_wishlistItemCollection
 
 $_coreRegistry
 
 $_customerSession
 
 $_wishlistFactory
 
 $_storeManager
 
 $_postDataHelper
 
 $_customerViewHelper
 
 $wishlistProvider
 
 $productRepository
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Wishlist Data Helper

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects)

@api

Since
100.0.2

Definition at line 20 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Framework\Registry  $coreRegistry,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Wishlist\Model\WishlistFactory  $wishlistFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Data\Helper\PostHelper  $postDataHelper,
\Magento\Customer\Helper\View  $customerViewHelper,
WishlistProviderInterface  $wishlistProvider,
\Magento\Catalog\Api\ProductRepositoryInterface  $productRepository 
)
Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Framework\Registry$coreRegistry
\Magento\Customer\Model\Session$customerSession
\Magento\Wishlist\Model\WishlistFactory$wishlistFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Data\Helper\PostHelper$postDataHelper
\Magento\Customer\Helper\View$customerViewHelper
WishlistProviderInterface$wishlistProvider
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository

Definition at line 113 of file Data.php.

123  {
124  $this->_coreRegistry = $coreRegistry;
125  $this->_customerSession = $customerSession;
126  $this->_wishlistFactory = $wishlistFactory;
127  $this->_storeManager = $storeManager;
128  $this->_postDataHelper = $postDataHelper;
129  $this->_customerViewHelper = $customerViewHelper;
130  $this->wishlistProvider = $wishlistProvider;
131  $this->productRepository = $productRepository;
132  parent::__construct($context);
133  }
$storeManager

Member Function Documentation

◆ _createWishlistItemCollection()

_createWishlistItemCollection ( )
protected

Create wishlist item collection

Returns
\Magento\Wishlist\Model\ResourceModel\Item\Collection

Definition at line 232 of file Data.php.

233  {
234  return $this->getWishlist()->getItemCollection();
235  }

◆ _getCartUrlParameters()

_getCartUrlParameters (   $item)
protected

Get cart URL parameters

Parameters
string | \Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
array

Definition at line 459 of file Data.php.

460  {
461  $params = [
462  'item' => is_string($item) ? $item : $item->getWishlistItemId(),
463  ];
464  if ($item instanceof \Magento\Wishlist\Model\Item) {
465  $params['qty'] = $item->getQty();
466  }
467  return $params;
468  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _getCurrentCustomer()

_getCurrentCustomer ( )
protected

Retrieve logged in customer

Returns
\Magento\Customer\Api\Data\CustomerInterface

Definition at line 150 of file Data.php.

151  {
152  return $this->getCustomer();
153  }

◆ _getUrlStore()

_getUrlStore (   $item)
protected

Retrieve Item Store for URL

Parameters
\Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
\Magento\Store\Model\Store

Definition at line 256 of file Data.php.

257  {
258  $storeId = null;
259  $product = null;
260  if ($item instanceof \Magento\Wishlist\Model\Item) {
261  $product = $item->getProduct();
262  } elseif ($item instanceof \Magento\Catalog\Model\Product) {
263  $product = $item;
264  }
265  if ($product) {
266  if ($product->isVisibleInSiteVisibility()) {
267  $storeId = $product->getStoreId();
268  } else {
269  if ($product->hasUrlDataObject()) {
270  $storeId = $product->getUrlDataObject()->getStoreId();
271  }
272  }
273  }
274  return $this->_storeManager->getStore($storeId);
275  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ _isCustomerLogIn()

_isCustomerLogIn ( )
protected

Retrieve customer login status

Returns
bool

Definition at line 140 of file Data.php.

141  {
142  return $this->_customerSession->isLoggedIn();
143  }

◆ addRefererToParams()

addRefererToParams ( array  $params)

Add UENC referer to params

Parameters
array$params
Returns
array

Definition at line 420 of file Data.php.

421  {
423  $this->urlEncoder->encode($this->_getRequest()->getServer('HTTP_REFERER'));
424  return $params;
425  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ calculate()

calculate ( )

Calculate count of wishlist items and put value to customer session. Method called after wishlist modifications and trigger 'wishlist_items_renewed' event. Depends from configuration.

Returns
$this

Definition at line 570 of file Data.php.

571  {
572  $count = 0;
573  if ($this->getCustomer()) {
574  $collection = $this->getWishlistItemCollection()->setInStockFilter(true);
575  if ($this->scopeConfig->getValue(
576  self::XML_PATH_WISHLIST_LINK_USE_QTY,
577  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
578  )
579  ) {
580  $count = $collection->getItemsQty();
581  } else {
582  $count = $collection->count();
583  }
584  $this->_customerSession->setWishlistDisplayType(
585  $this->scopeConfig->getValue(
586  self::XML_PATH_WISHLIST_LINK_USE_QTY,
587  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
588  )
589  );
590  $this->_customerSession->setDisplayOutOfStockProducts(
591  $this->scopeConfig->getValue(
592  self::XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK,
593  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
594  )
595  );
596  }
597  $this->_customerSession->setWishlistItemCount($count);
598  $this->_eventManager->dispatch('wishlist_items_renewed');
599  return $this;
600  }
$count
Definition: recent.phtml:13

◆ defaultCommentString()

defaultCommentString ( )

Retrieve default empty comment message

Returns
\Magento\Framework\Phrase

Definition at line 548 of file Data.php.

549  {
550  return __('Comment');
551  }
__()
Definition: __.php:13

◆ getAddParams()

getAddParams (   $item,
array  $params = [] 
)

Retrieve params for adding product to wishlist

Parameters
\Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
array$params
Returns
string

Definition at line 321 of file Data.php.

322  {
323  $productId = null;
324  if ($item instanceof \Magento\Catalog\Model\Product) {
325  $productId = $item->getEntityId();
326  }
327  if ($item instanceof \Magento\Wishlist\Model\Item) {
328  $productId = $item->getProductId();
329  }
330 
331  $url = $this->_getUrlStore($item)->getUrl('wishlist/index/add');
332  if ($productId) {
333  $params['product'] = $productId;
334  }
335 
336  return $this->_postDataHelper->getPostData($url, $params);
337  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getAddToCartParams()

getAddToCartParams (   $item,
  $addReferer = false 
)

Retrieve URL for adding item to shopping cart

Parameters
string | \Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
bool$addReferer
Returns
string

Definition at line 399 of file Data.php.

400  {
403 
404  if ($addReferer) {
406  }
407 
408  return $this->_postDataHelper->getPostData(
409  $this->_getUrlStore($item)->getUrl('wishlist/index/cart'),
410  $params
411  );
412  }
addRefererToParams(array $params)
Definition: Data.php:420
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getAddToCartUrl()

getAddToCartUrl (   $item)

Retrieve params for adding item to shopping cart

Parameters
string | \Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
string

Definition at line 387 of file Data.php.

388  {
389  return $this->_getUrlStore($item)->getUrl('wishlist/index/cart', $this->_getCartUrlParameters($item));
390  }

◆ getConfigureUrl()

getConfigureUrl (   $item)

Retrieve URL for configuring item from wishlist

Parameters
\Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
string

Definition at line 303 of file Data.php.

304  {
305  return $this->_getUrl(
306  'wishlist/index/configure',
307  [
308  'id' => $item->getWishlistItemId(),
309  'product_id' => $item->getProductId()
310  ]
311  );
312  }

◆ getCustomer()

getCustomer ( )

Retrieve current customer

Returns
\Magento\Customer\Api\Data\CustomerInterface|null

Definition at line 171 of file Data.php.

172  {
173  if (!$this->_currentCustomer && $this->_customerSession->isLoggedIn()) {
174  $this->_currentCustomer = $this->_customerSession->getCustomerDataObject();
175  }
177  }

◆ getCustomerName()

getCustomerName ( )

Retrieve customer name

Returns
string|null

Definition at line 517 of file Data.php.

518  {
519  return $this->getCustomer()
520  ? $this->_customerViewHelper->getCustomerName($this->getCustomer())
521  : null;
522  }

◆ getDefaultWishlistName()

getDefaultWishlistName ( )

Retrieve default empty comment message

Returns
\Magento\Framework\Phrase

Definition at line 558 of file Data.php.

559  {
560  return __('Wish List');
561  }
__()
Definition: __.php:13

◆ getItemCount()

getItemCount ( )

Retrieve wishlist item count (include config settings)

Used in top link menu only

Returns
int

Definition at line 203 of file Data.php.

204  {
205  $storedDisplayType = $this->_customerSession->getWishlistDisplayType();
206  $currentDisplayType = $this->scopeConfig->getValue(
207  self::XML_PATH_WISHLIST_LINK_USE_QTY,
208  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
209  );
210 
211  $storedDisplayOutOfStockProducts = $this->_customerSession->getDisplayOutOfStockProducts();
212  $currentDisplayOutOfStockProducts = $this->scopeConfig->getValue(
213  self::XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK,
214  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
215  );
216  if (!$this->_customerSession->hasWishlistItemCount() ||
217  $currentDisplayType != $storedDisplayType ||
218  $this->_customerSession->hasDisplayOutOfStockProducts() ||
219  $currentDisplayOutOfStockProducts != $storedDisplayOutOfStockProducts
220  ) {
221  $this->calculate();
222  }
223 
224  return $this->_customerSession->getWishlistItemCount();
225  }

◆ getListUrl()

getListUrl (   $wishlistId = null)

Retrieve customer wishlist url

Parameters
int$wishlistId
Returns
string

Definition at line 476 of file Data.php.

477  {
478  $params = [];
479  if ($wishlistId) {
480  $params['wishlist_id'] = $wishlistId;
481  }
482  return $this->_getUrl('wishlist', $params);
483  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getMoveFromCartParams()

getMoveFromCartParams (   $itemId)

Retrieve params for adding product to wishlist

Parameters
int$itemId
Returns
string

Definition at line 346 of file Data.php.

347  {
348  $url = $this->_getUrl('wishlist/index/fromcart');
349  $params = ['item' => $itemId];
350  return $this->_postDataHelper->getPostData($url, $params);
351  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getProductUrl()

getProductUrl (   $item,
  $additional = [] 
)

Retrieve URL to item Product

Parameters
\Magento\Wishlist\Model\Item | \Magento\Catalog\Model\Product$item
array$additional
Returns
string

Definition at line 622 of file Data.php.

623  {
624  if ($item instanceof \Magento\Catalog\Model\Product) {
625  $product = $item;
626  } else {
627  $product = $item->getProduct();
628  }
629  $buyRequest = $item->getBuyRequest();
630  if (is_object($buyRequest)) {
631  $config = $buyRequest->getSuperProductConfig();
632  if ($config && !empty($config['product_id'])) {
633  $product = $this->productRepository->getById(
634  $config['product_id'],
635  false,
636  $this->_storeManager->getStore()->getStoreId()
637  );
638  }
639  }
640  return $product->getUrlModel()->getUrl($product, $additional);
641  }
$config
Definition: fraud_order.php:17
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ getRemoveParams()

getRemoveParams (   $item,
  $addReferer = false 
)

Retrieve params for removing item from wishlist

Parameters
\Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
bool$addReferer
Returns
string

Definition at line 284 of file Data.php.

285  {
286  $url = $this->_getUrl('wishlist/index/remove');
287  $params = ['item' => $item->getWishlistItemId()];
289 
290  if ($addReferer) {
292  }
293 
294  return $this->_postDataHelper->getPostData($url, $params);
295  }
addRefererToParams(array $params)
Definition: Data.php:420
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getRssUrl()

getRssUrl (   $wishlistId = null)

Retrieve RSS URL

Parameters
int | string | null$wishlistId
Returns
string

Definition at line 530 of file Data.php.

531  {
532  $customer = $this->_getCurrentCustomer();
533  if ($customer) {
534  $key = $customer->getId() . ',' . $customer->getEmail();
535  $params = ['data' => $this->urlEncoder->encode($key), '_secure' => false];
536  }
537  if ($wishlistId) {
538  $params['wishlist_id'] = $wishlistId;
539  }
540  return $this->_getUrl('wishlist/index/rss', $params);
541  }
$customer
Definition: customers.php:11
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getSharedAddAllToCartUrl()

getSharedAddAllToCartUrl ( )

Retrieve URL for adding All items to shopping cart from shared wishlist

Returns
string

Definition at line 446 of file Data.php.

447  {
448  return $this->_postDataHelper->getPostData(
449  $this->_storeManager->getStore()->getUrl('*/*/allcart', ['_current' => true])
450  );
451  }

◆ getSharedAddToCartUrl()

getSharedAddToCartUrl (   $item)

Retrieve URL for adding item to shopping cart from shared wishlist

Parameters
string | \Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
string

Definition at line 433 of file Data.php.

434  {
435  return $this->_postDataHelper->getPostData(
436  $this->_getUrlStore($item)->getUrl('wishlist/shared/cart'),
438  );
439  }

◆ getUpdateParams()

getUpdateParams (   $item)

Retrieve params for updating product in wishlist

Parameters
\Magento\Catalog\Model\Product | \Magento\Wishlist\Model\Item$item
Returns
string|false

Definition at line 360 of file Data.php.

361  {
362  $itemId = null;
363  if ($item instanceof \Magento\Catalog\Model\Product) {
364  $itemId = $item->getWishlistItemId();
365  $productId = $item->getId();
366  }
367  if ($item instanceof \Magento\Wishlist\Model\Item) {
368  $itemId = $item->getId();
369  $productId = $item->getProduct()->getId();
370  }
371 
372  $url = $this->_getUrl('wishlist/index/updateItemOptions');
373  if ($itemId) {
374  $params = ['id' => $itemId, 'product' => $productId, 'qty' => $item->getQty()];
375  return $this->_postDataHelper->getPostData($url, $params);
376  }
377 
378  return false;
379  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getWishlist()

getWishlist ( )

Retrieve wishlist by logged in customer

Returns
\Magento\Wishlist\Model\Wishlist

Definition at line 184 of file Data.php.

185  {
186  if ($this->_wishlist === null) {
187  if ($this->_coreRegistry->registry('shared_wishlist')) {
188  $this->_wishlist = $this->_coreRegistry->registry('shared_wishlist');
189  } else {
190  $this->_wishlist = $this->wishlistProvider->getWishlist();
191  }
192  }
193  return $this->_wishlist;
194  }

◆ getWishlistItemCollection()

getWishlistItemCollection ( )

Retrieve wishlist items collection

Returns
\Magento\Wishlist\Model\ResourceModel\Item\Collection

Definition at line 242 of file Data.php.

243  {
244  if ($this->_wishlistItemCollection === null) {
245  $this->_wishlistItemCollection = $this->_createWishlistItemCollection();
246  }
248  }

◆ isAllow()

isAllow ( )

Check is allow wishlist module

Returns
bool

Definition at line 490 of file Data.php.

491  {
492  if ($this->_moduleManager->isOutputEnabled($this->_getModuleName()) && $this->scopeConfig->getValue(
493  'wishlist/general/active',
494  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
495  )
496  ) {
497  return true;
498  }
499  return false;
500  }

◆ isAllowInCart()

isAllowInCart ( )

Check is allow wishlist action in shopping cart

Returns
bool

Definition at line 507 of file Data.php.

508  {
509  return $this->isAllow() && $this->getCustomer();
510  }

◆ isDisplayQty()

isDisplayQty ( )

Should display item quantities in my wishlist link

Returns
bool

Definition at line 607 of file Data.php.

608  {
609  return $this->scopeConfig->getValue(
610  self::XML_PATH_WISHLIST_LINK_USE_QTY,
611  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
612  );
613  }

◆ setCustomer()

setCustomer ( \Magento\Customer\Api\Data\CustomerInterface  $customer)

Set current customer

Parameters
\Magento\Customer\Api\Data\CustomerInterface$customer
Returns
void

Definition at line 161 of file Data.php.

162  {
163  $this->_currentCustomer = $customer;
164  }
$customer
Definition: customers.php:11

Field Documentation

◆ $_coreRegistry

$_coreRegistry
protected

Definition at line 65 of file Data.php.

◆ $_currentCustomer

$_currentCustomer
protected

Definition at line 37 of file Data.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 70 of file Data.php.

◆ $_customerViewHelper

$_customerViewHelper
protected

Definition at line 90 of file Data.php.

◆ $_postDataHelper

$_postDataHelper
protected

Definition at line 85 of file Data.php.

◆ $_productCollection

$_productCollection
protected

Definition at line 51 of file Data.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 80 of file Data.php.

◆ $_wishlist

$_wishlist
protected

Definition at line 44 of file Data.php.

◆ $_wishlistFactory

$_wishlistFactory
protected

Definition at line 75 of file Data.php.

◆ $_wishlistItemCollection

$_wishlistItemCollection
protected

Definition at line 58 of file Data.php.

◆ $productRepository

$productRepository
protected

Definition at line 100 of file Data.php.

◆ $wishlistProvider

$wishlistProvider
protected

Definition at line 95 of file Data.php.

◆ XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK

const XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock'

Config key 'Display Out of Stock Products'

Definition at line 30 of file Data.php.

◆ XML_PATH_WISHLIST_LINK_USE_QTY

const XML_PATH_WISHLIST_LINK_USE_QTY = 'wishlist/wishlist_link/use_qty'

Config key 'Display Wishlist Summary'

Definition at line 25 of file Data.php.


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