magento 2 - Set limit to the compared productSet product reviews limit and paginationi need to limit the number of products added to compare in magentoMagento Products Compare limitProduct add to compare if product out of stockset custom limit for pagination magento2How to add a delete button/icon for each product in the compare page?How to send compare product list via email in magento 1.9?Custom attribute values Not showing while compare the product in magento2Magento 2 - Compare product Count and Compare product URL Not working?how to get Compared Product collection in magento 2
Best approach to update all entries in a list that is paginated?
How could our ancestors have domesticated a solitary predator?
How much stiffer are 23c tires over 28c?
Why is this plane circling around the Lucknow airport every day?
Do I really need to have a scientific explanation for my premise?
Why would a jet engine that runs at temps excess of 2000°C melt when it crashes?
Word for a person who has no opinion about whether god exists
Is there an equal sign with wider gap?
Adding an additional "order by" column gives me a much worse plan
Make a transparent 448*448 image
Is it possible to have an Abelian group under two different binary operations but the binary operations are not distributive?
Who deserves to be first and second author? PhD student who collected data, research associate who wrote the paper or supervisor?
Set and print content of environment variable in cmd.exe subshell?
Is there an elementary proof that there are infinitely many primes that are *not* completely split in an abelian extension?
What are some noteworthy "mic-drop" moments in math?
Do Bugbears' arms literally get longer when it's their turn?
Reverse string, can I make it faster?
Space in array system equations
Replacing Windows 7 security updates with anti-virus?
Moving plot label
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Should QA ask requirements to developers?
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
What does a stand alone "T" index value do?
magento 2 - Set limit to the compared product
Set product reviews limit and paginationi need to limit the number of products added to compare in magentoMagento Products Compare limitProduct add to compare if product out of stockset custom limit for pagination magento2How to add a delete button/icon for each product in the compare page?How to send compare product list via email in magento 1.9?Custom attribute values Not showing while compare the product in magento2Magento 2 - Compare product Count and Compare product URL Not working?how to get Compared Product collection in magento 2
I need to set limit to the compared product, for example: max_limit 4, But now it is adding Number of products to compare list.
Kindly suggest.
magento2 product compare
add a comment |
I need to set limit to the compared product, for example: max_limit 4, But now it is adding Number of products to compare list.
Kindly suggest.
magento2 product compare
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26
add a comment |
I need to set limit to the compared product, for example: max_limit 4, But now it is adding Number of products to compare list.
Kindly suggest.
magento2 product compare
I need to set limit to the compared product, for example: max_limit 4, But now it is adding Number of products to compare list.
Kindly suggest.
magento2 product compare
magento2 product compare
edited Feb 13 '17 at 8:06
Khoa TruongDinh
21.8k64187
21.8k64187
asked Feb 13 '17 at 7:22
SanjSanj
359
359
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26
add a comment |
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26
add a comment |
2 Answers
2
active
oldest
votes
We can try with Plugin. We use MagentoCatalogHelperProductCompare to get the current compared products.
app/code/Company/Catalog/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogControllerProductCompareAdd">
<plugin name="LimitToCompareProducts"
type="CompanyCatalogModelPluginCompareLimitToCompareProducts"/>
</type>
</config>
app/code/Company/Catalog/Model/Plugin/Compare/LimitToCompareProducts.php
<?php
namespace CompanyCatalogModelPluginCompare;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoCatalogHelperProductCompare;
class LimitToCompareProducts
const LIMIT_TO_COMPARE_PRODUCTS = 3;
/**
* @var MagentoFrameworkMessageManagerInterface
*/
protected $messageManager;
/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;
/** @var Compare */
protected $helper;
/**
* RestrictCustomerEmail constructor.
* @param Compare $helper
* @param RedirectFactory $redirectFactory
* @param ManagerInterface $messageManager
*/
public function __construct(
RedirectFactory $redirectFactory,
Compare $helper,
ManagerInterface $messageManager
)
$this->helper = $helper;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
MagentoCatalogControllerProductCompareAdd $subject,
Closure $proceed
)
$count = $this->helper->getItemCount();
if($count > self::LIMIT_TO_COMPARE_PRODUCTS)
$this->messageManager->addErrorMessage(
'You can add the compared products under 3 item(s)'
);
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setRefererOrBaseUrl();
return $proceed();
1
What aboutAdmin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Ankit Shah
Feb 13 '17 at 8:51
add a comment |
@ankit
What about Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
This does not limit the quantity of items on your compare.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159534%2fmagento-2-set-limit-to-the-compared-product%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
We can try with Plugin. We use MagentoCatalogHelperProductCompare to get the current compared products.
app/code/Company/Catalog/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogControllerProductCompareAdd">
<plugin name="LimitToCompareProducts"
type="CompanyCatalogModelPluginCompareLimitToCompareProducts"/>
</type>
</config>
app/code/Company/Catalog/Model/Plugin/Compare/LimitToCompareProducts.php
<?php
namespace CompanyCatalogModelPluginCompare;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoCatalogHelperProductCompare;
class LimitToCompareProducts
const LIMIT_TO_COMPARE_PRODUCTS = 3;
/**
* @var MagentoFrameworkMessageManagerInterface
*/
protected $messageManager;
/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;
/** @var Compare */
protected $helper;
/**
* RestrictCustomerEmail constructor.
* @param Compare $helper
* @param RedirectFactory $redirectFactory
* @param ManagerInterface $messageManager
*/
public function __construct(
RedirectFactory $redirectFactory,
Compare $helper,
ManagerInterface $messageManager
)
$this->helper = $helper;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
MagentoCatalogControllerProductCompareAdd $subject,
Closure $proceed
)
$count = $this->helper->getItemCount();
if($count > self::LIMIT_TO_COMPARE_PRODUCTS)
$this->messageManager->addErrorMessage(
'You can add the compared products under 3 item(s)'
);
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setRefererOrBaseUrl();
return $proceed();
1
What aboutAdmin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Ankit Shah
Feb 13 '17 at 8:51
add a comment |
We can try with Plugin. We use MagentoCatalogHelperProductCompare to get the current compared products.
app/code/Company/Catalog/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogControllerProductCompareAdd">
<plugin name="LimitToCompareProducts"
type="CompanyCatalogModelPluginCompareLimitToCompareProducts"/>
</type>
</config>
app/code/Company/Catalog/Model/Plugin/Compare/LimitToCompareProducts.php
<?php
namespace CompanyCatalogModelPluginCompare;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoCatalogHelperProductCompare;
class LimitToCompareProducts
const LIMIT_TO_COMPARE_PRODUCTS = 3;
/**
* @var MagentoFrameworkMessageManagerInterface
*/
protected $messageManager;
/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;
/** @var Compare */
protected $helper;
/**
* RestrictCustomerEmail constructor.
* @param Compare $helper
* @param RedirectFactory $redirectFactory
* @param ManagerInterface $messageManager
*/
public function __construct(
RedirectFactory $redirectFactory,
Compare $helper,
ManagerInterface $messageManager
)
$this->helper = $helper;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
MagentoCatalogControllerProductCompareAdd $subject,
Closure $proceed
)
$count = $this->helper->getItemCount();
if($count > self::LIMIT_TO_COMPARE_PRODUCTS)
$this->messageManager->addErrorMessage(
'You can add the compared products under 3 item(s)'
);
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setRefererOrBaseUrl();
return $proceed();
1
What aboutAdmin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Ankit Shah
Feb 13 '17 at 8:51
add a comment |
We can try with Plugin. We use MagentoCatalogHelperProductCompare to get the current compared products.
app/code/Company/Catalog/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogControllerProductCompareAdd">
<plugin name="LimitToCompareProducts"
type="CompanyCatalogModelPluginCompareLimitToCompareProducts"/>
</type>
</config>
app/code/Company/Catalog/Model/Plugin/Compare/LimitToCompareProducts.php
<?php
namespace CompanyCatalogModelPluginCompare;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoCatalogHelperProductCompare;
class LimitToCompareProducts
const LIMIT_TO_COMPARE_PRODUCTS = 3;
/**
* @var MagentoFrameworkMessageManagerInterface
*/
protected $messageManager;
/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;
/** @var Compare */
protected $helper;
/**
* RestrictCustomerEmail constructor.
* @param Compare $helper
* @param RedirectFactory $redirectFactory
* @param ManagerInterface $messageManager
*/
public function __construct(
RedirectFactory $redirectFactory,
Compare $helper,
ManagerInterface $messageManager
)
$this->helper = $helper;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
MagentoCatalogControllerProductCompareAdd $subject,
Closure $proceed
)
$count = $this->helper->getItemCount();
if($count > self::LIMIT_TO_COMPARE_PRODUCTS)
$this->messageManager->addErrorMessage(
'You can add the compared products under 3 item(s)'
);
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setRefererOrBaseUrl();
return $proceed();
We can try with Plugin. We use MagentoCatalogHelperProductCompare to get the current compared products.
app/code/Company/Catalog/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogControllerProductCompareAdd">
<plugin name="LimitToCompareProducts"
type="CompanyCatalogModelPluginCompareLimitToCompareProducts"/>
</type>
</config>
app/code/Company/Catalog/Model/Plugin/Compare/LimitToCompareProducts.php
<?php
namespace CompanyCatalogModelPluginCompare;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoCatalogHelperProductCompare;
class LimitToCompareProducts
const LIMIT_TO_COMPARE_PRODUCTS = 3;
/**
* @var MagentoFrameworkMessageManagerInterface
*/
protected $messageManager;
/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;
/** @var Compare */
protected $helper;
/**
* RestrictCustomerEmail constructor.
* @param Compare $helper
* @param RedirectFactory $redirectFactory
* @param ManagerInterface $messageManager
*/
public function __construct(
RedirectFactory $redirectFactory,
Compare $helper,
ManagerInterface $messageManager
)
$this->helper = $helper;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
MagentoCatalogControllerProductCompareAdd $subject,
Closure $proceed
)
$count = $this->helper->getItemCount();
if($count > self::LIMIT_TO_COMPARE_PRODUCTS)
$this->messageManager->addErrorMessage(
'You can add the compared products under 3 item(s)'
);
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setRefererOrBaseUrl();
return $proceed();
edited Feb 13 '17 at 8:33
answered Feb 13 '17 at 8:05
Khoa TruongDinhKhoa TruongDinh
21.8k64187
21.8k64187
1
What aboutAdmin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Ankit Shah
Feb 13 '17 at 8:51
add a comment |
1
What aboutAdmin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Ankit Shah
Feb 13 '17 at 8:51
1
1
What about
Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?– Ankit Shah
Feb 13 '17 at 8:51
What about
Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?– Ankit Shah
Feb 13 '17 at 8:51
add a comment |
@ankit
What about Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
This does not limit the quantity of items on your compare.
add a comment |
@ankit
What about Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
This does not limit the quantity of items on your compare.
add a comment |
@ankit
What about Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
This does not limit the quantity of items on your compare.
@ankit
What about Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
This does not limit the quantity of items on your compare.
answered 9 hours ago
user3653773user3653773
2613
2613
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159534%2fmagento-2-set-limit-to-the-compared-product%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
developersushant.wordpress.com/2016/01/25/…
– Ravi Thanki
Feb 13 '17 at 7:24
Thanks, I went through this link previously but this code is in magento 1.9 as i need in magento 2 version
– Sanj
Feb 13 '17 at 7:28
have you check set limit from here, Admin -> Stores -> Configuration -> Catalog -> Catalog -> Recently Viewed/Compared Products -> Default Recently Compared Products Count?
– Rakesh Jesadiya
Feb 13 '17 at 9:26