Skip to content

Commit fa1adc0

Browse files
committed
Merge branch 'release/3.15.0-beta' into epic/MAGE-997
2 parents 5745e6b + 85ca71c commit fa1adc0

File tree

15 files changed

+365
-21
lines changed

15 files changed

+365
-21
lines changed

Api/RecommendManagementInterface.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Api;
4+
5+
interface RecommendManagementInterface
6+
{
7+
/**
8+
* @param string $productId
9+
* @return array
10+
*/
11+
public function getBoughtTogetherRecommendation(string $productId): array;
12+
13+
/**
14+
* @param string $productId
15+
* @return array
16+
*/
17+
public function getRelatedProductsRecommendation(string $productId): array;
18+
19+
/**
20+
* @return array
21+
*/
22+
public function getTrendingItemsRecommendation(): array;
23+
24+
/**
25+
* @param string $productId
26+
* @return array
27+
*/
28+
public function getLookingSimilarRecommendation(string $productId): array;
29+
}

Block/Algolia.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1111
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1212
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
13+
use Algolia\AlgoliaSearch\Model\LandingPage as LandingPageModel;
1314
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
1415
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
1516
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
@@ -215,7 +216,7 @@ protected function getAddToCartUrl($additional = []): string
215216
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
216217
}
217218

218-
protected function getCurrentLandingPage(): LandingPage|null|false
219+
protected function getCurrentLandingPage(): LandingPageModel|null|false
219220
{
220221
$landingPageId = $this->getRequest()->getParam('landing_page_id');
221222
if (!$landingPageId) {

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# CHANGE LOG
22

3+
## 3.14.2
4+
5+
### Updates
6+
- Trained model check before enabling recommend
7+
38
## 3.14.1
49

510
### Updates
611
- Token clean up on session expiration
712

813
### Bug Fixes
914
- Query string append issue addressed
10-
- Address base table not found in integration tests with CLI command classes issue addressed
15+
- Fixed issue with "base table not found" in integration tests due to new CLI command classes
16+
- Removed a warning during indexing of entities with no `created_at` attribute
17+
- Fixed incorrect Recommend paths resulting from earlier JS asset reorg
1118
- README.md updated
1219

13-
1420
## 3.14.0
1521

1622
GA release

Helper/ConfigHelper.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,28 @@ class ConfigHelper
120120
public const EXTRA_SETTINGS_ADDITIONAL_SECTIONS =
121121
'algoliasearch_extra_settings/extra_settings/additional_sections_extra_settings';
122122
public const MAGENTO_DEFAULT_CACHE_TIME = 'system/full_page_cache/ttl';
123-
protected const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled';
124-
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled';
125-
protected const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled_in_cart_page';
126-
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled_in_cart_page';
123+
public const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled';
124+
public const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled';
125+
public const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled_in_cart_page';
126+
public const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled_in_cart_page';
127127
protected const NUM_OF_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_PRODUCTS = 'algoliasearch_recommend/recommend/frequently_bought_together/num_of_frequently_bought_together_products';
128128
protected const NUM_OF_RECOMMEND_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/related_product/num_of_related_products';
129129
protected const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/related_product/is_remove_core_related_products_block';
130130
protected const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/frequently_bought_together/is_remove_core_upsell_products_block';
131-
protected const IS_RECOMMEND_TRENDING_ITEMS_ENABLED = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled';
131+
public const IS_RECOMMEND_TRENDING_ITEMS_ENABLED = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled';
132132
protected const IS_RECOMMEND_LOOKING_SIMILAR_ENABLED = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled';
133133
protected const NUM_OF_LOOKING_SIMILAR = 'algoliasearch_recommend/recommend/looking_similar/num_of_products';
134134
protected const NUM_OF_TRENDING_ITEMS = 'algoliasearch_recommend/recommend/trends_item/num_of_trending_items';
135135
protected const TREND_ITEMS_FACET_NAME = 'algoliasearch_recommend/recommend/trends_item/facet_name';
136136
protected const TREND_ITEMS_FACET_VALUE = 'algoliasearch_recommend/recommend/trends_item/facet_value';
137-
protected const IS_TREND_ITEMS_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_pdp';
138-
protected const IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_cart_page';
137+
public const IS_TREND_ITEMS_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_pdp';
138+
public const IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_cart_page';
139139
protected const IS_ADDTOCART_ENABLED_IN_FREQUENTLY_BOUGHT_TOGETHER = 'algoliasearch_recommend/recommend/frequently_bought_together/is_addtocart_enabled';
140140
protected const IS_ADDTOCART_ENABLED_IN_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/related_product/is_addtocart_enabled';
141141
protected const IS_ADDTOCART_ENABLED_IN_TRENDS_ITEM = 'algoliasearch_recommend/recommend/trends_item/is_addtocart_enabled';
142142
protected const IS_ADDTOCART_ENABLED_IN_LOOKING_SIMILAR = 'algoliasearch_recommend/recommend/looking_similar/is_addtocart_enabled';
143-
protected const IS_LOOKING_SIMILAR_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_pdp';
144-
protected const IS_LOOKING_SIMILAR_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_cart_page';
143+
public const IS_LOOKING_SIMILAR_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_pdp';
144+
public const IS_LOOKING_SIMILAR_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_cart_page';
145145
protected const LOOKING_SIMILAR_TITLE = 'algoliasearch_recommend/recommend/looking_similar/title';
146146
public const LEGACY_USE_VIRTUAL_REPLICA_ENABLED = 'algoliasearch_instant/instant/use_virtual_replica';
147147
protected const AUTOCOMPLETE_KEYBORAD_NAVIAGATION = 'algoliasearch_autocomplete/autocomplete/navigator';

Helper/LandingPageHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
parent::__construct($context);
6060
}
6161

62-
public function getLandingPage($pageId)
62+
public function getLandingPage($pageId): LandingPage|null|false
6363
{
6464
if ($pageId !== null && $pageId !== $this->landingPage->getId()) {
6565
$this->landingPage->setStoreId($this->storeManager->getStore()->getId());

Model/RecommendManagement.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Algolia\AlgoliaSearch\Model;
5+
6+
use Algolia\AlgoliaSearch\Api\RecommendClient;
7+
use Algolia\AlgoliaSearch\Api\RecommendManagementInterface;
8+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
9+
use Algolia\AlgoliaSearch\Service\IndexNameFetcher;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
class RecommendManagement implements RecommendManagementInterface
13+
{
14+
/**
15+
* @var null|RecommendClient
16+
*/
17+
protected ?RecommendClient $client = null;
18+
19+
/**
20+
* @param ConfigHelper $configHelper
21+
* @param IndexNameFetcher $indexNameFetcher
22+
*/
23+
public function __construct(
24+
protected readonly ConfigHelper $configHelper,
25+
protected readonly IndexNameFetcher $indexNameFetcher
26+
){}
27+
28+
/**
29+
* @return RecommendClient
30+
*/
31+
protected function getClient(): RecommendClient
32+
{
33+
if ($this->client === null) {
34+
$this->client = RecommendClient::create(
35+
$this->configHelper->getApplicationID(),
36+
$this->configHelper->getAPIKey()
37+
);
38+
}
39+
return $this->client;
40+
}
41+
42+
/**
43+
* @param string $productId
44+
* @return array
45+
* @throws NoSuchEntityException
46+
*/
47+
public function getBoughtTogetherRecommendation(string $productId): array
48+
{
49+
return $this->getRecommendations($productId, 'bought-together');
50+
}
51+
52+
/**
53+
* @param string $productId
54+
* @return array
55+
* @throws NoSuchEntityException
56+
*/
57+
public function getRelatedProductsRecommendation(string $productId): array
58+
{
59+
return $this->getRecommendations($productId, 'related-products');
60+
}
61+
62+
/**
63+
* @return array
64+
* @throws NoSuchEntityException
65+
*/
66+
public function getTrendingItemsRecommendation(): array
67+
{
68+
return $this->getRecommendations('', 'trending-items');
69+
}
70+
71+
/**
72+
* @param string $productId
73+
* @return array
74+
* @throws NoSuchEntityException
75+
*/
76+
public function getLookingSimilarRecommendation(string $productId): array
77+
{
78+
return $this->getRecommendations($productId, 'bought-together');
79+
}
80+
81+
/**
82+
* @param string $productId
83+
* @param string $model
84+
* @param float|int $threshold
85+
* @return array
86+
* @throws NoSuchEntityException
87+
*/
88+
protected function getRecommendations(string $productId, string $model, float|int $threshold = 50): array
89+
{
90+
$request['indexName'] = $this->indexNameFetcher->getIndexName('_products');
91+
$request['model'] = $model;
92+
$request['threshold'] = $threshold;
93+
if (!empty($productId)) {
94+
$request['objectID'] = $productId;
95+
}
96+
97+
$client = $this->getClient();
98+
$recommendations = $client->getRecommendations(
99+
[
100+
'requests' => [
101+
$request
102+
],
103+
],
104+
);
105+
106+
return $recommendations['results'][0] ?? [];
107+
}
108+
}

Model/Observer.php renamed to Observer/AddAlgoliaAssetsObserver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Algolia\AlgoliaSearch\Model;
3+
namespace Algolia\AlgoliaSearch\Observer;
44

55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
66
use Magento\Framework\Event\ObserverInterface;
@@ -11,8 +11,9 @@
1111

1212
/**
1313
* Algolia search observer model
14+
* @todo Add AlgoliaCredentialsManager to this class once it's available
1415
*/
15-
class Observer implements ObserverInterface
16+
class AddAlgoliaAssetsObserver implements ObserverInterface
1617
{
1718
protected $config;
1819
protected $registry;

0 commit comments

Comments
 (0)