19 class Compare extends \Magento\Framework\Url\Helper\Data
102 private $_storeManager;
122 \
Magento\Customer\Model\Visitor $customerVisitor,
123 \
Magento\Customer\Model\Session $customerSession,
129 $this->_itemCollectionFactory = $itemCollectionFactory;
130 $this->_catalogProductVisibility = $catalogProductVisibility;
131 $this->_customerVisitor = $customerVisitor;
132 $this->_customerSession = $customerSession;
133 $this->_catalogSession = $catalogSession;
134 $this->_formKey = $formKey;
138 parent::__construct($context);
150 $itemIds[] =
$item->getId();
154 'items' => implode(
',', $itemIds),
169 return $this->postHelper->getPostData($this->
getAddUrl(), [
'product' =>
$product->getId()]);
179 return $this->
_getUrl(
'catalog/product_compare/add');
190 $beforeCompareUrl = $this->_catalogSession->getBeforeCompareUrl();
196 return $this->_wishlistHelper->getAddParams(
$product, $encodedUrl);
207 $beforeCompareUrl = $this->_catalogSession->getBeforeCompareUrl();
224 return $this->
_getUrl(
'catalog/product_compare/remove');
238 'confirmation' =>
true,
239 'confirmationMessage' =>
__(
'Are you sure you want to remove this item from your Compare Products list?')
251 return $this->
_getUrl(
'catalog/product_compare/clear');
263 'confirmation' =>
true,
264 'confirmationMessage' =>
__(
'Are you sure you want to remove all items from your Compare Products list?'),
276 if (!$this->_itemCollection) {
279 $this->_itemCollection = $this->_itemCollectionFactory->create();
280 $this->_itemCollection->useProductItem(
true)->setStoreId($this->_storeManager->getStore()->getId());
282 if ($this->_customerSession->isLoggedIn()) {
283 $this->_itemCollection->setCustomerId($this->_customerSession->getCustomerId());
284 }
elseif ($this->_customerId) {
285 $this->_itemCollection->setCustomerId($this->_customerId);
287 $this->_itemCollection->setVisitorId($this->_customerVisitor->getId());
290 $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
293 $this->_itemCollection->addPriceData();
295 $this->_itemCollection->addAttributeToSelect(
'name')->addUrlRewrite()->load();
298 $this->_catalogSession->setCatalogCompareItemsCount(count($this->_itemCollection));
310 public function calculate($logout =
false)
313 $collection = $this->_itemCollectionFactory->create()
314 ->useProductItem(
true);
315 if (!$logout && $this->_customerSession->isLoggedIn()) {
316 $collection->setCustomerId($this->_customerSession->getCustomerId());
317 }
elseif ($this->_customerId) {
320 $collection->setVisitorId($this->_customerVisitor->getId());
325 ->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
328 $this->_catalogSession->setCatalogCompareItemsCount(
$count);
340 if (!$this->_catalogSession->hasCatalogCompareItemsCount()) {
344 return $this->_catalogSession->getCatalogCompareItemsCount();
365 $this->_allowUsedFlat = (bool)$flag;
388 $this->_customerId =
$id;
elseif(isset( $params[ 'redirect_parent']))
getPostDataParams($product)
getAddToWishlistParams($product)
const PARAM_NAME_URL_ENCODED
_getUrl($route, $params=[])
$_catalogProductVisibility
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
getAddToCartUrl($product)
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory $itemCollectionFactory, \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, \Magento\Customer\Model\Visitor $customerVisitor, \Magento\Customer\Model\Session $customerSession, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Data\Form\FormKey $formKey, \Magento\Wishlist\Helper\Data $wishlistHelper, \Magento\Framework\Data\Helper\PostHelper $postHelper)
getPostDataRemove($product)