Skip to content

Commit

Permalink
Merge branch '2.4-develop' into bundle-products-fixed-cart-discount
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Hotel authored Nov 27, 2020
2 parents b4275c9 + 8c95f07 commit aa7e7cd
Show file tree
Hide file tree
Showing 70 changed files with 1,922 additions and 440 deletions.
7 changes: 7 additions & 0 deletions app/code/Magento/Analytics/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
<token/>
</general>
</analytics>
<system>
<media_storage_configuration>
<allowed_resources>
<analytics_folder>analytics</analytics_folder>
</allowed_resources>
</media_storage_configuration>
</system>
</default>
</config>
3 changes: 2 additions & 1 deletion app/code/Magento/AwsS3/Driver/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
* Resolves relative path.
*
* @param string $path Absolute path
* @param bool $fixPath
* @return string Relative path
*/
private function normalizeRelativePath(string $path, bool $fixPath = false): string
Expand Down Expand Up @@ -358,7 +359,7 @@ public function isFile($path): bool
return false;
}

$path = $this->normalizeRelativePath($path, true);;
$path = $this->normalizeRelativePath($path, true);

if ($this->adapter->has($path) && ($meta = $this->adapter->getMetadata($path))) {
return ($meta['type'] ?? null) === self::TYPE_FILE;
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/AwsS3/Driver/AwsS3Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function createConfigured(
throw new DriverException(__('Bucket and region are required values'));
}

if (!empty($config['http_handler'])) {
$config['http_handler'] = $this->objectManager->create($config['http_handler'])($config);
}

$client = new S3Client($config);
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);

Expand Down
61 changes: 61 additions & 0 deletions app/code/Magento/AwsS3/Model/HttpLoggerHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AwsS3\Model;

use Aws\Handler\GuzzleV6\GuzzleHandler;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

final class HttpLoggerHandler
{
/**
* @var Filesystem\Directory\WriteInterface
*/
private $directory;

/**
* @var string
*/
private $file;

/**
* @param Filesystem $filesystem
* @param string $file
* @throws FileSystemException
*/
public function __construct(
Filesystem $filesystem,
$file = 'debug/s3.log'
) {
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->file = $file;
}

public function __invoke()
{
$this->directory->create(pathinfo($this->file, PATHINFO_DIRNAME));
$localStream = $this->directory->getDriver()->fileOpen($this->directory->getAbsolutePath($this->file), 'a');
$streamHandler = new StreamHandler($localStream, Logger::DEBUG, true, null, true);
$logger = new \Monolog\Logger('S3', [$streamHandler]);
$stack = HandlerStack::create();
$stack->push(
Middleware::log(
$logger,
new MessageFormatter('{code}:{method}:{target} {error}')
)
);
return new GuzzleHandler(new Client(['handler' => $stack]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Model\Sales\Order\Shipment;

use Magento\Catalog\Model\Product\Type;
use Magento\Sales\Model\ValidatorInterface;

/**
* Validate if requested order items can be shipped according to bundle product shipment type
*/
class BundleShipmentTypeValidator implements ValidatorInterface
{
/**
* @inheritdoc
*/
public function validate($item)
{
$result = [];
if (!$item->isDummy(true)) {
return $result;
}

$message = 'Cannot create shipment as bundle product "%1" has shipment type "%2". ' .
'%3 should be shipped instead.';

if ($item->getHasChildren() && $item->getProductType() === Type::TYPE_BUNDLE) {
$result[] = __(
$message,
$item->getSku(),
__('Separately'),
__('Bundle product options'),
);
}

if ($item->getParentItem() && $item->getParentItem()->getProductType() === Type::TYPE_BUNDLE) {
$result[] = __(
$message,
$item->getParentItem()->getSku(),
__('Together'),
__('Bundle product itself'),
);
}

return $result;
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidator">
<arguments>
<argument name="validators" xsi:type="array">
<item name="shipment_type" xsi:type="object">Magento\Bundle\Model\Sales\Order\Shipment\BundleShipmentTypeValidator</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Bundle/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ Select...,Select...
Status,Status
Thumbnail,Thumbnail
Type,Type
"Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead.","Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead."
"Bundle product itself","Bundle product itself"
"Bundle product options","Bundle product options"
25 changes: 5 additions & 20 deletions app/code/Magento/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
use Magento\Catalog\Model\View\Asset\ImageFactory;
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Image as MagentoImage;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
use Magento\Framework\Filesystem\Driver\File as FilesystemDriver;

/**
* Image operations
Expand Down Expand Up @@ -202,11 +200,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
*/
private $serializer;

/**
* @var FilesystemDriver
*/
private $filesystemDriver;

/**
* Constructor
*
Expand All @@ -227,7 +220,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
* @param array $data
* @param SerializerInterface $serializer
* @param ParamsBuilder $paramsBuilder
* @param FilesystemDriver $filesystemDriver
* @throws \Magento\Framework\Exception\FileSystemException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
Expand All @@ -249,8 +241,7 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
SerializerInterface $serializer = null,
ParamsBuilder $paramsBuilder = null,
FilesystemDriver $filesystemDriver = null
ParamsBuilder $paramsBuilder = null
) {
$this->_storeManager = $storeManager;
$this->_catalogProductMediaConfig = $catalogProductMediaConfig;
Expand All @@ -265,7 +256,6 @@ public function __construct(
$this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->paramsBuilder = $paramsBuilder ?: ObjectManager::getInstance()->get(ParamsBuilder::class);
$this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance()->get(FilesystemDriver::class);
}

/**
Expand Down Expand Up @@ -675,12 +665,7 @@ public function getDestinationSubdir()
public function isCached()
{
$path = $this->imageAsset->getPath();
try {
$isCached = is_array($this->loadImageInfoFromCache($path)) || $this->filesystemDriver->isExists($path);
} catch (FileSystemException $e) {
$isCached = false;
}
return $isCached;
return is_array($this->loadImageInfoFromCache($path)) || $this->_mediaDirectory->isExist($path);
}

/**
Expand Down Expand Up @@ -952,7 +937,7 @@ private function getImageSize($imagePath)
*/
private function saveImageInfoToCache(array $imageInfo, string $imagePath)
{
$imagePath = $this->cachePrefix . $imagePath;
$imagePath = $this->cachePrefix . $imagePath;
$this->_cacheManager->save(
$this->serializer->serialize($imageInfo),
$imagePath,
Expand All @@ -968,7 +953,7 @@ private function saveImageInfoToCache(array $imageInfo, string $imagePath)
*/
private function loadImageInfoFromCache(string $imagePath)
{
$imagePath = $this->cachePrefix . $imagePath;
$imagePath = $this->cachePrefix . $imagePath;
$cacheData = $this->_cacheManager->load($imagePath);
if (!$cacheData) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<severity value="BLOCKER"/>
<testCaseId value="MC-10895"/>
<group value="Catalog"/>
<skip>
<issueId value="MC-13817"/>
</skip>
<group value="mtf_migrated"/>
</annotations>

Expand All @@ -35,8 +32,9 @@
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<!--Generate date for use as default value, needs to be MM/d/YYYY -->
<!--Generate date for use as default value, needs to be MM/d/YYYY and mm/d/yy-->
<generateDate date="now" format="m/j/Y" stepKey="generateDefaultDate"/>
<generateDate date="now" format="m/j/y" stepKey="generateDateCompressedFormat"/>

<!--Navigate to Stores > Attributes > Product.-->
<actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="goToProductAttributes"/>
Expand All @@ -57,7 +55,7 @@
<seeOptionIsSelected stepKey="assertInputType" selector="{{AttributePropertiesSection.InputType}}" userInput="{{dateProductAttribute.frontend_input}}"/>
<seeOptionIsSelected stepKey="assertRequired" selector="{{AttributePropertiesSection.ValueRequired}}" userInput="{{dateProductAttribute.is_required_admin}}"/>
<seeInField stepKey="assertAttrCode" selector="{{AdvancedAttributePropertiesSection.AttributeCode}}" userInput="{{dateProductAttribute.attribute_code}}"/>
<seeInField stepKey="assertDefaultValue" selector="{{AdvancedAttributePropertiesSection.DefaultValueDate}}" userInput="{$generateDefaultDate}"/>
<seeInField stepKey="assertDefaultValue" selector="{{AdvancedAttributePropertiesSection.DefaultValueDate}}" userInput="{$generateDateCompressedFormat}"/>

<!--Go to New Product page, add Attribute and check values-->
<amOnPage url="{{AdminProductCreatePage.url('4', 'simple')}}" stepKey="goToCreateSimpleProductPage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ protected function setUp(): void

$this->productFactory = $this->getMockBuilder(
\Magento\Catalog\Model\ResourceModel\ProductFactory::class
)->addMethods(['getTypeId'])
)->disableOriginalConstructor()
->addMethods(['getTypeId'])
->onlyMethods(['create'])
->getMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Magento\Quote\Model\ShippingAssignmentFactory;
use Magento\Quote\Model\ShippingFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -148,7 +149,7 @@ protected function setUp(): void
'importCustomerAddressData',
'save',
'getShippingRateByCode',
'getShippingMethod'
'getShippingMethod',
]
)
->disableOriginalConstructor()
Expand All @@ -167,7 +168,7 @@ protected function setUp(): void
'collectTotals',
'getExtensionAttributes',
'setExtensionAttributes',
'setBillingAddress'
'setBillingAddress',
]
)
->disableOriginalConstructor()
Expand Down Expand Up @@ -238,9 +239,7 @@ private function setShippingAssignmentsMocks($shippingMethod): void
->willReturn(null);
$this->shippingAddressMock->expects($this->once())
->method('setLimitCarrier');
$this->cartExtensionMock = $this->getMockBuilder(CartExtension::class)
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
->getMock();
$this->cartExtensionMock = $this->getCartExtensionMock();
$this->cartExtensionFactoryMock->expects($this->once())
->method('create')
->willReturn($this->cartExtensionMock);
Expand Down Expand Up @@ -622,4 +621,21 @@ public function testSaveAddressInformation(): void
$this->model->saveAddressInformation($cartId, $addressInformationMock)
);
}

/**
* Build cart extension mock.
*
* @return MockObject
*/
private function getCartExtensionMock(): MockObject
{
$mockBuilder = $this->getMockBuilder(CartExtension::class);
try {
$mockBuilder->addMethods(['getShippingAssignments', 'setShippingAssignments']);
} catch (RuntimeException $e) {
// CartExtension already generated.
}

return $mockBuilder->getMock();
}
}
Loading

0 comments on commit aa7e7cd

Please sign in to comment.