Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/Adapters/ShopifyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,6 @@ private function extractImages(array $imagesData): array
/**
* Transform Shopify variants to BradSearch format.
*
* Variant `imageUrl` is intentionally omitted: the parent product's curated
* `featuredImage` is the merchant-approved hero image, and we don't want
* variant enrichment to swap it for a per-variant photo at search time.
*
* @param array<string> $locales
* @param array<string, mixed> $translations
*/
Expand Down Expand Up @@ -741,6 +737,11 @@ private function transformVariants(
$result['basePriceTaxExcluded'] = $basePrice;
}

$variantImage = $variant['media']['nodes'][0]['image']['url'] ?? null;
if (is_string($variantImage) && $variantImage !== '') {
$result['imageUrl'] = ['small' => $variantImage, 'medium' => $variantImage];
}

if (! empty($locales)) {
$result['attrs'] = $this->transformVariantOptionsWithLocales($options, $locales);
foreach ($locales as $locale) {
Expand Down
25 changes: 18 additions & 7 deletions tests/Adapters/ShopifyAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,8 @@ public function testVariantBasePriceFallsBackToPriceWhenCompareAtMissing(): void
$this->assertEquals('79.95', $variant['basePrice']);
}

public function testVariantsDoNotCarryImageUrl(): void
public function testVariantWithOwnImageCarriesImageUrl(): void
{
// Per merchant feedback: search rows must show the curated featuredImage,
// not whatever variant happens to match. Keeping imageUrl off the variant
// means variant enrichment can't swap the parent's hero image at search time.
$product = $this->makeProduct('gid://shopify/Product/1', 'Snowboard', 'Desc', 'BrandX', 'Sports');
$product['node']['handle'] = 'snowboard';
$product['node']['onlineStoreUrl'] = 'https://shop.example.com/products/snowboard';
Expand All @@ -709,9 +706,19 @@ public function testVariantsDoNotCarryImageUrl(): void
[
'node' => [
'id' => 'gid://shopify/ProductVariant/12345',
'sku' => 'SNO-001',
'sku' => 'SNO-S',
'price' => '79.95',
'selectedOptions' => [],
'media' => ['nodes' => [['image' => ['url' => 'https://cdn.shopify.com/variant-s.jpg', 'width' => 800, 'height' => 800]]]],
],
],
[
'node' => [
'id' => 'gid://shopify/ProductVariant/12346',
'sku' => 'SNO-L',
'price' => '79.95',
'selectedOptions' => [],
'media' => ['nodes' => []],
],
],
],
Expand All @@ -721,8 +728,12 @@ public function testVariantsDoNotCarryImageUrl(): void

$result = $this->adapter->transform($data, []);

$variant = $result['products'][0]['variants'][0];
$this->assertArrayNotHasKey('imageUrl', $variant);
$variants = $result['products'][0]['variants'];
$this->assertEquals(
['small' => 'https://cdn.shopify.com/variant-s.jpg', 'medium' => 'https://cdn.shopify.com/variant-s.jpg'],
$variants[0]['imageUrl']
);
$this->assertArrayNotHasKey('imageUrl', $variants[1]);
$this->assertEquals('https://cdn.shopify.com/product-image.jpg', $result['products'][0]['imageUrl']['small']);
}

Expand Down
Loading