Skip to content

Commit 17ce598

Browse files
authored
Backport hotfix: Add support for products not having a SKU (#47)
* Add support for products not having a SKU * Add test for product support with empty SKU
1 parent 819c447 commit 17ce598

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/BusinessLogic/Domain/PromotionalWidgets/Services/WidgetValidationService.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,15 @@ public function isProductSupported(string $productId): bool
102102

103103
$productSku = $this->productService->getProductsSkuByProductId($productId);
104104

105-
if (!$productSku) {
106-
return false;
107-
}
108-
109-
$excludedProducts = $generalSettings->getExcludedProducts() ?? [];
110-
111-
if (
112-
$excludedProducts &&
113-
in_array($productSku, $excludedProducts, true)
114-
) {
115-
return false;
105+
if ($productSku) {
106+
$excludedProducts = $generalSettings->getExcludedProducts() ?? [];
107+
108+
if (
109+
$excludedProducts &&
110+
in_array($productSku, $excludedProducts, true)
111+
) {
112+
return false;
113+
}
116114
}
117115

118116
$excludedCategories = $generalSettings->getExcludedCategories() ?? [];

tests/BusinessLogic/Domain/PromotionalWidgets/Services/WidgetValidationServiceTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,36 @@ public function testIsProductSupportedSkuExcluded(): void
280280
self::assertFalse($result);
281281
}
282282

283+
/**
284+
* @dataProvider dataProviderIsProductSupportedEmptySku
285+
* @return void
286+
*/
287+
public function testIsProductSupportedEmptySku($sku): void
288+
{
289+
//arrange
290+
$this->mockGeneralSettingsService->saveGeneralSettings(
291+
new GeneralSettings(
292+
true,
293+
null,
294+
null,
295+
null,
296+
null
297+
)
298+
);
299+
$this->mockProductService->setMockProductSku('');
300+
301+
// act
302+
$result = $this->widgetValidationService->isProductSupported($sku);
303+
304+
// assert
305+
self::assertTrue($result);
306+
}
307+
308+
public function dataProviderIsProductSupportedEmptySku(): array
309+
{
310+
return [[''], ['0']];
311+
}
312+
283313
/**
284314
* @return void
285315
*/

0 commit comments

Comments
 (0)