Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Ajax/Free/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Core/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Helper/ProductGalleryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions Model/Config/Source/Dropdown/FreeTransformBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Cloudinary\Cloudinary\Model\Config\Source\Dropdown;

use Magento\Framework\Data\OptionSourceInterface;

class FreeTransformBehavior implements OptionSourceInterface
{
public function toOptionArray()
{
return [
[
'value' => 'add',
'label' => 'Add',
],
[
'value' => 'override',
'label' => 'Override',
],
];
}
}
45 changes: 36 additions & 9 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()));
}
Expand All @@ -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
*/
Expand Down Expand Up @@ -575,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,
Expand All @@ -593,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);

Expand Down
42 changes: 42 additions & 0 deletions Model/GraphQLResolver/ProductAttributeCldResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Cloudinary\Cloudinary\Model\GraphQLResolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Cloudinary\Cloudinary\Model\Api\ProductGalleryManagement;
use Magento\Framework\GraphQl\Type\Definition\ObjectType;

/**
* Class ProductAttributeCldResolver
**/
class ProductAttributeCldResolver implements ResolverInterface
{
/**
* @var ProductGalleryManagement
*/
private $productGalleryManagement;

/**
* ProductAttributeCldResolver constructor.
* @param ProductGalleryManagement $productGalleryManagement
*/
public function __construct(
ProductGalleryManagement $productGalleryManagement
) {
$this->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'];
}
}
4 changes: 2 additions & 2 deletions Plugin/Catalog/Block/Product/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ 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;
$this->keepFrame = (bool) $imageMiscParams['keep_frame'];
}

if ($this->keepFrame) {
Expand Down
4 changes: 2 additions & 2 deletions Plugin/Catalog/Model/Product/Image/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ 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;
$this->keepFrame = (bool) $imageMiscParams['keep_frame'];
}

if ($this->keepFrame) {
Expand Down
19 changes: 9 additions & 10 deletions Ui/DataProvider/Product/Form/Modifier/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
),
],
],
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
</field>
<field id="cloudinary_auto_upload_mapping_request" translate="label comment" type="select" sortOrder="3" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enable auto-upload</label>
<comment>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.</comment>
<comment><![CDATA[
<p class="note">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.</p>
<p class="note"><b>Note:</b> Disabling auto upload mapping from Magento will not remove the configuration from Cloudinary. To completely disable your auto upload mapping, navigate to your Cloudinary <a href="https://cloudinary.com/console/lui/settings/upload" target="_blank" title="Cloudinary Upload settings">Upload settings</a> and clear the <b>Auto upload mapping</b> that corresponds to your Magento URLs.</p>]]>
</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="cloudinary_auto_upload_mapping_button" translate="label comment" type="button" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0">
Expand Down Expand Up @@ -84,7 +87,20 @@
<label>Global Custom Transformation</label>
<comment><![CDATA[Add global custom transformations in addition to those selected above.<br>Custom transformations will be added to the default image transformations settings chosen above.<br>For information about the full range of transforms available see the <a href="http://cloudinary.com/documentation/image_transformation_reference" target="_blank" title="Cloudinary documentation">Cloudinary documentation</a>.<br>You may need to clear or rebuild the Magento block and full page caches to see the changes in the front end.]]></comment>
<backend_model>Cloudinary\Cloudinary\Model\Config\Backend\Free</backend_model>
<config_path>cloudinary/transformations/cloudinary_free_transform_global</config_path>
</field>
<field id="cloudinary_free_transform_global_products" translate="label comment" type="text" sortOrder="7" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Products Custom Transformation</label>
<comment><![CDATA[Same as "Global Custom Transformation" but <b>for products only</b>.<br>
*Set the behavior of this field on the dropdown below.]]></comment>
<backend_model>Cloudinary\Cloudinary\Model\Config\Backend\Free</backend_model>
<config_path>cloudinary/transformations/cloudinary_free_transform_global_products</config_path>
</field>
<field id="cloudinary_free_transform_global_products_behavior" translate="label comment" type="select" sortOrder="8" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Products Custom Transformation Behavior</label>
<source_model>Cloudinary\Cloudinary\Model\Config\Source\Dropdown\FreeTransformBehavior</source_model>
<frontend_model>Cloudinary\Cloudinary\Block\Adminhtml\Form\Field\Free</frontend_model>
<config_path>cloudinary/transformations/cloudinary_free_transform_global_products_behavior</config_path>
</field>
</group>
<group id="product_gallery" translate="label" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0">
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<cloudinary_fetch_format>1</cloudinary_fetch_format>
<cloudinary_image_quality>auto</cloudinary_image_quality>
<cloudinary_image_dpr>2.0</cloudinary_image_dpr>
<cloudinary_free_transform_global_products_behavior>add</cloudinary_free_transform_global_products_behavior>
</transformations>
<configuration>
<cloudinary_cdn_subdomain>1</cloudinary_cdn_subdomain>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Cloudinary_Cloudinary" setup_version="1.16.1">
<module name="Cloudinary_Cloudinary" setup_version="1.17.0">
<sequence>
<module name="Magento_ProductVideo"/>
<module name="Magento_PageBuilder"/>
Expand Down
12 changes: 12 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -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")
}
30 changes: 15 additions & 15 deletions marketplace.composer.json
Original file line number Diff line number Diff line change
@@ -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\\": ""
}
}
}
2 changes: 1 addition & 1 deletion view/adminhtml/templates/config/free.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

<div id="cloudinary_custom_transform_preview"
style="margin-top: 10px;"
data-mage-init='{"cloudinaryFreeTransform":{"previewButtonId": "#cloudinary_free_transform_preview_button", "transformInputFieldId": "#cloudinary_transformations_cloudinary_free_transform_global", "ajaxUrl": "<?= $this->getUrl('cloudinary/ajax_free/sample') ?>", "ajaxKey": "<?= $this->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": "<?= $this->getUrl('cloudinary/ajax_free/sample') ?>", "ajaxKey": "<?= $this->getFormKey() ?>"}}'>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd" extends="pagebuilder_base_form_with_background_attributes">
<fieldset name="background">
<field name="video_source">
<settings>
<tooltip>
<description translate="true">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)</description>
</tooltip>
</settings>
</field>
</fieldset>
</form>
Loading