Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Wishlist.php
Go to the documentation of this file.
1 <?php
13 
19 {
25  protected $_optionsCfg = [];
26 
30  protected $_helperPool;
31 
35  protected $currentCustomer;
36 
40  protected $postDataHelper;
41 
50  public function __construct(
51  \Magento\Catalog\Block\Product\Context $context,
52  \Magento\Framework\App\Http\Context $httpContext,
53  \Magento\Catalog\Helper\Product\ConfigurationPool $helperPool,
54  \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
55  \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
56  array $data = []
57  ) {
58  parent::__construct(
59  $context,
61  $data
62  );
63  $this->_helperPool = $helperPool;
64  $this->currentCustomer = $currentCustomer;
65  $this->postDataHelper = $postDataHelper;
66  }
67 
74  protected function _prepareCollection($collection)
75  {
76  $collection->setInStockFilter(true)->setOrder('added_at', 'ASC');
77  return $this;
78  }
79 
85  protected function _prepareLayout()
86  {
87  parent::_prepareLayout();
88  $this->pageConfig->getTitle()->set(__('My Wish List'));
89  }
90 
96  public function getBackUrl()
97  {
98  return $this->getUrl('customer/account/');
99  }
100 
107  public function setOptionsRenderCfgs($optionCfg)
108  {
109  $this->_optionsCfg = $optionCfg;
110  return $this;
111  }
112 
118  public function getOptionsRenderCfgs()
119  {
120  return $this->_optionsCfg;
121  }
122 
131  public function addOptionsRenderCfg($productType, $helperName, $template = null)
132  {
133  $this->_optionsCfg[$productType] = ['helper' => $helperName, 'template' => $template];
134  return $this;
135  }
136 
143  public function getOptionsRenderCfg($productType)
144  {
145  if (isset($this->_optionsCfg[$productType])) {
146  return $this->_optionsCfg[$productType];
147  } elseif (isset($this->_optionsCfg['default'])) {
148  return $this->_optionsCfg['default'];
149  } else {
150  return null;
151  }
152  }
153 
160  public function getDetailsHtml(\Magento\Wishlist\Model\Item $item)
161  {
162  $cfg = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());
163  if (!$cfg) {
164  return '';
165  }
166 
167  $block = $this->getChildBlock('item_options');
168  if (!$block) {
169  return '';
170  }
171 
172  if ($cfg['template']) {
173  $template = $cfg['template'];
174  } else {
175  $cfgDefault = $this->getOptionsRenderCfg('default');
176  if (!$cfgDefault) {
177  return '';
178  }
179  $template = $cfgDefault['template'];
180  }
181 
182  $block->setTemplate($template);
183  $block->setOptionList($this->_helperPool->get($cfg['helper'])->getOptions($item));
184  return $block->toHtml();
185  }
186 
193  public function getAddToCartQty(\Magento\Wishlist\Model\Item $item)
194  {
195  $qty = $this->getQty($item);
196  return $qty ? $qty : 1;
197  }
198 
203  public function getAddAllToCartParams()
204  {
205  return $this->postDataHelper->getPostData(
206  $this->getUrl('wishlist/index/allcart'),
207  ['wishlist_id' => $this->getWishlistInstance()->getId()]
208  );
209  }
210 
214  protected function _toHtml()
215  {
216  if ($this->currentCustomer->getCustomerId()) {
217  return parent::_toHtml();
218  } else {
219  return '';
220  }
221  }
222 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$block
Definition: block.php:8
getAddToCartQty(\Magento\Wishlist\Model\Item $item)
Definition: Wishlist.php:193
__construct(\Magento\Catalog\Block\Product\Context $context, \Magento\Framework\App\Http\Context $httpContext, \Magento\Catalog\Helper\Product\ConfigurationPool $helperPool, \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, array $data=[])
Definition: Wishlist.php:50
getDetailsHtml(\Magento\Wishlist\Model\Item $item)
Definition: Wishlist.php:160
$template
Definition: export.php:12
addOptionsRenderCfg($productType, $helperName, $template=null)
Definition: Wishlist.php:131