From 5f5106dffba3649f64d91c111c939b78b08e6b77 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Wed, 2 Jun 2021 17:42:57 +0300 Subject: [PATCH 1/3] v1.14.12: Removed AutomaticLoginUser --- Helper/MediaLibraryHelper.php | 9 --------- Model/Configuration.php | 9 --------- composer.json | 2 +- etc/adminhtml/system.xml | 5 ----- etc/module.xml | 2 +- marketplace.composer.json | 2 +- 6 files changed, 3 insertions(+), 26 deletions(-) diff --git a/Helper/MediaLibraryHelper.php b/Helper/MediaLibraryHelper.php index 75b7ce5..e89fed9 100644 --- a/Helper/MediaLibraryHelper.php +++ b/Helper/MediaLibraryHelper.php @@ -78,15 +78,6 @@ public function getCloudinaryMLOptions($multiple = false, $refresh = true) 'platform' => "{$this->configuration->getMagentoPlatformName()} {$this->configuration->getMagentoPlatformEdition()} {$this->configuration->getMagentoPlatformVersion()}" ] ]; - if (($this->credentials["username"] = $this->configuration->getAutomaticLoginUser())) { - $this->cloudinaryMLoptions["timestamp"] = $this->timestamp; - $this->cloudinaryMLoptions["username"] = $this->credentials["username"]; - $this->cloudinaryMLoptions["signature"] = $this->signature = hash('sha256', urldecode(http_build_query([ - 'cloud_name' => $this->credentials['cloud_name'], - 'timestamp' => $this->timestamp, - 'username' => $this->credentials['username'], - ])) . $this->credentials['api_secret']); - } } } if ($this->cloudinaryMLoptions) { diff --git a/Model/Configuration.php b/Model/Configuration.php index b23b510..5d37572 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -34,7 +34,6 @@ class Configuration implements ConfigurationInterface //= Basics const CONFIG_PATH_ENABLED = 'cloudinary/cloud/cloudinary_enabled'; const CONFIG_PATH_ENVIRONMENT_VARIABLE = 'cloudinary/setup/cloudinary_environment_variable'; - const CONFIG_PATH_AUTOMATIC_LOGIN_USER = 'cloudinary/setup/cloudinary_automatic_login_user'; const CONFIG_PATH_CDN_SUBDOMAIN = 'cloudinary/configuration/cloudinary_cdn_subdomain'; //= Transformations @@ -229,14 +228,6 @@ public function getCredentials() return $this->getEnvironmentVariable()->getCredentials(); } - /** - * @return string - */ - public function getAutomaticLoginUser() - { - return (string) $this->configReader->getValue(self::CONFIG_PATH_AUTOMATIC_LOGIN_USER); - } - /** * @return Transformation */ diff --git a/composer.json b/composer.json index b39a7f8..72a2733 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary-magento2", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.14.11", + "version": "1.14.12", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 291ec2f..92dc131 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -31,11 +31,6 @@ Cloudinary\Cloudinary\Model\Config\Backend\Credentials - - - ]]> - validate-email - diff --git a/etc/module.xml b/etc/module.xml index b92e87a..4311dda 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/marketplace.composer.json b/marketplace.composer.json index 7ff072f..9f2fac3 100644 --- a/marketplace.composer.json +++ b/marketplace.composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.14.11", + "version": "1.14.12", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" From ea3c2cffe90da32c970eea292fcdfeaf66ad97a9 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Wed, 9 Jun 2021 10:50:40 +0300 Subject: [PATCH 2/3] v1.14.13: Added API endpoints for getting product CLD media URLs --- Api/ProductGalleryManagementInterface.php | 16 ++++ Model/Api/ProductGalleryManagement.php | 106 ++++++++++++++++++++-- composer.json | 2 +- etc/module.xml | 2 +- etc/webapi.xml | 18 ++++ marketplace.composer.json | 2 +- 6 files changed, 133 insertions(+), 13 deletions(-) diff --git a/Api/ProductGalleryManagementInterface.php b/Api/ProductGalleryManagementInterface.php index 24ae886..3fc70d2 100644 --- a/Api/ProductGalleryManagementInterface.php +++ b/Api/ProductGalleryManagementInterface.php @@ -36,4 +36,20 @@ public function addItems($items); * @return string */ public function addProductMedia($sku, $urls); + + /** + * Get product gallery items as Cloudinary URLs. + * @method getProductMedia + * @param string $sku + * @return string + */ + public function getProductMedia($sku); + + /** + * Get products gallery items as Cloudinary URLs. + * @method getProductsMedia + * @param mixed $skus + * @return string + */ + public function getProductsMedia($skus); } diff --git a/Model/Api/ProductGalleryManagement.php b/Model/Api/ProductGalleryManagement.php index b8bc606..7bb673a 100644 --- a/Model/Api/ProductGalleryManagement.php +++ b/Model/Api/ProductGalleryManagement.php @@ -247,11 +247,7 @@ public function addProductMedia($sku, $urls) ]; try { $this->checkEnvHeader(); - if (!$this->configuration->isEnabled()) { - throw new LocalizedException( - __("Cloudinary module is disabled. Please enable it first in order to use this API.") - ); - } + $this->checkEnabled(); $urls = (array)$urls; foreach ($urls as $i => $url) { try { @@ -284,6 +280,50 @@ public function addProductMedia($sku, $urls) return $this->jsonHelper->jsonEncode($result); } + /** + * {@inheritdoc} + */ + public function getProductMedia($sku) + { + return $this->_getProductMedia($sku); + } + + /** + * {@inheritdoc} + */ + public function getProductsMedia($skus) + { + return $this->_getProductMedia($skus); + } + + /** + * [_getProductMedia description] + * @method _getProductMedia + * @param mixed $sku + * @return string (json result) + */ + private function _getProductMedia($sku) + { + $result = ["data" => []]; + + try { + $this->checkEnvHeader(); + $this->checkEnabled(); + if (is_array($sku) || is_object($sku)) { + foreach ($sku as $key => $_sku) { + $result['data'][$_sku] = $this->getProductCldUrlsBySku($_sku); + } + } else { + $result['data'] = $this->getProductCldUrlsBySku($sku); + } + } catch (\Exception $e) { + $result["error"] = 1; + $result["message"] = $e->getMessage(); + } + + return $this->jsonHelper->jsonEncode($result); + } + /** * {@inheritdoc} */ @@ -312,11 +352,7 @@ public function addItems($items) ]; try { $this->checkEnvHeader(); - if (!$this->configuration->isEnabled()) { - throw new LocalizedException( - __("Cloudinary module is disabled. Please enable it first in order to use this API.") - ); - } + $this->checkEnabled(); $items = (array)$items; foreach ($items as $i => $item) { try { @@ -568,6 +604,20 @@ private function checkEnvHeader() return $this; } + /** + * @method checkEnabled + * @return $this + */ + private function checkEnabled() + { + if (!$this->configuration->isEnabled()) { + throw new LocalizedException( + __("Cloudinary module is disabled. Please enable it first in order to use this API.") + ); + } + return $this; + } + private function getLocalTmpFileName($remoteFileUrl) { $localFileName = Uploader::getCorrectFileName(basename($remoteFileUrl)); @@ -682,6 +732,42 @@ private function saveCloudinaryMapping() ->save(); } + /** + * @method getProductMediaBySku + * @param string $sku + * @return array + */ + private function getProductCldUrlsBySku($sku) + { + $urls = [ + 'image' => null, + 'small_image' => null, + 'thumbnail' => null, + 'media_gallery' => [], + ]; + try { + $product = $this->productRepository->get($sku); + foreach ($product->getMediaGalleryImages() as $gallItem) { + $urls['media_gallery'][] = $gallItem->getUrl(); + if ($product->getData('image') === $gallItem->getFile()) { + $urls['image'] = $gallItem->getUrl(); + } + if ($product->getData('small_image') === $gallItem->getFile()) { + $urls['small_image'] = $gallItem->getUrl(); + } + if ($product->getData('thumbnail') === $gallItem->getFile()) { + $urls['thumbnail'] = $gallItem->getUrl(); + } + } + } catch (\Exception $e) { + $urls = [ + 'error' => 1, + 'message' => $e->getMessage(), + ]; + } + return $urls; + } + /////////////////////////////// // App Environment Emulation // /////////////////////////////// diff --git a/composer.json b/composer.json index 72a2733..945c01d 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary-magento2", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.14.12", + "version": "1.14.13", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" diff --git a/etc/module.xml b/etc/module.xml index 4311dda..1ebb8ab 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/etc/webapi.xml b/etc/webapi.xml index d3b782b..afc1e3b 100644 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -47,6 +47,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/marketplace.composer.json b/marketplace.composer.json index 9f2fac3..f42ef50 100644 --- a/marketplace.composer.json +++ b/marketplace.composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.14.12", + "version": "1.14.13", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" From 2d74305e57125ebb0dc3934f706c65b9b5c9a2d8 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Wed, 9 Jun 2021 12:35:02 +0300 Subject: [PATCH 3/3] v1.14.13: Added a note to the product gallery configuration --- etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 92dc131..030da15 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -81,7 +81,7 @@ 0 - Product Gallery documentation for information on the configuration options.]]> + Product Gallery documentation for information on the configuration options.
*To enable the Product Gallery to access and load your media, ensure that you remove any restrictions on listing resources. To verify this, open the Cloudinary Console, navigate to Settings and select the Security tab. From here, make sure that “Resource List” is unchecked in the “Restricted Media Types” option group.]]>
Magento\Config\Model\Config\Source\Yesno cloudinary/product_gallery/enabled