Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-devel…
Browse files Browse the repository at this point in the history
…op latest changes

Accepted Community Pull Requests:
 - #30076: Reduced html content of image details templates (by @sivaschenko)
 - #29979: fix incorrect image size when rendition is inserted  (by @engcom-Golf)
 - #30044: #1832: Rename renditions stores config fieldset and add comments (by @joweecaquicla)
 - #29934: Fix gallery rendering on page load so current breakpoint configuration isn't replaced by any other configuration (by @Januszpl)
 - #25405: Fix inability to place PayPal guest order when Automatic Assignment to Customer Group is enabled (by @xylodev)
 - #25510: Fix for issue 25147 - Totals information management module - only set carrier/method code if set in address (by @joe-vortex)
 - #29274: Update Curl to respect case-insensitive headers (by @pmzandbergen)
 - #29542: Fix Parameter Tokenizer omitting first char of key (by @marvinhinz)


Fixed GitHub Issues:
 - #1806: how to use require_once in magento2 (reported by @LifeAsBook) has been fixed in #29979 by @engcom-Golf in 2.4-develop branch
   Related commits:
     1. 22da500
     2. b5180c0
     3. 7cfbc30
     4. 9a6bd96
     5. 9d0252a
     6. e832db8
     7. 1db2872
     8. 837dd9d
     9. 79ddf27
     10. 1535626
     11. cbc38f6
     12. 0cafa20
     13. ccd7251
     14. 35642f7
     15. f6f5a5e

 - #29933: Gallery multiply breakpoints options configuration doesn't work properly because of mediaCheck triggering exit media query function on page load (reported by @Januszpl) has been fixed in #29934 by @Januszpl in 2.4-develop branch
   Related commits:
     1. faf6dfa
     2. 9e53105
     3. a46a395
     4. c9b7a02

 - #25399: Unable to place a guest order with PayPal Express when Enable Automatic Assignment to Customer Group is enabled (reported by @xylodev) has been fixed in #25405 by @xylodev in 2.4-develop branch
   Related commits:
     1. 594fc93
     2. fb299a0
     3. f898245
     4. 7f280cd

 - #25147: Totals Information Management - setting quote shipping method when address method is null (reported by @joe-vortex) has been fixed in #25510 by @joe-vortex in 2.4-develop branch
   Related commits:
     1. a99d980
     2. 1900ffc
     3. 8820a5c
     4. b0e0517
     5. e4fb9d1

 - #29524: [Issue] Update Curl to respect case-insensitive headers (reported by @m2-assistant[bot]) has been fixed in #29274 by @pmzandbergen in 2.4-develop branch
   Related commits:
     1. 44d88e6
     2. ba6513f
     3. 730c495
     4. 552e0c1
     5. b5463b8
     6. e43e45f
     7. e1d21cd
     8. 9570f8f
     9. 9db1f83
     10. d61e030
     11. e912bdf
     12. d5c674d

 - #29185: \Magento\Framework\Filter\Template\Tokenizer\Parameter (reported by @bernd-reindl) has been fixed in #29542 by @marvinhinz in 2.4-develop branch
   Related commits:
     1. 4328a2d
     2. 55a1543
     3. 1b322f4
  • Loading branch information
magento-engcom-team authored Sep 18, 2020
2 parents 90ab6fc + 6e255c4 commit 28020ae
Show file tree
Hide file tree
Showing 30 changed files with 1,010 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<element name="selectFromGalleryButton" type="button" selector="//*[@class='file-uploader-area']/label[text()='Select from Gallery']"/>
<element name="uploadImageFile" type="input" selector=".file-uploader-area>input"/>
<element name="imageFileName" type="text" selector=".file-uploader-filename"/>
<element name="imageFileMeta" type="text" selector=".file-uploader-meta"/>
<element name="removeImageButton" type="button" selector=".file-uploader-summary .action-remove"/>
<element name="AddCMSBlock" type="select" selector="//*[@name='landing_page']"/>
<element name="description" type="input" selector="//*[@name='description']"/>
Expand Down
14 changes: 9 additions & 5 deletions app/code/Magento/Checkout/Model/TotalsInformationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Checkout\Model;

/**
* Class TotalsInformationManagement
* Class for management of totals information.
*/
class TotalsInformationManagement implements \Magento\Checkout\Api\TotalsInformationManagementInterface
{
Expand Down Expand Up @@ -38,7 +38,7 @@ public function __construct(
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function calculate(
$cartId,
Expand All @@ -52,16 +52,20 @@ public function calculate(
$quote->setBillingAddress($addressInformation->getAddress());
} else {
$quote->setShippingAddress($addressInformation->getAddress());
$quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
$addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
);
if ($addressInformation->getShippingCarrierCode() && $addressInformation->getShippingMethodCode()) {
$quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
$addressInformation->getShippingCarrierCode().'_'.$addressInformation->getShippingMethodCode()
);
}
}
$quote->collectTotals();

return $this->cartTotalRepository->get($cartId);
}

/**
* Check if quote have items.
*
* @param \Magento\Quote\Model\Quote $quote
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Checkout\Test\Unit\Model;

use Magento\Checkout\Api\Data\TotalsInformationInterface;
use Magento\Checkout\Model\TotalsInformationManagement;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\CartTotalRepositoryInterface;
use Magento\Quote\Model\Quote\Address;

class TotalsInformationManagementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var CartRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $cartRepositoryMock;

/**
* @var CartTotalRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $cartTotalRepositoryMock;

/**
* @var TotalsInformationManagement
*/
private $totalsInformationManagement;

protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->cartRepositoryMock = $this->createMock(
CartRepositoryInterface::class
);
$this->cartTotalRepositoryMock = $this->createMock(
CartTotalRepositoryInterface::class
);

$this->totalsInformationManagement = $this->objectManager->getObject(
TotalsInformationManagement::class,
[
'cartRepository' => $this->cartRepositoryMock,
'cartTotalRepository' => $this->cartTotalRepositoryMock,
]
);
}

/**
* Test for \Magento\Checkout\Model\TotalsInformationManagement::calculate.
*
* @param string|null $carrierCode
* @param string|null $carrierMethod
* @param int $methodSetCount
* @dataProvider dataProviderCalculate
*/
public function testCalculate(?string $carrierCode, ?string $carrierMethod, int $methodSetCount)
{
$cartId = 1;
$cartMock = $this->createMock(
\Magento\Quote\Model\Quote::class
);
$cartMock->expects($this->once())->method('getItemsCount')->willReturn(1);
$cartMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
$this->cartRepositoryMock->expects($this->once())->method('get')->with($cartId)->willReturn($cartMock);
$this->cartTotalRepositoryMock->expects($this->once())->method('get')->with($cartId);

$addressInformationMock = $this->createMock(
TotalsInformationInterface::class
);
$addressMock = $this->getMockBuilder(Address::class)
->addMethods(
[
'setShippingMethod',
'setCollectShippingRates',
]
)
->disableOriginalConstructor()
->getMock();

$addressInformationMock->expects($this->once())->method('getAddress')->willReturn($addressMock);
$addressInformationMock->expects($this->any())->method('getShippingCarrierCode')->willReturn($carrierCode);
$addressInformationMock->expects($this->any())->method('getShippingMethodCode')->willReturn($carrierMethod);
$cartMock->expects($this->once())->method('setShippingAddress')->with($addressMock);
$cartMock->expects($this->exactly($methodSetCount))->method('getShippingAddress')->willReturn($addressMock);
$addressMock->expects($this->exactly($methodSetCount))
->method('setCollectShippingRates')->with(true)->willReturn($addressMock);
$addressMock->expects($this->exactly($methodSetCount))
->method('setShippingMethod')->with($carrierCode . '_' . $carrierMethod);
$cartMock->expects($this->once())->method('collectTotals');

$this->totalsInformationManagement->calculate($cartId, $addressInformationMock);
}

/**
* Data provider for testCalculate.
*
* @return array
*/
public function dataProviderCalculate(): array
{
return [
[
null,
null,
0
],
[
null,
'carrier_method',
0
],
[
'carrier_code',
null,
0
],
[
'carrier_code',
'carrier_method',
1
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMediaGalleryInsertLargeImageFileSizeTest">
<annotations>
<features value="AdminMediaGalleryInsertLargeImageFileSizeTest"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1806"/>
<title value="Admin user should see correct image file size after rendition"/>
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1507933/scenarios/5200023"/>
<stories value="User inserts image rendition to the content"/>
<description value="Admin user should see correct image file size after rendition"/>
<severity value="AVERAGE"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="category"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<!-- Delete uploaded image -->
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPageFoDelete"/>
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItemForDelete">
<argument name="categoryName" value="$category.name$"/>
</actionGroup>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryForDelete"/>
<actionGroup ref="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup" stepKey="enableMassActionToDeleteImages"/>
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectSecondImageToDelete">
<argument name="imageName" value="{{ImageUpload.fileName}}"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clickDeleteSelectedButton"/>
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>

<!-- Delete category -->
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>

<!-- Open category page -->
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem">
<argument name="categoryName" value="$category.name$"/>
</actionGroup>

<!-- Add image to category from gallery -->
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGallery"/>
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="addCategoryImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectImage">
<argument name="imageName" value="{{ImageUpload.fileName}}"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="addSelected"/>


<!-- Assert added image size -->
<actionGroup ref="AdminAssertImageUploadFileSizeThanActionGroup" stepKey="assertSize">
<argument name="fileSize" value="26 KB"/>
</actionGroup>
</test>
</tests>
10 changes: 7 additions & 3 deletions app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
<system>
<section id="system">
<group id="media_gallery_renditions" translate="label" type="text" sortOrder="1010" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Media Gallery Renditions</label>
<label>Media Gallery Image Optimization</label>
<comment>Resize images to improve performance and decrease the file size. When you use an image from Media Gallery on the storefront, the smaller image is generated and placed instead of the original.
Changing these settings will update all generated images.</comment>
<field id="width" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Max Width</label>
<label>Maximum Width</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum width of an image in pixels.</comment>
</field>
<field id="height" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Max Height</label>
<label>Maximum Height</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum height of an image in pixels.</comment>
</field>
</group>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\MediaGalleryUi\Controller\Adminhtml\Image;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\MediaGalleryUi\Model\InsertImageData\GetInsertImageData;

/**
* OnInsert action returns on insert image details
*/
class OnInsert extends Action implements HttpPostActionInterface
{
/**
* @see _isAllowed()
*/
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::insert_assets';

/**
* @var JsonFactory
*/
private $resultJsonFactory;

/**
* @var GetInsertImageData
*/
private $getInsertImageData;

/**
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param GetInsertImageData $getInsertImageData
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
GetInsertImageData $getInsertImageData
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->getInsertImageData = $getInsertImageData;
}

/**
* Return a content (just a link or an html block) for inserting image to the content
*
* @return ResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getParams();
$insertImageData = $this->getInsertImageData->execute(
$data['filename'],
(bool)$data['force_static_path'],
(bool)$data['as_is'],
isset($data['store']) ? (int)$data['store'] : null
);

return $this->resultJsonFactory->create()->setData([
'content' => $insertImageData->getContent(),
'size' => $insertImageData->getSize(),
'type' => $insertImageData->getType(),
]);
}
}
Loading

0 comments on commit 28020ae

Please sign in to comment.