Override the ListCompare block.
Create Vendor/Module/etc/di.xml on your custom module
1 2 3 4 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Block\Product\Compare\ListCompare" type="Vendor\Module\Block\Product\Compare\ListCompare" /> </config> |
Create Vendor/Module/Block/Product/Compare/ListCompare.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<?php namespace Vendor\Module\Block\Product\Compare; class ListCompare extends \Magento\Catalog\Block\Product\Compare\ListCompare { public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory $itemCollectionFactory, \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, \Magento\Customer\Model\Visitor $customerVisitor, \Magento\Framework\App\Http\Context $httpContext, \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer, \Magento\Framework\ObjectManagerInterface $objectManager, array $data = [] ) { $this->objectManager = $objectManager; parent::__construct($context,$urlEncoder,$itemCollectionFactory,$catalogProductVisibility,$customerVisitor,$httpContext,$currentCustomer,$data); } /** * Retrieve Product Compare items collection * * @return \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection */ public function getItems() { if ($this->_items === null) { $this->_compareProduct->setAllowUsedFlat(false); $this->_items = $this->_itemCollectionFactory->create(); $this->_items->useProductItem(true)->setStoreId($this->_storeManager->getStore()->getId()); if ($this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH)) { $this->_items->setCustomerId($this->currentCustomer->getCustomerId()); } elseif ($this->_customerId) { $this->_items->setCustomerId($this->_customerId); } else { /****** Custom Code ******/ $sessionManager = $this->objectManager->create('\Magento\Framework\Session\SessionManagerInterface'); $visitor = $sessionManager->getVisitorData(); if(!$this->_customerVisitor->getId() && isset($visitor['visitor_id'])){ $visitorid = $visitor['visitor_id']; }else{ $visitorid = $this->_customerVisitor->getId(); } /****** Custom Code ******/ $this->_items->setVisitorId($visitorid); } $this->_items->addAttributeToSelect( $this->_catalogConfig->getProductAttributes() )->loadComparableAttributes()->addMinimalPrice()->addTaxPercents()->setVisibility( $this->_catalogProductVisibility->getVisibleInSiteIds() ); } return $this->_items; } } |
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62837de608a01347930929/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...