Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractBlock.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Wishlist\Block;
8 
13 
18 {
24  protected $_collection;
25 
31  protected $_wishlist;
32 
36  protected $httpContext;
37 
41  private $viewConfig;
42 
46  private $imageUrlBuilder;
47 
55  public function __construct(
56  \Magento\Catalog\Block\Product\Context $context,
57  \Magento\Framework\App\Http\Context $httpContext,
58  array $data = [],
59  ConfigInterface $config = null,
60  UrlBuilder $urlBuilder = null
61  ) {
62  $this->httpContext = $httpContext;
63  parent::__construct(
64  $context,
65  $data
66  );
67  $this->viewConfig = $config ?? ObjectManager::getInstance()->get(ConfigInterface::class);
68  $this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
69  }
70 
76  protected function _getHelper()
77  {
79  }
80 
86  protected function _getWishlist()
87  {
88  return $this->_getHelper()->getWishlist();
89  }
90 
98  protected function _prepareCollection($collection)
99  {
100  return $this;
101  }
102 
108  protected function _createWishlistItemCollection()
109  {
110  return $this->_getWishlist()->getItemCollection();
111  }
112 
118  public function getWishlistItems()
119  {
120  if ($this->_collection === null) {
121  $this->_collection = $this->_createWishlistItemCollection();
122  $this->_prepareCollection($this->_collection);
123  }
124 
125  return $this->_collection;
126  }
127 
133  public function getWishlistInstance()
134  {
135  return $this->_getWishlist();
136  }
137 
145  public function getItemRemoveParams($item)
146  {
147  return $this->_getHelper()->getRemoveParams($item);
148  }
149 
156  public function getItemAddToCartParams($item)
157  {
158  return $this->_getHelper()->getAddToCartParams($item);
159  }
160 
168  {
169  return $this->_getHelper()->getSharedAddToCartUrl($item);
170  }
171 
177  public function getSharedAddAllToCartUrl()
178  {
179  return $this->_getHelper()->getSharedAddAllToCartUrl();
180  }
181 
189  {
190  return $this->_getHelper()->getAddParams($product);
191  }
192 
200  public function getItemConfigureUrl($product)
201  {
202  return $this->_getHelper()->getConfigureUrl($product);
203  }
204 
211  public function getEscapedDescription($item)
212  {
213  if ($item->getDescription()) {
214  return $this->escapeHtml($item->getDescription());
215  }
216  return '&nbsp;';
217  }
218 
225  public function hasDescription($item)
226  {
227  return trim($item->getDescription()) != '';
228  }
229 
236  public function getFormatedDate($date)
237  {
238  return $this->formatDate($date, \IntlDateFormatter::MEDIUM);
239  }
240 
246  public function isSaleable()
247  {
248  foreach ($this->getWishlistItems() as $item) {
249  if ($item->getProduct()->isSaleable()) {
250  return true;
251  }
252  }
253 
254  return false;
255  }
256 
262  public function getWishlistItemsCount()
263  {
264  return $this->_getWishlist()->getItemsCount();
265  }
266 
273  public function getQty($item)
274  {
275  $qty = $item->getQty() * 1;
276  if (!$qty) {
277  $qty = 1;
278  }
279  return $qty;
280  }
281 
287  public function hasWishlistItems()
288  {
289  return $this->getWishlistItemsCount() > 0;
290  }
291 
299  public function getProductUrl($item, $additional = [])
300  {
301  return $this->_getHelper()->getProductUrl($item, $additional);
302  }
303 
310  public function getImageUrl($product)
311  {
312  $viewImageConfig = $this->viewConfig->getViewConfig()->getMediaAttributes(
313  'Magento_Catalog',
315  'wishlist_small_image'
316  );
317  return $this->imageUrlBuilder->getUrl(
318  $product->getData($viewImageConfig['type']),
319  'wishlist_small_image'
320  );
321  }
322 
332  public function getItemPriceHtml(
333  \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item,
334  $priceType = \Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_PRICE_CODE,
335  $renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
336  array $arguments = []
337  ) {
339  $priceRender = $this->getLayout()->getBlock('product.price.render.default');
340  $priceRender->setItem($item);
341  $arguments += [
342  'zone' => $renderZone,
343  'render_block' => $priceRender
344  ];
345  return $priceRender ? $priceRender->render($priceType, $item->getProduct(), $arguments) : null;
346  }
347 }
$config
Definition: fraud_order.php:17
formatDate( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
__construct(\Magento\Catalog\Block\Product\Context $context, \Magento\Framework\App\Http\Context $httpContext, array $data=[], ConfigInterface $config=null, UrlBuilder $urlBuilder=null)
$this _collection
Definition: coupons.php:7
$priceType
Definition: msrp.phtml:18
$arguments
getProductUrl($item, $additional=[])