-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4149 from magento-honey-badgers/hb-graphql-pr-2.3.2
[honey] MC-15941, MC-15882
- Loading branch information
Showing
8 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...odel/Resolver/Products/DataProvider/Product/CollectionProcessor/MediaGalleryProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Catalog\Model\Product\Media\Config as MediaConfig; | ||
|
||
/** | ||
* Add attributes required for every GraphQL product resolution process. | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
class MediaGalleryProcessor implements CollectionProcessorInterface | ||
{ | ||
/** | ||
* @var MediaConfig | ||
*/ | ||
private $mediaConfig; | ||
|
||
/** | ||
* Add media gallery attributes to collection | ||
* | ||
* @param MediaConfig $mediaConfig | ||
*/ | ||
public function __construct(MediaConfig $mediaConfig) | ||
{ | ||
$this->mediaConfig = $mediaConfig; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function process( | ||
Collection $collection, | ||
SearchCriteriaInterface $searchCriteria, | ||
array $attributeNames | ||
): Collection { | ||
if (in_array('media_gallery_entries', $attributeNames)) { | ||
$mediaAttributes = $this->mediaConfig->getMediaAttributeCodes(); | ||
foreach ($mediaAttributes as $mediaAttribute) { | ||
if (!in_array($mediaAttribute, $attributeNames)) { | ||
$collection->addAttributeToSelect($mediaAttribute); | ||
} | ||
} | ||
$collection->addMediaGalleryData(); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_multiple_images.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
require __DIR__ . '/product_image.php'; | ||
require __DIR__ . '/product_simple.php'; | ||
|
||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
$product = $productRepository->get('simple'); | ||
|
||
/** @var $product \Magento\Catalog\Model\Product */ | ||
$product->setStoreId(0) | ||
->setImage('/m/a/magento_image.jpg') | ||
->setSmallImage('/m/a/magento_image.jpg') | ||
->setThumbnail('/m/a/magento_thumbnail.jpg') | ||
->setSwatchImage('/m/a/magento_thumbnail.jpg') | ||
->setData('media_gallery', ['images' => [ | ||
[ | ||
'file' => '/m/a/magento_image.jpg', | ||
'position' => 1, | ||
'label' => 'Image Alt Text', | ||
'disabled' => 0, | ||
'media_type' => 'image' | ||
], | ||
[ | ||
'file' => '/m/a/magento_thumbnail.jpg', | ||
'position' => 2, | ||
'label' => 'Thumbnail Image', | ||
'disabled' => 0, | ||
'media_type' => 'image' | ||
], | ||
]]) | ||
->setCanSaveCustomOptions(true) | ||
->save(); |
7 changes: 7 additions & 0 deletions
7
...ts/integration/testsuite/Magento/Catalog/_files/product_with_multiple_images_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
require __DIR__ . '/product_with_image_rollback.php'; |