Skip to content

Commit 2736d76

Browse files
committed
Do not add products in event if category display mode does not show products @samicoman #266
1 parent 1847e37 commit 2736d76

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

DataLayer/Tag/Category/Products.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yireo\GoogleTagManager2\DataLayer\Tag\Category;
44

55
use Magento\Framework\Exception\NoSuchEntityException;
6+
use Magento\Catalog\Model\Category;
67
use Yireo\GoogleTagManager2\Config\Config;
78
use Yireo\GoogleTagManager2\Api\Data\TagInterface;
89
use Yireo\GoogleTagManager2\Util\GetCurrentCategory;
@@ -40,14 +41,19 @@ public function __construct(
4041
*/
4142
public function get(): array
4243
{
44+
$category = $this->getCurrentCategory->get();
45+
if ($category->getDisplayMode() === Category::DM_PAGE) {
46+
return [];
47+
}
48+
4349
$productsData = [];
4450
$i = 1;
4551
foreach ($this->getCurrentCategoryProducts->getProducts() as $product) {
4652
if ($this->config->getMaximumCategoryProducts() > 0 && $i > $this->config->getMaximumCategoryProducts()) {
4753
break;
4854
}
4955

50-
$product->setCategory($this->getCurrentCategory->get());
56+
$product->setCategory($product);
5157
$productData = $this->productDataMapper->mapByProduct($product);
5258
$productData['quantity'] = 1;
5359
$productData['index'] = $i;

0 commit comments

Comments
 (0)