File tree Expand file tree Collapse file tree 8 files changed +143
-2
lines changed Expand file tree Collapse file tree 8 files changed +143
-2
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ public function getConfiguration()
222
222
'enabledRelated ' => $ config ->isRecommendRelatedProductsEnabled (),
223
223
'enabledFBTInCart ' => $ config ->isRecommendFrequentlyBroughtTogetherEnabledOnCartPage (),
224
224
'enabledRelatedInCart ' => $ config ->isRecommendRelatedProductsEnabledOnCartPage (),
225
+ 'enabledLookingSimilar ' => $ config ->isRecommendLookingSimilarEnabled (),
225
226
'limitFBTProducts ' => $ config ->getNumberOfFrequentlyBoughtTogetherProducts (),
226
227
'limitRelatedProducts ' => $ config ->getNumberOfRelatedProducts (),
227
228
'limitTrendingItems ' => $ config ->getNumberOfTrendingItems (),
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Block \Widget ;
4
+
5
+ use Magento \Framework \Math \Random ;
6
+ use Magento \Framework \View \Element \Template ;
7
+ use Magento \Framework \View \Element \Template \Context ;
8
+ use Magento \Widget \Block \BlockInterface ;
9
+ use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
10
+
11
+ class LookingSimilar extends Template implements BlockInterface
12
+ {
13
+ /**
14
+ * @var ConfigHelper
15
+ */
16
+ protected $ configHelper ;
17
+
18
+ protected $ _template = 'recommend/widget/looking-similar.phtml ' ;
19
+
20
+ /**
21
+ * @param Context $context
22
+ * @param ConfigHelper $configHelper
23
+ * @param Random $mathRandom
24
+ * @param array $data
25
+ */
26
+ public function __construct (
27
+ Context $ context ,
28
+ ConfigHelper $ configHelper ,
29
+ Random $ mathRandom ,
30
+ array $ data = []
31
+ ) {
32
+ $ this ->mathRandom = $ mathRandom ;
33
+ $ this ->configHelper = $ configHelper ;
34
+ parent ::__construct (
35
+ $ context ,
36
+ $ data
37
+ );
38
+ }
39
+
40
+ /**
41
+ * @return string
42
+ * @throws \Magento\Framework\Exception\LocalizedException
43
+ */
44
+ public function generateUniqueToken ()
45
+ {
46
+ return $ this ->mathRandom ->getRandomString (5 );
47
+ }
48
+
49
+ /**
50
+ * @return int
51
+ */
52
+ public function isLookingSimilarEnabled ()
53
+ {
54
+ return $ this ->configHelper ->isRecommendLookingSimilarEnabled ();
55
+ }
56
+ }
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ class ConfigHelper
127
127
protected const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/related_product/is_remove_core_related_products_block ' ;
128
128
protected const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/frequently_bought_together/is_remove_core_upsell_products_block ' ;
129
129
protected const IS_RECOMMEND_TRENDING_ITEMS_ENABLED = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled ' ;
130
+ protected const IS_RECOMMEND_LOOKING_SIMILAR_ENABLED = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled ' ;
130
131
protected const NUM_OF_LOOKING_SIMILAR = 'algoliasearch_recommend/recommend/looking_similar/num_of_products ' ;
131
132
protected const NUM_OF_TRENDING_ITEMS = 'algoliasearch_recommend/recommend/trends_item/num_of_trending_items ' ;
132
133
protected const TREND_ITEMS_FACET_NAME = 'algoliasearch_recommend/recommend/trends_item/facet_name ' ;
@@ -851,6 +852,21 @@ public function getTrendingItemsFacetValue($storeId = null)
851
852
);
852
853
}
853
854
855
+ /**
856
+ * Determines whether Looking Similar enabled (for widgets))
857
+ *
858
+ * @param $storeId
859
+ * @return int
860
+ */
861
+ public function isRecommendLookingSimilarEnabled ($ storeId = null )
862
+ {
863
+ return (int )$ this ->configInterface ->getValue (
864
+ self ::IS_RECOMMEND_LOOKING_SIMILAR_ENABLED ,
865
+ ScopeInterface::SCOPE_STORE ,
866
+ $ storeId
867
+ );
868
+ }
869
+
854
870
/**
855
871
* Determines whether Looking Similar enabled on PDP
856
872
*
Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ public function getAlgoliaRecommendConfiguration()
67
67
return [
68
68
'enabledFBT ' => $ this ->configHelper ->isRecommendFrequentlyBroughtTogetherEnabled (),
69
69
'enabledRelated ' => $ this ->configHelper ->isRecommendRelatedProductsEnabled (),
70
- 'isTrendItemsEnabledInPDP ' => $ this ->configHelper ->isTrendItemsEnabledInPDP ()
70
+ 'isTrendItemsEnabledInPDP ' => $ this ->configHelper ->isTrendItemsEnabledInPDP (),
71
+ 'isLookingSimilarEnabledInPDP ' => $ this ->configHelper ->isLookingSimilarEnabledOnPDP ()
71
72
];
72
73
}
73
74
}
Original file line number Diff line number Diff line change 19
19
</parameter >
20
20
</parameters >
21
21
</widget >
22
+ <widget class =" Algolia\AlgoliaSearch\Block\Widget\LookingSimilar" id =" algoliasearch_looking_similar_item" >
23
+ <label >Algolia Looking Similar Items</label >
24
+ <description >You can allow Algolia Looking Similar items to appear anywhere you want</description >
25
+ <parameters >
26
+ <parameter name =" numOfLookingSimilarItem" sort_order =" 10" visible =" true" xsi : type =" text" >
27
+ <label >Number Of Looking Similar Items</label >
28
+ <description >How many products do you want to display in the Looking Similar Items?.</description >
29
+ <value >6</value >
30
+ </parameter >
31
+ </parameters >
32
+ </widget >
22
33
</widgets >
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ $recommendConfig = $viewModel->getAlgoliaRecommendConfiguration();
12
12
if (!empty ($ recommendConfig ['enabledFBT ' ])
13
13
|| !empty ($ recommendConfig ['enabledRelated ' ])
14
14
|| !empty ($ recommendConfig ['isTrendItemsEnabledInPDP ' ])
15
- || !empty ($ recommendConfig ['isLookingSimilarEnabledOnPDP ' ])):
15
+ || !empty ($ recommendConfig ['isLookingSimilarEnabledInPDP ' ])):
16
16
$ product = $ viewModel ->getProduct (); ?>
17
17
<div id="frequentlyBoughtTogether" class="recommend-component"></div>
18
18
<div id="relatedProducts" class="recommend-component"></div>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /** @var \Algolia\AlgoliaSearch\Block\Widget\LookingSimilar $block */
3
+ $ isEnabled = $ block ->isLookingSimilarEnabled ();
4
+ if ($ isEnabled ):
5
+ $ lsContainer = 'lsItems ' . $ block ->generateUniqueToken (); ?>
6
+ <div id="<?= $ lsContainer ?> " class="lsItem recommend-component"></div>
7
+ <script type="text/x-magento-init">
8
+ {
9
+ "*": {
10
+ "Algolia_AlgoliaSearch/recommend" : {
11
+ "recommendLSContainer" : "<?= $ lsContainer ?> ",
12
+ "numOfLookingSimilarItem" : "<?= $ block ->getData ('numOfLookingSimilarItem ' ) ?> ",
13
+ }
14
+ }
15
+ }
16
+ </script>
17
+ <script type="text/x-magento-init">
18
+ {
19
+ "[data-role=tocart-form]": {
20
+ "catalogAddToCart": {}
21
+ }
22
+ }
23
+ </script>
24
+ <?php endif ; ?>
Original file line number Diff line number Diff line change @@ -197,6 +197,38 @@ define([
197
197
) ;
198
198
}
199
199
} ) ;
200
+ } else if (
201
+ algoliaConfig . recommend . enabledLookingSimilar &&
202
+ typeof config . recommendLSContainer !== 'undefined'
203
+ ) {
204
+ let containerValue = '#' + config . recommendLSContainer ;
205
+ recommendJs . lookingSimilar ( {
206
+ container : containerValue ,
207
+ recommendClient,
208
+ indexName,
209
+ maxRecommendations : config . numOfLookingSimilarItem
210
+ ? parseInt ( config . numOfLookingSimilarItem )
211
+ : algoliaConfig . recommend . limitLookingSimilar ,
212
+ transformItems : function ( items ) {
213
+ return items . map ( ( item , index ) => ( {
214
+ ...item ,
215
+ position : index + 1 ,
216
+ } ) ) ;
217
+ } ,
218
+ headerComponent ( { html} ) {
219
+ return recommendProductsHtml . getHeaderHtml (
220
+ html ,
221
+ algoliaConfig . recommend . lookingSimilarTitle
222
+ ) ;
223
+ } ,
224
+ itemComponent ( { item, html} ) {
225
+ return recommendProductsHtml . getItemHtml (
226
+ item ,
227
+ html ,
228
+ algoliaConfig . recommend . isAddToCartEnabledInLookingSimilar
229
+ ) ;
230
+ } ,
231
+ } ) ;
200
232
}
201
233
} ) ;
202
234
} ;
You can’t perform that action at this time.
0 commit comments