From ec7b5159af55802c126bac05f855c5d4888c8eaa Mon Sep 17 00:00:00 2001 From: pini-girit Date: Wed, 7 Jul 2021 14:58:53 +0300 Subject: [PATCH 1/2] v1.15.2: Added default image global transformation --- Core/Image/Transformation.php | 11 ++++++++- Core/Image/Transformation/DefaultImage.php | 28 ++++++++++++++++++++++ Model/Configuration.php | 13 +++++++++- composer.json | 2 +- etc/adminhtml/system.xml | 6 ++++- etc/module.xml | 2 +- marketplace.composer.json | 2 +- 7 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Core/Image/Transformation/DefaultImage.php diff --git a/Core/Image/Transformation.php b/Core/Image/Transformation.php index 47819e4e..d64a26f7 100644 --- a/Core/Image/Transformation.php +++ b/Core/Image/Transformation.php @@ -3,6 +3,7 @@ namespace Cloudinary\Cloudinary\Core\Image; use Cloudinary\Cloudinary\Core\Image\Transformation\Crop; +use Cloudinary\Cloudinary\Core\Image\Transformation\DefaultImage; use Cloudinary\Cloudinary\Core\Image\Transformation\Dimensions; use Cloudinary\Cloudinary\Core\Image\Transformation\Dpr; use Cloudinary\Cloudinary\Core\Image\Transformation\FetchFormat; @@ -12,6 +13,7 @@ class Transformation { + private $defaultImage; private $gravity; private $dimensions; private $crop; @@ -27,6 +29,12 @@ public function __construct() $this->flags = []; } + public function withDefaultImage(DefaultImage $defaultImage) + { + $this->defaultImage = trim((string)$defaultImage); + return $this; + } + public function withGravity(Gravity $gravity) { $this->gravity = $gravity; @@ -93,7 +101,8 @@ public function build() 'width' => $this->dimensions ? $this->dimensions->getWidth() : null, 'height' => $this->dimensions ? $this->dimensions->getHeight() : null, 'dpr' => (string)$this->dpr, - 'flags' => $this->flags + 'flags' => $this->flags, + 'default_image' => $this->defaultImage, ] ]; } diff --git a/Core/Image/Transformation/DefaultImage.php b/Core/Image/Transformation/DefaultImage.php new file mode 100644 index 00000000..2ee83912 --- /dev/null +++ b/Core/Image/Transformation/DefaultImage.php @@ -0,0 +1,28 @@ +value = $value; + } + + public function __toString() + { + return $this->value; + } + + public static function fromString($value) + { + return new DefaultImage($value); + } + + public static function null() + { + return new DefaultImage(null); + } +} diff --git a/Model/Configuration.php b/Model/Configuration.php index 5d37572c..e5798956 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -8,6 +8,7 @@ use Cloudinary\Cloudinary\Core\Credentials; use Cloudinary\Cloudinary\Core\Exception\InvalidCredentials; use Cloudinary\Cloudinary\Core\Image\Transformation; +use Cloudinary\Cloudinary\Core\Image\Transformation\DefaultImage; use Cloudinary\Cloudinary\Core\Image\Transformation\Dpr; use Cloudinary\Cloudinary\Core\Image\Transformation\FetchFormat; use Cloudinary\Cloudinary\Core\Image\Transformation\Freeform; @@ -41,6 +42,7 @@ class Configuration implements ConfigurationInterface const CONFIG_PATH_DEFAULT_QUALITY = 'cloudinary/transformations/cloudinary_image_quality'; const CONFIG_PATH_DEFAULT_DPR = 'cloudinary/transformations/cloudinary_image_dpr'; const CONFIG_PATH_DEFAULT_FETCH_FORMAT = 'cloudinary/transformations/cloudinary_fetch_format'; + const CONFIG_PATH_DEFAULT_IMAGE = 'cloudinary/transformations/cloudinary_default_image'; const CONFIG_PATH_GLOBAL_FREEFORM = 'cloudinary/transformations/cloudinary_free_transform_global'; //= Lazyload @@ -238,7 +240,8 @@ public function getDefaultTransformation() ->withQuality(Quality::fromString($this->getImageQuality())) ->withFetchFormat(FetchFormat::fromString($this->getFetchFormat())) ->withFreeform(Freeform::fromString($this->getDefaultGlobalFreeform())) - ->withDpr(Dpr::fromString($this->getImageDpr())); + ->withDpr(Dpr::fromString($this->getImageDpr())) + ->withDefaultImage(DefaultImage::fromString($this->getCloudinaryDefaultImage())); } /** @@ -324,6 +327,14 @@ public function getFetchFormat() return $this->configReader->isSetFlag(self::CONFIG_PATH_DEFAULT_FETCH_FORMAT) ? FetchFormat::FETCH_FORMAT_AUTO : ''; } + /** + * @return string + */ + public function getCloudinaryDefaultImage() + { + return (string) $this->configReader->getValue(self::CONFIG_PATH_DEFAULT_IMAGE); + } + /** * @return string */ diff --git a/composer.json b/composer.json index 7b6b478b..d6cf5314 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.15.1", + "version": "1.15.2", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 82431e29..3cf4f357 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -69,7 +69,11 @@ Set the DPR value for your images. A DPR value of 2.0 will generate and deliver hi-res images for better results on HiDPI devices such as Retina Displays. Cloudinary\Cloudinary\Model\Config\Source\Dropdown\Dpr - + + + The public ID and file extension of the image to use as a placeholder when an asset no longer exists (e.g. sample.jpg). + + Custom transformations will be added to the default image transformations settings chosen above.
For information about the full range of transforms available see the Cloudinary documentation.
You may need to clear or rebuild the Magento block and full page caches to see the changes in the front end.]]>
Cloudinary\Cloudinary\Model\Config\Backend\Free diff --git a/etc/module.xml b/etc/module.xml index 5d600991..73ad1044 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/marketplace.composer.json b/marketplace.composer.json index 224a01c6..2909bdbe 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.15.1", + "version": "1.15.2", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" From ea9e82ea2bc01870603c69d6a37d25bb91473a86 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Thu, 8 Jul 2021 16:57:59 +0300 Subject: [PATCH 2/2] v1.15.2: Fixed import error when the CSV has multiple CLD video URLs --- Plugin/CatalogImportExport/Model/Import/Uploader.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugin/CatalogImportExport/Model/Import/Uploader.php b/Plugin/CatalogImportExport/Model/Import/Uploader.php index d1e4a1ad..722d32ab 100644 --- a/Plugin/CatalogImportExport/Model/Import/Uploader.php +++ b/Plugin/CatalogImportExport/Model/Import/Uploader.php @@ -152,6 +152,7 @@ public function aroundMove(\Magento\CatalogImportExport\Model\Import\Uploader $u if ($this->parsedRemoteFileUrl['type'] === 'video') { $cloudinaryVideosImportMap = $this->coreRegistry->registry('cloudinary_videos_import_map') ?: []; $cloudinaryVideosImportMap["{$result['file']}"] = $this->parsedRemoteFileUrl["orig_url"]; + $this->coreRegistry->unregister('cloudinary_videos_import_map'); $this->coreRegistry->register('cloudinary_videos_import_map', $cloudinaryVideosImportMap); } }