From 84733e9b2a02a7980e25fc6f322695c9538d5737 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Thu, 5 Aug 2021 15:26:35 +0300 Subject: [PATCH 01/11] v1.17.0,CLOUDINARY-332: Added analytics param to PG asset URLs --- Helper/ProductGalleryHelper.php | 1 + composer.json | 2 +- etc/module.xml | 2 +- marketplace.composer.json | 30 +++++++++++++++--------------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Helper/ProductGalleryHelper.php b/Helper/ProductGalleryHelper.php index 9e9c309e..8e3103ca 100644 --- a/Helper/ProductGalleryHelper.php +++ b/Helper/ProductGalleryHelper.php @@ -94,6 +94,7 @@ public function getCloudinaryPGOptions($refresh = false, $ignoreDisabled = false unset($this->cloudinaryPGoptions['custom_free_params']); } $this->cloudinaryPGoptions['cloudName'] = $this->getCloudName(); + $this->cloudinaryPGoptions['queryParam'] = 'AB'; } return $this->cloudinaryPGoptions; diff --git a/composer.json b/composer.json index cb537ae0..4b1b87b6 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.16.1", + "version": "1.17.0", "license": "MIT", "require": { "cloudinary/cloudinary_php": "^1.20.0" diff --git a/etc/module.xml b/etc/module.xml index 9f637331..a4b59f0d 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/marketplace.composer.json b/marketplace.composer.json index 7f77c212..d1f80080 100644 --- a/marketplace.composer.json +++ b/marketplace.composer.json @@ -1,18 +1,18 @@ { - "name": "cloudinary/cloudinary", - "description": "Cloudinary Magento 2 Integration.", - "type": "magento2-module", - "version": "1.16.1", - "license": "MIT", - "require": { - "cloudinary/cloudinary_php": "^1.20.0" - }, - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Cloudinary\\Cloudinary\\": "" - } + "name": "cloudinary/cloudinary", + "description": "Cloudinary Magento 2 Integration.", + "type": "magento2-module", + "version": "1.17.0", + "license": "MIT", + "require": { + "cloudinary/cloudinary_php": "^1.20.0" + }, + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Cloudinary\\Cloudinary\\": "" } + } } \ No newline at end of file From 35f597b822b8a26c7c82f61ca27a12e2a21fc554 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Thu, 12 Aug 2021 10:43:11 +0300 Subject: [PATCH 02/11] v1.17.0: Updated CLD Logos --- view/adminhtml/web/css/source/_module.less | 4 +- .../images/cloudinary_cloud_glyph_regular.svg | 1 + .../images/cloudinary_cloud_glyph_white.svg | 1 + .../images/cloudinary_icon_for_blue_bg.svg | 69 ------ .../images/cloudinary_icon_for_dark_bg.svg | 69 ------ .../images/cloudinary_icon_for_white_bg.svg | 69 ------ .../images/cloudinary_logo_for_blue_bg.svg | 188 ---------------- .../images/cloudinary_logo_for_dark_bg.svg | 188 ---------------- .../images/cloudinary_logo_for_white_bg.svg | 188 ---------------- .../cloudinary_vertical_logo_for_blue_bg.svg | 203 ------------------ .../cloudinary_vertical_logo_for_dark_bg.svg | 203 ------------------ .../cloudinary_vertical_logo_for_white_bg.svg | 203 ------------------ 12 files changed, 4 insertions(+), 1382 deletions(-) create mode 100644 view/base/web/images/cloudinary_cloud_glyph_regular.svg create mode 100644 view/base/web/images/cloudinary_cloud_glyph_white.svg delete mode 100644 view/base/web/images/cloudinary_icon_for_blue_bg.svg delete mode 100644 view/base/web/images/cloudinary_icon_for_dark_bg.svg delete mode 100644 view/base/web/images/cloudinary_icon_for_white_bg.svg delete mode 100644 view/base/web/images/cloudinary_logo_for_blue_bg.svg delete mode 100644 view/base/web/images/cloudinary_logo_for_dark_bg.svg delete mode 100644 view/base/web/images/cloudinary_logo_for_white_bg.svg delete mode 100644 view/base/web/images/cloudinary_vertical_logo_for_blue_bg.svg delete mode 100644 view/base/web/images/cloudinary_vertical_logo_for_dark_bg.svg delete mode 100644 view/base/web/images/cloudinary_vertical_logo_for_white_bg.svg diff --git a/view/adminhtml/web/css/source/_module.less b/view/adminhtml/web/css/source/_module.less index 642d941f..b3e98a91 100644 --- a/view/adminhtml/web/css/source/_module.less +++ b/view/adminhtml/web/css/source/_module.less @@ -1,5 +1,5 @@ .cloudinary-configuration-tab .admin__page-nav-title strong:before { - background-image: url("Cloudinary_Cloudinary::images/cloudinary_icon_for_white_bg.svg"); + background-image: url("Cloudinary_Cloudinary::images/cloudinary_cloud_glyph_regular.svg"); background-size: contain; background-repeat: no-repeat; background-position: center center; @@ -31,7 +31,7 @@ padding: 6px 14px 6px 50px; &:before { - background-image: url("Cloudinary_Cloudinary::images/cloudinary_icon_for_blue_bg.svg"); + background-image: url("Cloudinary_Cloudinary::images/cloudinary_cloud_glyph_white.svg"); background-repeat: no-repeat; background-size: contain; background-position: center; diff --git a/view/base/web/images/cloudinary_cloud_glyph_regular.svg b/view/base/web/images/cloudinary_cloud_glyph_regular.svg new file mode 100644 index 00000000..a284090d --- /dev/null +++ b/view/base/web/images/cloudinary_cloud_glyph_regular.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/view/base/web/images/cloudinary_cloud_glyph_white.svg b/view/base/web/images/cloudinary_cloud_glyph_white.svg new file mode 100644 index 00000000..5a108827 --- /dev/null +++ b/view/base/web/images/cloudinary_cloud_glyph_white.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/view/base/web/images/cloudinary_icon_for_blue_bg.svg b/view/base/web/images/cloudinary_icon_for_blue_bg.svg deleted file mode 100644 index 8a5c6c4b..00000000 --- a/view/base/web/images/cloudinary_icon_for_blue_bg.svg +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_icon_for_dark_bg.svg b/view/base/web/images/cloudinary_icon_for_dark_bg.svg deleted file mode 100644 index 0dae7c93..00000000 --- a/view/base/web/images/cloudinary_icon_for_dark_bg.svg +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_icon_for_white_bg.svg b/view/base/web/images/cloudinary_icon_for_white_bg.svg deleted file mode 100644 index 0dae7c93..00000000 --- a/view/base/web/images/cloudinary_icon_for_white_bg.svg +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_logo_for_blue_bg.svg b/view/base/web/images/cloudinary_logo_for_blue_bg.svg deleted file mode 100644 index 72b86b0e..00000000 --- a/view/base/web/images/cloudinary_logo_for_blue_bg.svg +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_logo_for_dark_bg.svg b/view/base/web/images/cloudinary_logo_for_dark_bg.svg deleted file mode 100644 index 58bc88be..00000000 --- a/view/base/web/images/cloudinary_logo_for_dark_bg.svg +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_logo_for_white_bg.svg b/view/base/web/images/cloudinary_logo_for_white_bg.svg deleted file mode 100644 index f5e2b106..00000000 --- a/view/base/web/images/cloudinary_logo_for_white_bg.svg +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_vertical_logo_for_blue_bg.svg b/view/base/web/images/cloudinary_vertical_logo_for_blue_bg.svg deleted file mode 100644 index c29c5e7c..00000000 --- a/view/base/web/images/cloudinary_vertical_logo_for_blue_bg.svg +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_vertical_logo_for_dark_bg.svg b/view/base/web/images/cloudinary_vertical_logo_for_dark_bg.svg deleted file mode 100644 index 73618ee0..00000000 --- a/view/base/web/images/cloudinary_vertical_logo_for_dark_bg.svg +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/base/web/images/cloudinary_vertical_logo_for_white_bg.svg b/view/base/web/images/cloudinary_vertical_logo_for_white_bg.svg deleted file mode 100644 index 2e4d2e02..00000000 --- a/view/base/web/images/cloudinary_vertical_logo_for_white_bg.svg +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - From d8c224e2857e28b31db346f3336d102f1e5e0949 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Thu, 9 Sep 2021 11:22:25 +0300 Subject: [PATCH 03/11] v1.17.0:CLOUDINARY-209: Allow applying products-global transformation --- Controller/Adminhtml/Ajax/Free/Image.php | 2 +- .../Source/Dropdown/FreeTransformBehavior.php | 22 +++++ Model/Configuration.php | 31 ++++++- Plugin/Catalog/Block/Product/ImageFactory.php | 2 +- .../Model/Product/Image/UrlBuilder.php | 2 +- .../Product/Form/Modifier/Product.php | 19 +++-- etc/adminhtml/system.xml | 13 +++ etc/config.xml | 1 + view/adminhtml/templates/config/free.phtml | 2 +- view/adminhtml/web/js/cloudinary-free.js | 81 +++++++++++++++---- 10 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 Model/Config/Source/Dropdown/FreeTransformBehavior.php diff --git a/Controller/Adminhtml/Ajax/Free/Image.php b/Controller/Adminhtml/Ajax/Free/Image.php index e2102821..2784a18d 100644 --- a/Controller/Adminhtml/Ajax/Free/Image.php +++ b/Controller/Adminhtml/Ajax/Free/Image.php @@ -76,7 +76,7 @@ public function execute() */ private function defaultTransformWithFreeTransform($freeTransform) { - $transformation = $this->configuration->getDefaultTransformation(); + $transformation = $this->configuration->getDefaultTransformation(true); if ($freeTransform) { $transformation->withFreeform(Freeform::fromString($freeTransform)); diff --git a/Model/Config/Source/Dropdown/FreeTransformBehavior.php b/Model/Config/Source/Dropdown/FreeTransformBehavior.php new file mode 100644 index 00000000..2ed10c1e --- /dev/null +++ b/Model/Config/Source/Dropdown/FreeTransformBehavior.php @@ -0,0 +1,22 @@ + 'add', + 'label' => 'Add', + ], + [ + 'value' => 'override', + 'label' => 'Override', + ], + ]; + } +} diff --git a/Model/Configuration.php b/Model/Configuration.php index e5798956..174e005b 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -44,6 +44,8 @@ class Configuration implements ConfigurationInterface 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'; + const CONFIG_PATH_GLOBAL_FREEFORM_PRODUCTS = 'cloudinary/transformations/cloudinary_free_transform_global_products'; + const CONFIG_PATH_GLOBAL_FREEFORM_PRODUCTS_BEHAVIOR = 'cloudinary/transformations/cloudinary_free_transform_global_products_behavior'; //= Lazyload const XML_PATH_LAZYLOAD_ENABLED = 'cloudinary/lazyload/enabled'; @@ -231,15 +233,24 @@ public function getCredentials() } /** + * @param bool $isProduct * @return Transformation */ - public function getDefaultTransformation() + public function getDefaultTransformation($isProduct = false) { + if ($isProduct && ($globalFreeform = $this->getDefaultGlobalFreeformProducts())) { + if ($this->getDefaultGlobalFreeformProductsBehavior() === 'add') { + $globalFreeform = $this->getDefaultGlobalFreeform() . ',' . $globalFreeform; + } + } else { + $globalFreeform = $this->getDefaultGlobalFreeform(); + } + return Transformation::builder() ->withGravity(Gravity::fromString($this->getDefaultGravity())) ->withQuality(Quality::fromString($this->getImageQuality())) ->withFetchFormat(FetchFormat::fromString($this->getFetchFormat())) - ->withFreeform(Freeform::fromString($this->getDefaultGlobalFreeform())) + ->withFreeform(Freeform::fromString($globalFreeform)) ->withDpr(Dpr::fromString($this->getImageDpr())) ->withDefaultImage(DefaultImage::fromString($this->getCloudinaryDefaultImage())); } @@ -252,6 +263,22 @@ private function getDefaultGlobalFreeform() return (string) $this->configReader->getValue(self::CONFIG_PATH_GLOBAL_FREEFORM); } + /** + * @return string + */ + private function getDefaultGlobalFreeformProducts() + { + return (string) $this->configReader->getValue(self::CONFIG_PATH_GLOBAL_FREEFORM_PRODUCTS); + } + + /** + * @return string + */ + private function getDefaultGlobalFreeformProductsBehavior() + { + return (string) $this->configReader->getValue(self::CONFIG_PATH_GLOBAL_FREEFORM_PRODUCTS_BEHAVIOR); + } + /** * @return boolean */ diff --git a/Plugin/Catalog/Block/Product/ImageFactory.php b/Plugin/Catalog/Block/Product/ImageFactory.php index 1feb1bbe..b665cedf 100644 --- a/Plugin/Catalog/Block/Product/ImageFactory.php +++ b/Plugin/Catalog/Block/Product/ImageFactory.php @@ -216,7 +216,7 @@ function () use ($imageBlock) { private function createTransformation(array $imageMiscParams) { $dimensions = $this->getDimensions($imageMiscParams); - $transform = $this->configuration->getDefaultTransformation()->withDimensions($dimensions); + $transform = $this->configuration->getDefaultTransformation(true)->withDimensions($dimensions); if (isset($imageMiscParams['keep_frame'])) { $this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false; diff --git a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php index 2d38ab4c..26e1d10d 100644 --- a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php +++ b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php @@ -179,7 +179,7 @@ private function createTransformation(array $imageMiscParams) $imageMiscParams['image_height'] = (isset($imageMiscParams['image_height'])) ? $imageMiscParams['image_height'] : null; $imageMiscParams['image_width'] = (isset($imageMiscParams['image_width'])) ? $imageMiscParams['image_width'] : null; $dimensions = $this->dimensions ?: Dimensions::fromWidthAndHeight($imageMiscParams['image_width'], $imageMiscParams['image_height']); - $transform = $this->configuration->getDefaultTransformation()->withDimensions($dimensions); + $transform = $this->configuration->getDefaultTransformation(true)->withDimensions($dimensions); if (isset($imageMiscParams['keep_frame'])) { $this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false; diff --git a/Ui/DataProvider/Product/Form/Modifier/Product.php b/Ui/DataProvider/Product/Form/Modifier/Product.php index ec2d268e..71b5943c 100644 --- a/Ui/DataProvider/Product/Form/Modifier/Product.php +++ b/Ui/DataProvider/Product/Form/Modifier/Product.php @@ -2,17 +2,17 @@ namespace Cloudinary\Cloudinary\Ui\DataProvider\Product\Form\Modifier; -use Cloudinary\Cloudinary\Core\Image; use Cloudinary\Cloudinary\Core\CloudinaryImageProvider; use Cloudinary\Cloudinary\Core\ConfigurationInterface; +use Cloudinary\Cloudinary\Core\Image; use Cloudinary\Cloudinary\Core\Image\Transformation; use Cloudinary\Cloudinary\Core\Image\Transformation\Freeform; -use Magento\Catalog\Model\Locator\LocatorInterface; -use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; -use Magento\Ui\Component\Form; use Cloudinary\Cloudinary\Model\TransformationFactory; +use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\Catalog\Model\Product\Gallery\Entry; +use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\Framework\UrlInterface; +use Magento\Ui\Component\Form; class Product extends AbstractModifier { @@ -102,11 +102,10 @@ public function modifyMeta(array $meta) 'collapsible' => true, 'opened' => false, 'componentType' => Form\Fieldset::NAME, - 'sortOrder' => - $this->getNextGroupSortOrder( - $meta, - static::GROUP_CONTENT, - static::SORT_ORDER + 'sortOrder' => $this->getNextGroupSortOrder( + $meta, + static::GROUP_CONTENT, + static::SORT_ORDER ), ], ], @@ -223,7 +222,7 @@ private function injectImageUrls(array $images) */ private function defaultTransformWithFreeTransform($freeTransform) { - $transformation = $this->configuration->getDefaultTransformation(); + $transformation = $this->configuration->getDefaultTransformation(true); if ($freeTransform) { $transformation->withFreeform(Freeform::fromString($freeTransform)); diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index af50f581..d61150a7 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -84,7 +84,20 @@ 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 + cloudinary/transformations/cloudinary_free_transform_global + + + + for products only.
+ *Set the behavior of this field on the dropdown below.]]>
+ Cloudinary\Cloudinary\Model\Config\Backend\Free + cloudinary/transformations/cloudinary_free_transform_global_products +
+ + + Cloudinary\Cloudinary\Model\Config\Source\Dropdown\FreeTransformBehavior Cloudinary\Cloudinary\Block\Adminhtml\Form\Field\Free + cloudinary/transformations/cloudinary_free_transform_global_products_behavior diff --git a/etc/config.xml b/etc/config.xml index 2a6615ec..14c5437b 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -7,6 +7,7 @@ 1 auto 2.0 + add 1 diff --git a/view/adminhtml/templates/config/free.phtml b/view/adminhtml/templates/config/free.phtml index 95b8ef07..82b49cc6 100644 --- a/view/adminhtml/templates/config/free.phtml +++ b/view/adminhtml/templates/config/free.phtml @@ -18,5 +18,5 @@
", "ajaxKey": "getFormKey() ?>"}}'> + data-mage-init='{"cloudinaryFreeTransform":{"previewButtonId": "#cloudinary_free_transform_preview_button", "transformInputFieldId": "#cloudinary_transformations_cloudinary_free_transform_global", "transformInputProductsFieldId": "#cloudinary_transformations_cloudinary_free_transform_global_products", "transformInputProductsBehaviorFieldId": "#cloudinary_transformations_cloudinary_free_transform_global_products_behavior", "ajaxUrl": "getUrl('cloudinary/ajax_free/sample') ?>", "ajaxKey": "getFormKey() ?>"}}'>
diff --git a/view/adminhtml/web/js/cloudinary-free.js b/view/adminhtml/web/js/cloudinary-free.js index 374c9b83..82077e00 100644 --- a/view/adminhtml/web/js/cloudinary-free.js +++ b/view/adminhtml/web/js/cloudinary-free.js @@ -9,46 +9,58 @@ define( 'cloudinary.cloudinaryFreeTransform', { currentTransform: '', + currentTransformProducts: '', getTransformText: function() { - return $(this.options.transformInputFieldId).val(); + return $(this.options.transformInputFieldId).val() || ''; }, - getImageHtml: function(src) { - var id = 'cloudinary_custom_transform_preview_image', - style = 'width: auto; height: auto; max-width: 500px; max-height: 500px; min-height: 50px;', + getTransformProductsText: function() { + return $(this.options.transformInputProductsFieldId).val() || ''; + }, + + getTransformBehavior: function() { + return $(this.options.transformInputProductsBehaviorFieldId).val(); + }, + + getImageHtml: function(src, header) { + if (!src) { + return ''; + } + var cls = 'cloudinary_custom_transform_preview_image', + style = 'width: auto; height: auto; max-width: 350px; max-height: 350px; min-height: 50px;', + header = header || '', footer = '

Image size restricted for viewing purposes

'; - return '' + footer; + return header + '' + footer; }, getErrorHtml: function(message) { return '
  • ' + message + '
'; }, - updatePreviewImage: function(url) { - var $image = $('#cloudinary_custom_transform_preview_image'); - - if (!$image.length) { - $('#cloudinary_custom_transform_preview').html(this.getImageHtml(url)); - } else { - $image.attr('src', url); - } + updatePreviewImage: function(url, url2) { + $('#cloudinary_custom_transform_preview').html( + this.getImageHtml(url, '

Global Custom Transformation Preview

') + + this.getImageHtml(url2, '

Products Custom Transformation Preview

') + ); }, updatePreview: function() { - var self = this; + var self = this, + transformations_string = ""; if (!self.isPreviewActive()) { return; } self.currentTransform = self.getTransformText(); + self.currentTransformProducts = self.getTransformProductsText(); self.setPreviewActiveState(false); $.ajax({ url: this.options.ajaxUrl, data: { - free: self.getTransformText(), + free: self.currentTransform, form_key: self.options.ajaxKey }, type: 'post', @@ -56,7 +68,33 @@ define( showLoader: true }).done( function(response) { - self.updatePreviewImage(response.url); + if ((transformations_string = self.currentTransformProducts)) { + if (self.getTransformBehavior() === 'add') { + transformations_string = self.currentTransform + ',' + transformations_string; + } + var globalResURL = response.url; + $.ajax({ + url: self.options.ajaxUrl, + data: { + free: transformations_string, + form_key: self.options.ajaxKey + }, + type: 'post', + dataType: 'json', + showLoader: true + }).done( + function(response) { + self.updatePreviewImage(globalResURL, response.url); + } + ).fail( + function(result) { + $('#cloudinary_custom_transform_preview').html(self.getErrorHtml(result.responseJSON.error)); + } + ); + } else { + return self.updatePreviewImage(response.url); + transformations_string = self.getTransformText(); + } } ).fail( function(result) { @@ -66,7 +104,10 @@ define( }, setPreviewActiveState: function(state) { - if (state && (this.currentTransform !== this.getTransformText())) { + if ( + state && + (this.currentTransform !== this.getTransformText() || self.currentTransformProducts !== this.getTransformProductsText()) + ) { $(this.options.previewButtonId).removeClass('disabled'); } else { $(this.options.previewButtonId).addClass('disabled'); @@ -92,6 +133,12 @@ define( self.setPreviewActiveState(true); } ); + $(this.options.transformInputProductsFieldId).on( + 'change keydown paste input', + function() { + self.setPreviewActiveState(true); + } + ); } } From 9c911244222c7940682b83c1c0a7182c5768a92d Mon Sep 17 00:00:00 2001 From: pini-girit Date: Thu, 9 Sep 2021 11:22:25 +0300 Subject: [PATCH 04/11] v1.17.0:CLOUDINARY-209: Allow applying products-global transformation --- view/adminhtml/web/js/cloudinary-free.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/view/adminhtml/web/js/cloudinary-free.js b/view/adminhtml/web/js/cloudinary-free.js index 82077e00..e98ed72a 100644 --- a/view/adminhtml/web/js/cloudinary-free.js +++ b/view/adminhtml/web/js/cloudinary-free.js @@ -10,6 +10,7 @@ define( currentTransform: '', currentTransformProducts: '', + currentTransformBehavior: '', getTransformText: function() { return $(this.options.transformInputFieldId).val() || ''; @@ -55,6 +56,7 @@ define( self.currentTransform = self.getTransformText(); self.currentTransformProducts = self.getTransformProductsText(); + self.currentTransformBehavior = self.getTransformBehavior(); self.setPreviewActiveState(false); $.ajax({ @@ -69,7 +71,7 @@ define( }).done( function(response) { if ((transformations_string = self.currentTransformProducts)) { - if (self.getTransformBehavior() === 'add') { + if (self.currentTransformBehavior === 'add') { transformations_string = self.currentTransform + ',' + transformations_string; } var globalResURL = response.url; @@ -106,7 +108,11 @@ define( setPreviewActiveState: function(state) { if ( state && - (this.currentTransform !== this.getTransformText() || self.currentTransformProducts !== this.getTransformProductsText()) + ( + this.currentTransform !== this.getTransformText() || + this.currentTransformProducts !== this.getTransformProductsText() || + (this.getTransformProductsText() && this.currentTransformBehavior !== this.getTransformBehavior()) + ) ) { $(this.options.previewButtonId).removeClass('disabled'); } else { @@ -139,6 +145,12 @@ define( self.setPreviewActiveState(true); } ); + $(this.options.transformInputProductsBehaviorFieldId).on( + 'change', + function() { + self.setPreviewActiveState(true); + } + ); } } From efe12c44593c90adf4ee45ad0c6630171f028f80 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Mon, 4 Oct 2021 11:18:39 +0300 Subject: [PATCH 05/11] CLOUDINARY-347: Fix for Transformations keep_frame is not working (GH issue #105) --- Plugin/Catalog/Block/Product/ImageFactory.php | 2 +- Plugin/Catalog/Model/Product/Image/UrlBuilder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugin/Catalog/Block/Product/ImageFactory.php b/Plugin/Catalog/Block/Product/ImageFactory.php index b665cedf..657f3642 100644 --- a/Plugin/Catalog/Block/Product/ImageFactory.php +++ b/Plugin/Catalog/Block/Product/ImageFactory.php @@ -219,7 +219,7 @@ private function createTransformation(array $imageMiscParams) $transform = $this->configuration->getDefaultTransformation(true)->withDimensions($dimensions); if (isset($imageMiscParams['keep_frame'])) { - $this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false; + $this->keepFrame = (bool) $imageMiscParams['keep_frame']; } if ($this->keepFrame) { diff --git a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php index 26e1d10d..60268a0a 100644 --- a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php +++ b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php @@ -182,7 +182,7 @@ private function createTransformation(array $imageMiscParams) $transform = $this->configuration->getDefaultTransformation(true)->withDimensions($dimensions); if (isset($imageMiscParams['keep_frame'])) { - $this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false; + $this->keepFrame = (bool) $imageMiscParams['keep_frame']; } if ($this->keepFrame) { From 0dccae7ba0666c646dbd400335bf609a5e462313 Mon Sep 17 00:00:00 2001 From: Maya Shavin Date: Wed, 8 Dec 2021 10:53:32 +0200 Subject: [PATCH 06/11] add: GraphQL support for query Cld images --- .../ProductAttributeCldResolver.php | 42 +++++++++++++++++++ etc/schema.graphqls | 12 ++++++ 2 files changed, 54 insertions(+) create mode 100644 Model/GraphQLResolver/ProductAttributeCldResolver.php create mode 100644 etc/schema.graphqls diff --git a/Model/GraphQLResolver/ProductAttributeCldResolver.php b/Model/GraphQLResolver/ProductAttributeCldResolver.php new file mode 100644 index 00000000..5520e6f1 --- /dev/null +++ b/Model/GraphQLResolver/ProductAttributeCldResolver.php @@ -0,0 +1,42 @@ +productGalleryManagement = $productGalleryManagement; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $productId = $value['sku']; + $productMediaStr = $this->productGalleryManagement->getProductMedia($productId); + $jsonDecoder = new \Magento\Framework\Serialize\Serializer\Json(); + $productMedia = $jsonDecoder->unserialize($productMediaStr); + return $productMedia['data']; + } + } \ No newline at end of file diff --git a/etc/schema.graphqls b/etc/schema.graphqls new file mode 100644 index 00000000..8d2e385b --- /dev/null +++ b/etc/schema.graphqls @@ -0,0 +1,12 @@ +type CloudinaryData { + image: String + small_image: String + thumbnail: String + media_gallery: [String] +} + +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 9478bedb08964f0c4e05629358e36cd4062adbf5 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Tue, 7 Dec 2021 09:40:10 +0200 Subject: [PATCH 07/11] CLOUDINARY-332: Added analytics query param to all CLD URLs --- Core/CloudinaryImageProvider.php | 2 +- Model/Configuration.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Core/CloudinaryImageProvider.php b/Core/CloudinaryImageProvider.php index 218a8838..f8f6d544 100644 --- a/Core/CloudinaryImageProvider.php +++ b/Core/CloudinaryImageProvider.php @@ -134,7 +134,7 @@ public function retrieveTransformed(Image $image, Transformation $transformation 'sign_url' => $this->configuration->getUseSignedUrls(), 'version' => 1 ] - ); + ) . '?_i=AB'; if (!$this->configuration->isEnabledProductGallery()) { //Handle with use-root-path if necessary: diff --git a/Model/Configuration.php b/Model/Configuration.php index 174e005b..b0654441 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -602,11 +602,15 @@ public function getMagentoPlatformVersion() */ public function parseCloudinaryUrl($url, $publicId = null) { + $parsedUrlParts = $this->mbParseUrl($url); + $url = preg_replace('/\?.*/', '', $url); + $parsed = [ "orig_url" => $url, - "scheme" => null, - "host" => null, - "path" => null, + "scheme" => isset($parsedUrlParts["scheme"]) ? $parsedUrlParts["scheme"] : null, + "host" => isset($parsedUrlParts["host"]) ? $parsedUrlParts["host"] : null, + "path" => isset($parsedUrlParts["path"]) ? $parsedUrlParts["path"] : null, + "query" => isset($parsedUrlParts["query"]) ? $parsedUrlParts["query"] : null, "extension" => \pathinfo($url, PATHINFO_EXTENSION), "type" => null, "cloudName" => null, @@ -620,10 +624,6 @@ public function parseCloudinaryUrl($url, $publicId = null) "thumbnail_url" => null, ]; - $parsed["scheme"] = $this->mbParseUrl($url, PHP_URL_SCHEME); - $parsed["host"] = $this->mbParseUrl($url, PHP_URL_HOST); - $parsed["path"] = $this->mbParseUrl($url, PHP_URL_PATH); - $_url = ltrim($parsed["path"], '/'); $_url = preg_replace('/\.[^.]+$/', '', $_url); From 6f54a7e130aa3a1a8123d42b28b4faafd1bc3ad5 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Thu, 9 Dec 2021 09:25:05 +0200 Subject: [PATCH 08/11] MAG-431,CLOUDINARY-356: Added a note to the auto-upload-mapping configuration --- etc/adminhtml/system.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index d61150a7..7ff03b4d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -42,7 +42,10 @@ - Automatically upload your existing Magento images to your Cloudinary account when an image is requested by a user. Once enabled, click the button below to map your Magento media directory to your Cloudinary account. + Automatically upload your existing Magento images to your Cloudinary account when an image is requested by a user. Once enabled, click the button below to map your Magento media directory to your Cloudinary account.

+

Note: Disabling auto upload mapping from Magento will not remove the configuration from Cloudinary. To completely disable your auto upload mapping, navigate to your Cloudinary Upload settings and clear the Auto upload mapping that corresponds to your Magento URLs.

]]> +
Magento\Config\Model\Config\Source\Yesno
From 9a877efd6de813d601ceb656e4e5cf68fa2d8944 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Thu, 9 Dec 2021 16:46:40 +0200 Subject: [PATCH 09/11] MAG-773,CLOUDINARY-358: Fixed video URL validation on page-builder to support Magento v2.4^ --- ...uilder_base_form_with_background_video.xml | 18 +++++++++++ .../ui_component/pagebuilder_video_form.xml | 14 ++++---- .../js/form/element/validator-rules-mixin.js | 32 +++++++++++++++++-- 3 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 view/adminhtml/ui_component/pagebuilder_base_form_with_background_video.xml diff --git a/view/adminhtml/ui_component/pagebuilder_base_form_with_background_video.xml b/view/adminhtml/ui_component/pagebuilder_base_form_with_background_video.xml new file mode 100644 index 00000000..2b74c1a5 --- /dev/null +++ b/view/adminhtml/ui_component/pagebuilder_base_form_with_background_video.xml @@ -0,0 +1,18 @@ + + +
+
+ + + + Video URLs can be links to videos on YouTube, Vimeo or Cloudinary, or HTTP(S) links to files with valid video extensions (we recommend .mp4) + + + +
+
diff --git a/view/adminhtml/ui_component/pagebuilder_video_form.xml b/view/adminhtml/ui_component/pagebuilder_video_form.xml index c64340f9..81ef3934 100644 --- a/view/adminhtml/ui_component/pagebuilder_video_form.xml +++ b/view/adminhtml/ui_component/pagebuilder_video_form.xml @@ -6,15 +6,13 @@ */ -->
-
- +
+ - - true - - text - - YouTube, Vimeo and Cloudinary are supported + + Video URLs can be links to videos on YouTube, Vimeo or Cloudinary, or HTTP(S) links to files with valid video extensions (we recommend .mp4) + + Video URLs can be links to videos on YouTube, Vimeo or Cloudinary, or HTTP(S) links to files with valid video extensions (we recommend .mp4)
diff --git a/view/adminhtml/web/js/form/element/validator-rules-mixin.js b/view/adminhtml/web/js/form/element/validator-rules-mixin.js index 445945f4..b33b2233 100644 --- a/view/adminhtml/web/js/form/element/validator-rules-mixin.js +++ b/view/adminhtml/web/js/form/element/validator-rules-mixin.js @@ -20,6 +20,7 @@ define([ } return function(validator) { + validator.addRule( 'validate-video-url', function(href) { @@ -29,10 +30,35 @@ define([ href = (href || '').replace(/^\s+/, '').replace(/\s+$/, ''); - return validateIsUrl(href) && (href.match(/youtube\.com|youtu\.be/) || href.match(/vimeo\.com/) || href.match(/cloudinary\.com/)); + return validateIsUrl(href) && ( + href.match(/youtube\.com|youtu\.be/) || + href.match(/vimeo\.com/) || + href.match(/cloudinary\.com/) || + href.match(/\.(mp4|ogv|webm)(?!\w)/) + ); + }, + $.mage.__('Please enter a valid video URL. Valid URLs have a video file extension (.mp4, .webm, .ogv) or links to videos on YouTube, Vimeo or Cloudinary.')//eslint-disable-line max-len + ); + + validator.addRule( + 'validate-video-source', + function (href) { + if (utils.isEmptyNoTrim(href)) { + return true; + } + + href = (href || '').replace(/^\s+/, '').replace(/\s+$/, ''); + + return validateIsUrl(href) && ( + href.match(/youtube\.com|youtu\.be/) || + href.match(/vimeo\.com/) || + href.match(/cloudinary\.com/) || + href.match(/\.(mp4|ogv|webm)(?!\w)/) + ); }, - $.mage.__('Please enter a valid video URL.') + $.mage.__('Please enter a valid video URL. Valid URLs have a video file extension (.mp4, .webm, .ogv) or links to videos on YouTube, Vimeo or Cloudinary.')//eslint-disable-line max-len ); + return validator; }; -}); \ No newline at end of file +}); From 23b75cad89ea5cb49744614f88044baa8159d482 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Thu, 16 Dec 2021 17:33:09 +0200 Subject: [PATCH 10/11] MAG-777: Improved URL encoding-decoding on admin JS --- view/adminhtml/web/js/cloudinary-media-library-modal.js | 6 +++--- view/adminhtml/web/js/get-video-information.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/view/adminhtml/web/js/cloudinary-media-library-modal.js b/view/adminhtml/web/js/cloudinary-media-library-modal.js index 2377a509..fde8b08e 100644 --- a/view/adminhtml/web/js/cloudinary-media-library-modal.js +++ b/view/adminhtml/web/js/cloudinary-media-library-modal.js @@ -115,7 +115,7 @@ define([ asset.asset_derived_image_url .replace(new RegExp('^.*cloudinary.com/(' + this.options.cloudinaryMLoptions.cloud_name + '/)?' + asset.resource_type + '/' + asset.type + '/'), '') .replace(/\.[^/.]+$/, '') - .replace(new RegExp('\/' + widget.escapeRegex(encodeURI(asset.public_id)) + '$'), '') + .replace(new RegExp('\/' + widget.escapeRegex(encodeURI(decodeURI(asset.public_id))) + '$'), '') .replace(new RegExp('\/v[0-9]{1,10}$'), '') .replace(new RegExp('\/'), ','); if (widget.options.useDerived) { @@ -126,7 +126,7 @@ define([ asset.asset_image_url = asset.asset_url .replace(/\.[^/.]+$/, "") .replace(new RegExp('\/v[0-9]{1,10}\/'), '/') - .replace(new RegExp('\/(' + widget.escapeRegex(encodeURI(asset.public_id)) + ')$'), '/so_auto/$1.jpg'); + .replace(new RegExp('\/(' + widget.escapeRegex(encodeURI(decodeURI(asset.public_id))) + ')$'), '/so_auto/$1.jpg'); } $.ajax({ url: widget.options.imageUploaderUrl, @@ -212,4 +212,4 @@ define([ }); return $.mage.cloudinaryMediaLibraryModal; -}); \ No newline at end of file +}); diff --git a/view/adminhtml/web/js/get-video-information.js b/view/adminhtml/web/js/get-video-information.js index 9cee8d72..64c741cd 100644 --- a/view/adminhtml/web/js/get-video-information.js +++ b/view/adminhtml/web/js/get-video-information.js @@ -641,7 +641,7 @@ define( thumbnail = videoInfo.videoSrc .replace(/\.[^/.]+$/, "") .replace(new RegExp('\/v[0-9]{1,10}\/'), '/') - .replace(new RegExp('\/(' + this._escapeRegex(encodeURI(tmp.public_id)) + ')$'), '/so_auto/$1.jpg'); + .replace(new RegExp('\/(' + this._escapeRegex(encodeURI(decodeURI(tmp.public_id))) + ')$'), '/so_auto/$1.jpg'); //Fallback for video thumbnail image, use placeholder or store logo $.ajax({ @@ -871,4 +871,4 @@ define( } ); } -); \ No newline at end of file +); From 167c4fbbb006095e27499d153c8a4e7dbd701825 Mon Sep 17 00:00:00 2001 From: pniel-cohen Date: Sun, 19 Dec 2021 16:18:35 +0200 Subject: [PATCH 11/11] MAG-777: Updated js parts for get-video-information after Magento core changes --- .../adminhtml/web/js/get-video-information.js | 130 +++++++----------- view/adminhtml/web/js/new-video-dialog.js | 8 +- 2 files changed, 56 insertions(+), 82 deletions(-) diff --git a/view/adminhtml/web/js/get-video-information.js b/view/adminhtml/web/js/get-video-information.js index 64c741cd..db001c90 100644 --- a/view/adminhtml/web/js/get-video-information.js +++ b/view/adminhtml/web/js/get-video-information.js @@ -110,44 +110,45 @@ define( /** * Abstract play command */ - play: function() { + play: function () { this._player.play(); }, /** * Abstract pause command */ - pause: function() { + pause: function () { this._player.pause(); }, /** * Abstract stop command */ - stop: function() { + stop: function () { this._player.stop(); }, /** * Abstract playing command */ - playing: function() { + playing: function () { return this._player.playing(); }, /** * Abstract destroying command */ - destroy: function() { - this._player.destroy(); + destroy: function () { + if (this._player) { + this._player.destroy(); + } }, /** * Calculates ratio for responsive videos - * * @private */ - _calculateRatio: function() { + _calculateRatio: function () { if (!this._responsive) { return; } @@ -314,43 +315,40 @@ define( } ); - $.widget( - 'mage.videoVimeo', $.mage.productVideoLoader, { + $.widget('mage.videoVimeo', $.mage.productVideoLoader, { - /** - * Initialize the Vimeo widget - * - * @private - */ - _create: function() { - var timestamp, - src, - additionalParams; + /** + * Initialize the Vimeo widget + * @private + */ + _create: function () { + var timestamp, + src, + additionalParams; - this._initialize(); - timestamp = new Date().getTime(); + this._initialize(); + timestamp = new Date().getTime(); - if (this._autoplay) { - additionalParams += '&autoplay=1'; - } + if (this._autoplay) { + additionalParams += '&autoplay=1'; + } - src = 'https://player.vimeo.com/video/' + - this._code + '?api=1&player_id=vimeo' + - this._code + - timestamp + - additionalParams; - this.element.append( - $('