Skip to content

Commit 28484f1

Browse files
committed
MAGE-940: code updated as per code review suggestions
1 parent f697fd2 commit 28484f1

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Model/RecommendManagement.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ class RecommendManagement implements RecommendManagementInterface
1414
/**
1515
* @var null|RecommendClient
1616
*/
17-
private ?RecommendClient $client = null;
17+
protected ?RecommendClient $client = null;
1818

1919
/**
2020
* @param ConfigHelper $configHelper
2121
* @param IndexNameFetcher $indexNameFetcher
2222
*/
2323
public function __construct(
24-
private readonly ConfigHelper $configHelper,
25-
private readonly IndexNameFetcher $indexNameFetcher
24+
protected readonly ConfigHelper $configHelper,
25+
protected readonly IndexNameFetcher $indexNameFetcher
2626
){}
2727

2828
/**
2929
* @return RecommendClient
3030
*/
31-
private function getClient(): RecommendClient
31+
protected function getClient(): RecommendClient
3232
{
3333
if ($this->client === null) {
3434
$this->client = RecommendClient::create(
@@ -85,7 +85,7 @@ public function getLookingSimilarRecommendation(string $productId): array
8585
* @return array
8686
* @throws NoSuchEntityException
8787
*/
88-
private function getRecommendations(string $productId, string $model, float|int $threshold = 50): array
88+
protected function getRecommendations(string $productId, string $model, float|int $threshold = 50): array
8989
{
9090
$request['indexName'] = $this->indexNameFetcher->getIndexName('_products');
9191
$request['model'] = $model;

Observer/RecommendSettings.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
class RecommendSettings implements ObserverInterface
1616
{
17+
const QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status';
18+
const STATUS = 'status';
19+
const VISIBILITY = 'visibility';
20+
1721
/**
1822
* @var string
1923
*/
20-
private $productId = '';
24+
protected $productId = '';
2125

2226
/**
2327
* @param ConfigHelper $configHelper
@@ -27,11 +31,11 @@ class RecommendSettings implements ObserverInterface
2731
* @param SearchCriteriaBuilder $searchCriteriaBuilder
2832
*/
2933
public function __construct(
30-
private readonly ConfigHelper $configHelper,
31-
private readonly WriterInterface $configWriter,
32-
private readonly ProductRepositoryInterface $productRepository,
33-
private readonly RecommendManagementInterface $recommendManagement,
34-
private readonly SearchCriteriaBuilder $searchCriteriaBuilder
34+
protected readonly ConfigHelper $configHelper,
35+
protected readonly WriterInterface $configWriter,
36+
protected readonly ProductRepositoryInterface $productRepository,
37+
protected readonly RecommendManagementInterface $recommendManagement,
38+
protected readonly SearchCriteriaBuilder $searchCriteriaBuilder
3539
){}
3640

3741
/**
@@ -119,7 +123,7 @@ protected function validateRelatedProducts(string $changedPath): void
119123
$recommendations = $this->recommendManagement->getRelatedProductsRecommendation($this->getProductId());
120124
if (empty($recommendations['renderingContent'])) {
121125
throw new LocalizedException(__(
122-
"It appears that there is no trained model available for the AppID: %1.",
126+
"It appears that there is no trained model available for Algolia application ID: %1.",
123127
$this->configHelper->getApplicationID()
124128
));
125129
}
@@ -141,7 +145,7 @@ protected function validateTrendingItems(string $changedPath): void
141145
// When no recommendations suggested, most likely trained model is missing
142146
if (empty($recommendations['renderingContent'])) {
143147
throw new LocalizedException(__(
144-
"It appears that there is no trained model available for the AppID: %1.",
148+
"It appears that there is no trained model available for Algolia application ID: %1.",
145149
$this->configHelper->getApplicationID()
146150
));
147151
}
@@ -162,7 +166,7 @@ protected function validateLookingSimilar(string $changedPath): void
162166
$recommendations = $this->recommendManagement->getLookingSimilarRecommendation($this->getProductId());
163167
if (empty($recommendations['renderingContent'])) {
164168
throw new LocalizedException(__(
165-
"It appears that there is no trained model available for the AppID: %1.",
169+
"It appears that there is no trained model available for Algolia application ID: %1.",
166170
$this->configHelper->getApplicationID()
167171
));
168172
}
@@ -175,13 +179,13 @@ protected function validateLookingSimilar(string $changedPath): void
175179
/**
176180
* @return string
177181
*/
178-
private function getProductId(): string
182+
protected function getProductId(): string
179183
{
180184
if ($this->productId === '') {
181185
$searchCriteria = $this->searchCriteriaBuilder
182-
->addFilter('status', 1)
183-
->addFilter('quantity_and_stock_status', 1)
184-
->addFilter('visibility', [2, 3, 4], 'in')
186+
->addFilter(self::STATUS, 1)
187+
->addFilter(self::QUANTITY_AND_STOCK_STATUS, 1)
188+
->addFilter(self::VISIBILITY, [2, 3, 4], 'in')
185189
->setPageSize(10)
186190
->create();
187191
$result = $this->productRepository->getList($searchCriteria);

0 commit comments

Comments
 (0)