Skip to content

Commit 8e77395

Browse files
committed
MAGE-1112: add price attribute notice
1 parent 361043f commit 8e77395

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

Helper/ConfigHelper.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,17 +1068,42 @@ public function getAttributesToRetrieve($groupId)
10681068
return ['attributesToRetrieve' => $attributes];
10691069
}
10701070

1071+
/**
1072+
* @param $attributes
1073+
* @param $attributeName
1074+
* @return bool
1075+
*/
1076+
public function isAttributeInList($attributes, $attributeName): bool
1077+
{
1078+
foreach ($attributes as $attr) {
1079+
if ($attr['attribute'] === $attributeName) {
1080+
return true;
1081+
}
1082+
}
1083+
1084+
return false;
1085+
}
1086+
10711087
/**
10721088
* @param $storeId
1073-
* @return array
1089+
* @return mixed
10741090
*/
1075-
public function getProductAdditionalAttributes($storeId = null)
1091+
public function getProductAttributesList($storeId = null)
10761092
{
1077-
$attributes = $this->serializer->unserialize($this->configInterface->getValue(
1093+
return $this->serializer->unserialize($this->configInterface->getValue(
10781094
self::PRODUCT_ATTRIBUTES,
10791095
ScopeInterface::SCOPE_STORE,
10801096
$storeId
10811097
));
1098+
}
1099+
1100+
/**
1101+
* @param $storeId
1102+
* @return array
1103+
*/
1104+
public function getProductAdditionalAttributes($storeId = null)
1105+
{
1106+
$attributes = $this->getProductAttributesList($storeId);
10821107

10831108
$facets = $this->serializer->unserialize($this->configInterface->getValue(
10841109
self::FACETS,

Helper/Configuration/NoticeHelper.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
2323
'getRecommendNotice',
2424
'getCookieConfigurationNotice',
2525
'getMultiApplicationIDsNotice',
26+
'getPriceIndexingNotice',
2627
];
2728

2829
/** @var array[] */
@@ -189,8 +190,8 @@ protected function getClickAnalyticsNotice()
189190
];
190191
}
191192

192-
protected function getCookieConfigurationNotice()
193-
{
193+
protected function getCookieConfigurationNotice()
194+
{
194195
$noticeContent = '';
195196
$selector = '';
196197
$method = 'after';
@@ -363,4 +364,32 @@ protected function getMultiApplicationIDsNotice(): void
363364
'message' => $this->formatNotice($noticeTitle, $noticeContent),
364365
];
365366
}
367+
368+
369+
/**
370+
* This notice serves as a warning when user removes the price attribute from the attributes list but it's still present either in the sortings or in the facets
371+
* @return void
372+
*/
373+
protected function getPriceIndexingNotice(): void
374+
{
375+
$attributesToIndex = $this->configHelper->getProductAdditionalAttributes();
376+
$attributesList = $this->configHelper->getProductAttributesList();
377+
378+
// we want to display the warning only if price is not present in the attribute list but is present somewhere else
379+
if (!($this->configHelper->isAttributeInList($attributesToIndex, 'price')
380+
&& !$this->configHelper->isAttributeInList($attributesList, 'price'))
381+
) {
382+
return;
383+
}
384+
385+
$noticeTitle = 'Price attribute indexing';
386+
$noticeContent = '<p>Price attribute has been removed from the product attributes list but is still present in the facets, sortings or custom rankings lists.</p>
387+
<p>If you want to remove prices from the product records, you need to remove them from those lists as well.</p>';
388+
389+
$this->notices[] = [
390+
'selector' => '.entry-edit',
391+
'method' => 'before',
392+
'message' => $this->formatNotice($noticeTitle, $noticeContent),
393+
];
394+
}
366395
}

Service/Product/RecordBuilder.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,7 @@ protected function addAttribute($attribute, $defaultData, $customData, $addition
190190
*/
191191
public function isAttributeEnabled($additionalAttributes, $attributeName): bool
192192
{
193-
foreach ($additionalAttributes as $attr) {
194-
if ($attr['attribute'] === $attributeName) {
195-
return true;
196-
}
197-
}
198-
199-
return false;
193+
return $this->configHelper->isAttributeInList($additionalAttributes, $attributeName);
200194
}
201195

202196
/**
@@ -205,7 +199,7 @@ public function isAttributeEnabled($additionalAttributes, $attributeName): bool
205199
*/
206200
protected function isPriceIndexingEnabled(array $additionalAttributes): bool
207201
{
208-
return $this->isAttributeEnabled($additionalAttributes, 'price');
202+
return $this->configHelper->isAttributeInList($additionalAttributes, 'price');
209203
}
210204

211205
/**

0 commit comments

Comments
 (0)