From e0376a8c7607948b925ddbaa5851a3a1485339b3 Mon Sep 17 00:00:00 2001 From: Ariel Ashri Date: Tue, 2 Jul 2024 17:29:56 +0300 Subject: [PATCH 1/2] CLOUDINARY-493 - Add the media gallery params fields to Magento's graphql --- Helper/ProductGalleryHelper.php | 2 +- Model/Api/ProductGalleryManagement.php | 10 +++++++++- etc/schema.graphqls | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Helper/ProductGalleryHelper.php b/Helper/ProductGalleryHelper.php index 934a06d..66d5209 100644 --- a/Helper/ProductGalleryHelper.php +++ b/Helper/ProductGalleryHelper.php @@ -60,7 +60,7 @@ public function __construct( * @method getCloudinaryPGOptions * @param bool $refresh Refresh options * @param bool $ignoreDisabled Get te options even if the module or the product gallery are disabled - * @return array + * @return array|null */ public function getCloudinaryPGOptions($refresh = false, $ignoreDisabled = false) { diff --git a/Model/Api/ProductGalleryManagement.php b/Model/Api/ProductGalleryManagement.php index 9b1c195..7207bfd 100644 --- a/Model/Api/ProductGalleryManagement.php +++ b/Model/Api/ProductGalleryManagement.php @@ -10,6 +10,7 @@ use Cloudinary\Cloudinary\Model\ProductGalleryApiQueueFactory; use Cloudinary\Cloudinary\Model\ProductImageFinder; use Cloudinary\Cloudinary\Model\TransformationFactory; +use Cloudinary\Cloudinary\Helper\ProductGalleryHelper; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Model\Product\Gallery\Processor; use Magento\Catalog\Model\Product\Media\Config as ProductMediaConfig; @@ -161,6 +162,8 @@ class ProductGalleryManagement implements \Cloudinary\Cloudinary\Api\ProductGall */ private $resourceConnection; + private $productGalleryHelper; + /** * @method __construct * @param ConfigurationInterface $configuration @@ -208,7 +211,8 @@ public function __construct( MediaLibraryMapFactory $mediaLibraryMapFactory, ProductGalleryApiQueueFactory $productGalleryApiQueueFactory, AppEmulation $appEmulation, - ResourceConnection $resourceConnection + ResourceConnection $resourceConnection, + ProductGalleryHelper $productGalleryHelper ) { $this->configuration = $configuration; $this->request = $request; @@ -232,6 +236,7 @@ public function __construct( $this->productGalleryApiQueueFactory = $productGalleryApiQueueFactory; $this->appEmulation = $appEmulation; $this->resourceConnection = $resourceConnection; + $this->productGalleryHelper = $productGalleryHelper; } @@ -405,6 +410,7 @@ private function _getProductMedia($sku) } return $this->jsonHelper->jsonEncode($result); + } /** @@ -828,6 +834,7 @@ private function getProductCldUrlsBySku($sku) 'small_image' => null, 'thumbnail' => null, 'media_gallery' => [], + 'media_gallery_params' => [], ]; try { $product = $this->productRepository->get($sku); @@ -843,6 +850,7 @@ private function getProductCldUrlsBySku($sku) $urls['thumbnail'] = $gallItem->getUrl(); } } + $urls['media_gallery_params'] = $this->jsonHelper->jsonEncode($this->productGalleryHelper->getCloudinaryPGOptions()); } catch (\Exception $e) { $urls = [ 'error' => 1, diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 8d2e385..a8fbc2b 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -3,10 +3,11 @@ type CloudinaryData { small_image: String thumbnail: String media_gallery: [String] + media_gallery_params: String @doc(description: "Cloudinary media gallery params (json)") } interface ProductInterface { cld_data: CloudinaryData @resolver(class: "\\Cloudinary\\Cloudinary\\Model\\GraphQLResolver\\ProductAttributeCldResolver") @doc(description: "Cloudinary urls generated for product images") -} \ No newline at end of file +} From 9a0c79f76db7780aa22f24f4c226efcbc7b3485b Mon Sep 17 00:00:00 2001 From: Ariel Ashri Date: Sun, 7 Jul 2024 11:34:15 +0300 Subject: [PATCH 2/2] CLOUDINARY-493 - change param name to 'gallery_widget_parameterrs' --- Model/Api/ProductGalleryManagement.php | 4 ++-- etc/schema.graphqls | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/Api/ProductGalleryManagement.php b/Model/Api/ProductGalleryManagement.php index 7207bfd..cc42dd6 100644 --- a/Model/Api/ProductGalleryManagement.php +++ b/Model/Api/ProductGalleryManagement.php @@ -834,7 +834,7 @@ private function getProductCldUrlsBySku($sku) 'small_image' => null, 'thumbnail' => null, 'media_gallery' => [], - 'media_gallery_params' => [], + 'gallery_widget_parameters' => [], ]; try { $product = $this->productRepository->get($sku); @@ -850,7 +850,7 @@ private function getProductCldUrlsBySku($sku) $urls['thumbnail'] = $gallItem->getUrl(); } } - $urls['media_gallery_params'] = $this->jsonHelper->jsonEncode($this->productGalleryHelper->getCloudinaryPGOptions()); + $urls['gallery_widget_parameters'] = $this->jsonHelper->jsonEncode($this->productGalleryHelper->getCloudinaryPGOptions()); } catch (\Exception $e) { $urls = [ 'error' => 1, diff --git a/etc/schema.graphqls b/etc/schema.graphqls index a8fbc2b..1c07162 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -3,11 +3,11 @@ type CloudinaryData { small_image: String thumbnail: String media_gallery: [String] - media_gallery_params: String @doc(description: "Cloudinary media gallery params (json)") + gallery_widget_parameters: String @doc(description: "Cloudinary gallery widget parameters (json)") } interface ProductInterface { cld_data: CloudinaryData @resolver(class: "\\Cloudinary\\Cloudinary\\Model\\GraphQLResolver\\ProductAttributeCldResolver") - @doc(description: "Cloudinary urls generated for product images") + @doc(description: "Cloudinary urls generated for product images and gallery widget parameters.") }