Skip to content

Commit 764d80e

Browse files
authored
Merge pull request #56 from integer-net/skip-html-index-if-unnecessary
Skip html index if unnecessary
2 parents 5c698ef + c4bb05b commit 764d80e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

main/src/Model/Bridge/ProductRenderer.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use IntegerNet\Solr\Implementor\Product as ProductInterface;
1515
use IntegerNet\Solr\Implementor\ProductRenderer as ProductRendererInterface;
1616
use IntegerNet\Solr\Indexer\IndexDocument;
17+
use IntegerNet\Solr\Model\Config\FrontendStoresConfig;
1718
use Magento\Framework\App\State as AppState;
1819
use Magento\Framework\View\LayoutInterface;
1920

@@ -27,10 +28,18 @@ class ProductRenderer implements ProductRendererInterface
2728
* @var AppState
2829
*/
2930
private $appState;
31+
/**
32+
* @var FrontendStoresConfig
33+
*/
34+
private $storesConfig;
35+
/**
36+
* @var bool
37+
*/
3038
private $isLayoutLoaded = false;
3139

32-
public function __construct(LayoutInterface\Proxy $layout, AppState $appState)
40+
public function __construct(LayoutInterface\Proxy $layout, AppState $appState, FrontendStoresConfig $storesConfig)
3341
{
42+
$this->storesConfig = $storesConfig;
3443
$this->layout = $layout;
3544
$this->appState = $appState;
3645
}
@@ -65,7 +74,9 @@ public function addResultHtmlToProductData(ProductInterface $product, IndexDocum
6574
// We need direct access to the Magento product
6675
throw new \InvalidArgumentException('Magento 2 product bridge expected, '. get_class($product) .' received.');
6776
}
68-
$this->addAutosuggestItemHtml($product, $productData);
77+
if ($this->storesConfig->byStoreId($product->getStoreId())->getAutosuggestConfig()->isActive()) {
78+
$this->addAutosuggestItemHtml($product, $productData);
79+
}
6980
//TODO if $useHtmlInResult, render product list and grid HTML
7081
}
7182

main/src/Model/Config/FrontendStoresConfig.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public function __construct(StoreManagerInterface $storeManager, ConfigFactory $
2727
parent::__construct($configByStore);
2828
}
2929

30+
public function byStoreId($storeId)
31+
{
32+
return $this[$storeId];
33+
}
3034
}

main/src/etc/mview.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
/**
4-
* Same subscriptions as catalogsearch_fulltext
4+
* Same subscriptions as catalogsearch_fulltext, plus category links
55
*/
66
-->
77
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
@@ -18,6 +18,7 @@
1818
<table name="catalog_product_bundle_selection" entity_column="parent_product_id" />
1919
<table name="catalog_product_super_link" entity_column="product_id" />
2020
<table name="catalog_product_link" entity_column="product_id" />
21+
<table name="catalog_category_product" entity_column="product_id" />
2122
</subscriptions>
2223
</view>
2324
</config>

0 commit comments

Comments
 (0)