Skip to content

Commit 15b47d0

Browse files
committed
Instant Search Page updates
2 parents ddc86c8 + f669246 commit 15b47d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1446
-993
lines changed

Block/Cart/Recommend.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ public function __construct(
4343
*/
4444
public function getAllCartItems()
4545
{
46-
$cartItems = array();
46+
$cartItems = [];
4747
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
48-
foreach ( $itemCollection as $item) {
48+
foreach ($itemCollection as $item) {
4949
$cartItems[] = $item->getProductId();
5050
}
5151
return array_unique($cartItems);
5252
}
5353

54-
}
54+
/**
55+
* @return array
56+
*/
57+
public function getAlgoliaRecommendConfiguration()
58+
{
59+
return [
60+
'enabledFBTInCart' => $this->configHelper->isRecommendFrequentlyBroughtTogetherEnabledOnCartPage(),
61+
'enabledRelatedInCart' => $this->configHelper->isRecommendRelatedProductsEnabledOnCartPage(),
62+
'isTrendItemsEnabledInCartPage' => $this->configHelper->isTrendItemsEnabledInShoppingCart()
63+
];
64+
}
65+
}

Block/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public function getConfiguration()
163163
'nbOfCategoriesSuggestions' => $config->getNumberOfCategoriesSuggestions(),
164164
'nbOfQueriesSuggestions' => $config->getNumberOfQueriesSuggestions(),
165165
'isDebugEnabled' => $config->isAutocompleteDebugEnabled(),
166+
'isNavigatorEnabled' => $config->isAutocompleteNavigatorEnabled()
166167
],
167168
'landingPage' => [
168169
'query' => $this->getLandingPageQuery(),
@@ -184,6 +185,9 @@ public function getConfiguration()
184185
'isAddToCartEnabledInFBT' => $config->isAddToCartEnabledInFrequentlyBoughtTogether(),
185186
'isAddToCartEnabledInRelatedProduct' => $config->isAddToCartEnabledInRelatedProducts(),
186187
'isAddToCartEnabledInTrendsItem' => $config->isAddToCartEnabledInTrendsItem(),
188+
'FBTTitle' => __($config->getFBTTitle()),
189+
'relatedProductsTitle' => __($config->getRelatedProductsTitle()),
190+
'trendingItemsTitle' => __($config->getTrendingItemsTitle()),
187191
'addToCartParams' => $addToCartParams,
188192
],
189193
'extensionVersion' => $config->getExtensionVersion(),
@@ -309,6 +313,8 @@ public function getConfiguration()
309313
'searchForFacetValuesPlaceholder' => __('Search for other ...'),
310314
'showMore' => __('Show more products'),
311315
'searchTitle' => __('Search results for'),
316+
'placeholder' => __('Search for products, categories, ...'),
317+
'addToCart' => __('Add to Cart'),
312318
],
313319
];
314320

Block/RecommendProductView.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Algolia\AlgoliaSearch\Block;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
11+
use Magento\Framework\Registry;
12+
use Magento\Framework\View\Element\Template;
13+
use Magento\Framework\View\Element\Template\Context;
14+
15+
class RecommendProductView extends Template
16+
{
17+
/**
18+
* @var Product
19+
*/
20+
protected $product = null;
21+
22+
/**
23+
* Core registry
24+
*
25+
* @var Registry
26+
*/
27+
protected $coreRegistry = null;
28+
29+
/**
30+
* @var ConfigHelper
31+
*/
32+
protected $configHelper;
33+
34+
/**
35+
* @param Context $context
36+
* @param Registry $registry
37+
* @param ConfigHelper $configHelper
38+
* @param array $data
39+
*/
40+
public function __construct(
41+
Context $context,
42+
Registry $registry,
43+
ConfigHelper $configHelper,
44+
array $data = []
45+
) {
46+
$this->coreRegistry = $registry;
47+
$this->configHelper = $configHelper;
48+
parent::__construct($context, $data);
49+
}
50+
51+
/**
52+
* Returns a Product
53+
*
54+
* @return Product
55+
*/
56+
public function getProduct()
57+
{
58+
if (!$this->product) {
59+
$this->product = $this->coreRegistry->registry('product');
60+
}
61+
return $this->product;
62+
}
63+
64+
/**
65+
* @return array
66+
*/
67+
public function getAlgoliaRecommendConfiguration()
68+
{
69+
return [
70+
'enabledFBT' => $this->configHelper->isRecommendFrequentlyBroughtTogetherEnabled(),
71+
'enabledRelated' => $this->configHelper->isRecommendRelatedProductsEnabled(),
72+
'isTrendItemsEnabledInPDP' => $this->configHelper->isTrendItemsEnabledInPDP()
73+
];
74+
}
75+
}

Block/Widget/TrendsItem.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,37 @@
66
use Magento\Framework\View\Element\Template;
77
use Magento\Framework\View\Element\Template\Context;
88
use Magento\Widget\Block\BlockInterface;
9+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
910

1011
class TrendsItem extends Template implements BlockInterface
1112
{
13+
/**
14+
* @var ConfigHelper
15+
*/
16+
protected $configHelper;
17+
1218
protected $_template = 'recommend/widget/trends-item.phtml';
13-
19+
1420
/**
1521
* @param Context $context
22+
* @param ConfigHelper $configHelper
1623
* @param Random $mathRandom
1724
* @param array $data
1825
*/
1926
public function __construct(
2027
Context $context,
28+
ConfigHelper $configHelper,
2129
Random $mathRandom,
2230
array $data = []
2331
) {
2432
$this->mathRandom = $mathRandom;
33+
$this->configHelper = $configHelper;
2534
parent::__construct(
2635
$context,
2736
$data
2837
);
2938
}
30-
39+
3140
/**
3241
* @return string
3342
* @throws \Magento\Framework\Exception\LocalizedException
@@ -36,4 +45,12 @@ public function generateUniqueToken()
3645
{
3746
return $this->mathRandom->getRandomString(5);
3847
}
48+
49+
/**
50+
* @return int
51+
*/
52+
public function isTrendingItemEnabled()
53+
{
54+
return $this->configHelper->isRecommendTrendingItemsEnabled();
55+
}
3956
}

Controller/Adminhtml/Landingpage/Save.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Landingpage;
44

5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
56
use Algolia\AlgoliaSearch\Helper\MerchandisingHelper;
67
use Algolia\AlgoliaSearch\Model\LandingPageFactory;
78
use Magento\Framework\App\Request\DataPersistorInterface;
89
use Magento\Framework\Controller\ResultFactory;
910
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
1113

1214
class Save extends AbstractAction
1315
{
@@ -16,6 +18,16 @@ class Save extends AbstractAction
1618
*/
1719
protected $dataPersistor;
1820

21+
/**
22+
* @var CollectionFactory
23+
*/
24+
protected $customerGroupCollectionFactory;
25+
26+
/**
27+
* @var ConfigHelper
28+
*/
29+
protected $configHelper;
30+
1931
/**
2032
* PHP Constructor
2133
*
@@ -25,7 +37,7 @@ class Save extends AbstractAction
2537
* @param MerchandisingHelper $merchandisingHelper
2638
* @param StoreManagerInterface $storeManager
2739
* @param DataPersistorInterface $dataPersistor
28-
*
40+
* @param CollectionFactory $customerGroupCollectionFactory
2941
* @return Save
3042
*/
3143
public function __construct(
@@ -34,10 +46,13 @@ public function __construct(
3446
LandingPageFactory $landingPageFactory,
3547
MerchandisingHelper $merchandisingHelper,
3648
StoreManagerInterface $storeManager,
37-
DataPersistorInterface $dataPersistor
49+
DataPersistorInterface $dataPersistor,
50+
CollectionFactory $customerGroupCollectionFactory,
51+
ConfigHelper $configHelper
3852
) {
3953
$this->dataPersistor = $dataPersistor;
40-
54+
$this->customerGroupCollectionFactory = $customerGroupCollectionFactory;
55+
$this->configHelper = $configHelper;
4156
parent::__construct(
4257
$context,
4358
$coreRegistry,
@@ -84,6 +99,18 @@ public function execute()
8499

85100
if (isset($data['algolia_configuration']) && $data['algolia_configuration'] != $data['configuration']) {
86101
$data['configuration'] = $data['algolia_configuration'];
102+
if ($this->configHelper->isCustomerGroupsEnabled($data['store_id'])) {
103+
$configuration = json_decode($data['algolia_configuration'], true);
104+
$priceConfig = $configuration['price'.$data['price_key']];
105+
$customerGroups = $this->customerGroupCollectionFactory->create();
106+
$store = $this->storeManager->getStore($data['store_id']);
107+
$baseCurrencyCode = $store->getBaseCurrencyCode();
108+
foreach ($customerGroups as $group) {
109+
$groupId = (int) $group->getData('customer_group_id');
110+
$configuration['price.'.$baseCurrencyCode.'.group_'.$groupId] = $priceConfig;
111+
}
112+
$data['configuration'] = json_encode($configuration);
113+
}
87114
}
88115

89116
$landingPage->setData($data);
@@ -120,7 +147,12 @@ public function execute()
120147
return $resultRedirect->setPath('*/*/');
121148
}
122149

123-
private function manageQueryRules($landingPageId, $data)
150+
/**
151+
* @param $landingPageId
152+
* @param $data
153+
* @return void
154+
*/
155+
protected function manageQueryRules($landingPageId, $data)
124156
{
125157
$positions = json_decode($data['algolia_merchandising_positions'], true);
126158
$stores = [];

Controller/Adminhtml/Reindex/Save.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class Save extends \Magento\Backend\App\Action
2020
public const MAX_SKUS = 10;
2121

2222
/** @var ProductRepositoryInterface */
23-
private $productRepository;
23+
protected $productRepository;
2424

2525
/** @var StoreManagerInterface */
26-
private $storeManager;
26+
protected $storeManager;
2727

2828
/** @var DataHelper */
29-
private $dataHelper;
29+
protected $dataHelper;
3030

3131
/** @var ProductHelper */
32-
private $productHelper;
32+
protected $productHelper;
3333

3434
/**
3535
* @param Context $context
@@ -75,15 +75,17 @@ public function execute()
7575

7676
if (empty($skus)) {
7777
$this->messageManager->addErrorMessage(__('Please, enter at least one SKU.'));
78+
return $resultRedirect;
7879
}
7980

8081
if (count($skus) > self::MAX_SKUS) {
8182
$this->messageManager->addErrorMessage(
8283
__(
83-
'The maximal number of SKU(s) is %1. Could you please remove some SKU(s) to fit into the limit?',
84+
'The maximum number of SKU(s) is %1. Please remove some SKU(s) and try again',
8485
self::MAX_SKUS
8586
)
8687
);
88+
return $resultRedirect;
8789
}
8890

8991
foreach ($skus as $sku) {
@@ -125,15 +127,12 @@ public function execute()
125127
}
126128

127129
/**
128-
* @param \Magento\Catalog\Model\Product $product
129-
* @param array $stores
130-
*
131-
* @throws \Magento\Framework\Exception\LocalizedException
132-
* @throws \Magento\Framework\Exception\NoSuchEntityException
133-
*
130+
* @param $product
131+
* @param $stores
134132
* @return void
133+
* @throws NoSuchEntityException
135134
*/
136-
private function checkAndReindex($product, $stores)
135+
protected function checkAndReindex($product, $stores)
137136
{
138137
$websites = $this->storeManager->getWebsites();
139138
$storeGroup = $this->storeManager->getGroups();

0 commit comments

Comments
 (0)