Skip to content

Commit

Permalink
removed grouped image with broken external url from ES data (#225)
Browse files Browse the repository at this point in the history
remove grouped image from ES export instead of setting url null if external url is invalid
  • Loading branch information
julianzimmermann committed Feb 29, 2024
1 parent 1a2cf32 commit ee22bbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public function expandProductPageData(array $productData, ProductPageSearchTrans
foreach ($productImages as $productImage) {
if ($productImage['fk_product_image_set'] === $imageSet->getIdProductImageSet()) {
$key = $imageSet->getName();
$regrouped[$key === null || $key === '' ? static::IMAGE_GROUP_NAME_EMPTY : $key][] = $this->validateProductImageUrls($productImage);
$productImage = $this->validateProductImageUrls($productImage);
if ($productImage === null) {
continue;
}
$regrouped[$key === null || $key === '' ? static::IMAGE_GROUP_NAME_EMPTY : $key][] = $productImage;
}
}
}
Expand All @@ -65,13 +69,13 @@ public function expandProductPageData(array $productData, ProductPageSearchTrans
/**
* @param array $productImage
*
* @return array
* @return array|null
*/
protected function validateProductImageUrls(array $productImage): array
protected function validateProductImageUrls(array $productImage): ?array
{
foreach ($productImage as $key => $data) {
if ($data !== null && str_starts_with($key, static::EXTERNAL_URL_PREFIX)) {
$productImage[$key] = $this->urlValidator->isValid($data) ? $data : null;
if (str_starts_with($key, static::EXTERNAL_URL_PREFIX) && ($data === null || !$this->urlValidator->isValid($data))) {
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ public function testExpandProductPageDataWithUrlValidation(): void
$this->pageSearchTransferMock->expects(static::atLeastOnce())
->method('setGroupedProductImages')
->with(
static::callback(
static fn (array $groupedProductImages): bool => $groupedProductImages[$key][0]['external_url_small'] === null && $groupedProductImages[$key][0]['external_url_large'] === 'https://www.fondof.de'
),
[],
)->willReturn($this->pageSearchTransferMock);

$this->expander->expandProductPageData($productData, $this->pageSearchTransferMock);
Expand Down

0 comments on commit ee22bbf

Please sign in to comment.