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

Public Member Functions

 __construct (\Magento\Catalog\Helper\Image $imageHelper, \Magento\Msrp\Helper\Data $msrpHelper, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Catalog\Helper\Product\ConfigurationPool $configurationPool, \Magento\Checkout\Helper\Data $checkoutHelper, \Magento\Framework\Escaper $escaper=null, ItemResolverInterface $itemResolver=null)
 
- Public Member Functions inherited from AbstractItem
 getItemData (Item $item)
 

Protected Member Functions

 doGetItemData ()
 
 getOptionList ()
 
 getProductForThumbnail ()
 
 getProduct ()
 
 getConfigureUrl ()
 
 hasProductUrl ()
 
 getProductUrl ()
 
- Protected Member Functions inherited from AbstractItem
 doGetItemData ()
 

Protected Attributes

 $imageHelper
 
 $msrpHelper
 
 $urlBuilder
 
 $configurationPool
 
 $checkoutHelper
 
- Protected Attributes inherited from AbstractItem
 $item
 

Detailed Description

Default item

Definition at line 15 of file DefaultItem.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Catalog\Helper\Image  $imageHelper,
\Magento\Msrp\Helper\Data  $msrpHelper,
\Magento\Framework\UrlInterface  $urlBuilder,
\Magento\Catalog\Helper\Product\ConfigurationPool  $configurationPool,
\Magento\Checkout\Helper\Data  $checkoutHelper,
\Magento\Framework\Escaper  $escaper = null,
ItemResolverInterface  $itemResolver = null 
)
Parameters
\Magento\Catalog\Helper\Image$imageHelper
\Magento\Msrp\Helper\Data$msrpHelper
\Magento\Framework\UrlInterface$urlBuilder
\Magento\Catalog\Helper\Product\ConfigurationPool$configurationPool
\Magento\Checkout\Helper\Data$checkoutHelper
\Magento\Framework\Escaper | null$escaper
ItemResolverInterface | null$itemResolver@codeCoverageIgnore

Definition at line 62 of file DefaultItem.php.

70  {
71  $this->configurationPool = $configurationPool;
72  $this->imageHelper = $imageHelper;
73  $this->msrpHelper = $msrpHelper;
74  $this->urlBuilder = $urlBuilder;
75  $this->checkoutHelper = $checkoutHelper;
76  $this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
77  $this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(ItemResolverInterface::class);
78  }

Member Function Documentation

◆ doGetItemData()

doGetItemData ( )
protected

{}

Definition at line 83 of file DefaultItem.php.

84  {
85  $imageHelper = $this->imageHelper->init($this->getProductForThumbnail(), 'mini_cart_product_thumbnail');
86  $productName = $this->escaper->escapeHtml($this->item->getProduct()->getName());
87 
88  return [
89  'options' => $this->getOptionList(),
90  'qty' => $this->item->getQty() * 1,
91  'item_id' => $this->item->getId(),
92  'configure_url' => $this->getConfigureUrl(),
93  'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
94  'product_id' => $this->item->getProduct()->getId(),
95  'product_name' => $productName,
96  'product_sku' => $this->item->getProduct()->getSku(),
97  'product_url' => $this->getProductUrl(),
98  'product_has_url' => $this->hasProductUrl(),
99  'product_price' => $this->checkoutHelper->formatPrice($this->item->getCalculationPrice()),
100  'product_price_value' => $this->item->getCalculationPrice(),
101  'product_image' => [
102  'src' => $imageHelper->getUrl(),
103  'alt' => $imageHelper->getLabel(),
104  'width' => $imageHelper->getWidth(),
105  'height' => $imageHelper->getHeight(),
106  ],
107  'canApplyMsrp' => $this->msrpHelper->isShowBeforeOrderConfirm($this->item->getProduct())
108  && $this->msrpHelper->isMinimalPriceLessMsrp($this->item->getProduct()),
109  ];
110  }

◆ getConfigureUrl()

getConfigureUrl ( )
protected

Get item configure url

Returns
string

Definition at line 146 of file DefaultItem.php.

147  {
148  return $this->urlBuilder->getUrl(
149  'checkout/cart/configure',
150  ['id' => $this->item->getId(), 'product_id' => $this->item->getProduct()->getId()]
151  );
152  }

◆ getOptionList()

getOptionList ( )
protected

Get list of all options for product

Returns
array @codeCoverageIgnore

Definition at line 118 of file DefaultItem.php.

119  {
120  return $this->configurationPool->getByProductType($this->item->getProductType())->getOptions($this->item);
121  }

◆ getProduct()

getProduct ( )
protected
Returns
\Magento\Catalog\Model\Product @codeCoverageIgnore

Definition at line 136 of file DefaultItem.php.

137  {
138  return $this->item->getProduct();
139  }

◆ getProductForThumbnail()

getProductForThumbnail ( )
protected
Returns
\Magento\Catalog\Model\Product @codeCoverageIgnore

Definition at line 127 of file DefaultItem.php.

128  {
129  return $this->itemResolver->getFinalProduct($this->item);
130  }

◆ getProductUrl()

getProductUrl ( )
protected

Retrieve URL to item Product

Returns
string

Definition at line 190 of file DefaultItem.php.

191  {
192  if ($this->item->getRedirectUrl()) {
193  return $this->item->getRedirectUrl();
194  }
195 
196  $product = $this->item->getProduct();
197  $option = $this->item->getOptionByCode('product_type');
198  if ($option) {
199  $product = $option->getProduct();
200  }
201 
202  return $product->getUrlModel()->getUrl($product);
203  }

◆ hasProductUrl()

hasProductUrl ( )
protected

Check Product has URL

Returns
bool

Definition at line 159 of file DefaultItem.php.

160  {
161  if ($this->item->getRedirectUrl()) {
162  return true;
163  }
164 
165  $product = $this->item->getProduct();
166  $option = $this->item->getOptionByCode('product_type');
167  if ($option) {
168  $product = $option->getProduct();
169  }
170 
171  if ($product->isVisibleInSiteVisibility()) {
172  return true;
173  } else {
174  if ($product->hasUrlDataObject()) {
175  $data = $product->getUrlDataObject();
176  if (in_array($data->getVisibility(), $product->getVisibleInSiteVisibilities())) {
177  return true;
178  }
179  }
180  }
181 
182  return false;
183  }

Field Documentation

◆ $checkoutHelper

$checkoutHelper
protected

Definition at line 40 of file DefaultItem.php.

◆ $configurationPool

$configurationPool
protected

Definition at line 35 of file DefaultItem.php.

◆ $imageHelper

$imageHelper
protected

Definition at line 20 of file DefaultItem.php.

◆ $msrpHelper

$msrpHelper
protected

Definition at line 25 of file DefaultItem.php.

◆ $urlBuilder

$urlBuilder
protected

Definition at line 30 of file DefaultItem.php.


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