Skip to content

Commit

Permalink
Fix issue with large number of identities
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorvansach committed Jan 4, 2019
1 parent 9b85382 commit 1a420e4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
39 changes: 39 additions & 0 deletions Plugin/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*/

namespace Magefan\Catalog\Plugin\Magento\Catalog\Block\Product;

/**
* Class ListProduct
* @package Magefan\Catalog\Plugin\Magento\Catalog\Block\Product
*/
class ListProduct
{
/**
* Max. dentities count
*/
const MAX_COUNT = 400;

/**
* Slice identities.
* @param \Magento\Catalog\Block\Product\ListProduct $subject
* @param array $identities
*/
public function afterGetIdentities(
\Magento\Catalog\Block\Product\ListProduct $subject,
$identities
) {
if (count($identities) > self::MAX_COUNT) {
$identities = array_slice($identities, 0, self::MAX_COUNT);
$category = $subject->getLayer()->getCurrentCategory();
if ($category) {
$identities[] = \Magento\Catalog\Model\Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
}
}

return $identities;
}
}
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"name": "magefan/module-catalog",
"description": "Fixes for magento issues in catalog",
"require": {
"php": "~5.6.5 || >=7.0"
},
"type": "magento2-module",
"version": "1.0.1",
"version": "1.0.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<type name="Magento\Catalog\Model\Template\Filter">
<plugin disabled="false" name="Magefan_Catalog_Plugin_Magento_Catalog_Model_Template_Filter" sortOrder="10" type="Magefan\Catalog\Plugin\Magento\Catalog\Model\Template\Filter"/>
</type>
<type name="Magento\Catalog\Block\Product\ListProduct">
<plugin disabled="false" name="Magefan_Catalog_Plugin_Magento_Catalog_Block_Product_ListProduct" sortOrder="10" type="Magefan\Catalog\Plugin\Magento\Catalog\Block\Product\ListProduct"/>
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magefan_Catalog" setup_version="1.0.1"/>
<module name="Magefan_Catalog" setup_version="1.0.2"/>
</config>

0 comments on commit 1a420e4

Please sign in to comment.