Skip to content

Commit 2b144f9

Browse files
author
Prabhu Ram
committed
Merge remote-tracking branch 'mainline/2.4-develop' into compare-products
2 parents 8aadac8 + f55f411 commit 2b144f9

File tree

58 files changed

+2051
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2051
-542
lines changed

app/code/Magento/AwsS3/Driver/AwsS3.php

Lines changed: 107 additions & 71 deletions
Large diffs are not rendered by default.

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
use Aws\S3\S3Client;
1111
use League\Flysystem\AwsS3v3\AwsS3Adapter;
12+
use League\Flysystem\Cached\CachedAdapter;
13+
use Magento\Framework\Exception\LocalizedException;
1214
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\RemoteStorage\Driver\Cache\CacheFactory;
1316
use Magento\RemoteStorage\Driver\DriverException;
1417
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1518
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
19+
use Magento\RemoteStorage\Model\Config;
1620

1721
/**
1822
* Creates a pre-configured instance of AWS S3 driver.
@@ -24,19 +28,54 @@ class AwsS3Factory implements DriverFactoryInterface
2428
*/
2529
private $objectManager;
2630

31+
/**
32+
* @var CacheFactory
33+
*/
34+
private $cacheFactory;
35+
36+
/**
37+
* @var Config
38+
*/
39+
private $config;
40+
2741
/**
2842
* @param ObjectManagerInterface $objectManager
43+
* @param CacheFactory $cacheFactory
44+
* @param Config $config
2945
*/
30-
public function __construct(ObjectManagerInterface $objectManager)
46+
public function __construct(ObjectManagerInterface $objectManager, CacheFactory $cacheFactory, Config $config)
3147
{
3248
$this->objectManager = $objectManager;
49+
$this->cacheFactory = $cacheFactory;
50+
$this->config = $config;
3351
}
3452

3553
/**
3654
* @inheritDoc
3755
*/
38-
public function create(array $config, string $prefix): RemoteDriverInterface
56+
public function create(): RemoteDriverInterface
3957
{
58+
try {
59+
return $this->createConfigured(
60+
$this->config->getConfig(),
61+
$this->config->getPrefix(),
62+
$this->config->getCacheAdapter(),
63+
$this->config->getCacheConfig()
64+
);
65+
} catch (LocalizedException $exception) {
66+
throw new DriverException(__($exception->getMessage()), $exception);
67+
}
68+
}
69+
70+
/**
71+
* @inheritDoc
72+
*/
73+
public function createConfigured(
74+
array $config,
75+
string $prefix,
76+
string $cacheAdapter,
77+
array $cacheConfig
78+
): RemoteDriverInterface {
4079
$config['version'] = 'latest';
4180

4281
if (empty($config['credentials']['key']) || empty($config['credentials']['secret'])) {
@@ -53,7 +92,10 @@ public function create(array $config, string $prefix): RemoteDriverInterface
5392
return $this->objectManager->create(
5493
AwsS3::class,
5594
[
56-
'adapter' => $adapter,
95+
'adapter' => $this->objectManager->create(CachedAdapter::class, [
96+
'adapter' => $adapter,
97+
'cache' => $this->cacheFactory->create($cacheAdapter, $cacheConfig)
98+
]),
5799
'objectUrl' => $client->getObjectUrl($adapter->getBucket(), $adapter->applyPathPrefix('.'))
58100
]
59101
);

app/code/Magento/AwsS3/Test/Unit/Driver/AwsS3Test.php

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\AwsS3\Test\Unit\Driver;
99

10+
use League\Flysystem\AdapterInterface;
1011
use League\Flysystem\AwsS3v3\AwsS3Adapter;
11-
use League\Flysystem\Cached\CachedAdapter;
1212
use Magento\AwsS3\Driver\AwsS3;
1313
use Magento\Framework\Exception\FileSystemException;
1414
use PHPUnit\Framework\MockObject\MockObject;
@@ -37,7 +37,7 @@ class AwsS3Test extends TestCase
3737
*/
3838
protected function setUp(): void
3939
{
40-
$this->adapterMock = $this->createMock(CachedAdapter::class);
40+
$this->adapterMock = $this->getMockForAbstractClass(AdapterInterface::class);
4141
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
4242

4343
$this->driver = new AwsS3($this->adapterMock, $loggerMock, self::URL);
@@ -101,11 +101,6 @@ public function getAbsolutePathDataProvider(): array
101101
'test.txt',
102102
self::URL . 'test/test.txt'
103103
],
104-
[
105-
self::URL . 'media/',
106-
'media/image.jpg',
107-
self::URL . 'media/image.jpg'
108-
],
109104
[
110105
self::URL . 'media/',
111106
'/catalog/test.png',
@@ -140,6 +135,26 @@ public function getAbsolutePathDataProvider(): array
140135
self::URL . 'var/import/images/product_images/',
141136
self::URL . 'var/import/images/product_images/1.png',
142137
self::URL . 'var/import/images/product_images/1.png'
138+
],
139+
[
140+
self::URL . 'var/import/images/product_images/1.png',
141+
'',
142+
self::URL . 'var/import/images/product_images/1.png'
143+
],
144+
[
145+
self::URL . 'media/',
146+
'',
147+
self::URL . 'media/',
148+
],
149+
[
150+
self::URL . 'media/',
151+
self::URL . 'media',
152+
self::URL . 'media',
153+
],
154+
[
155+
self::URL,
156+
'',
157+
self::URL
143158
]
144159
];
145160
}
@@ -170,7 +185,7 @@ public function getRelativePathDataProvider(): array
170185
[
171186
'',
172187
'/test/test.txt',
173-
'test/test.txt'
188+
'/test/test.txt'
174189
],
175190
[
176191
self::URL,
@@ -216,14 +231,14 @@ public function isDirectoryDataProvider(): array
216231
return [
217232
[
218233
'some_directory/',
219-
'some_directory/',
234+
'some_directory',
220235
false,
221236
[],
222237
false
223238
],
224239
[
225240
'some_directory',
226-
'some_directory/',
241+
'some_directory',
227242
true,
228243
[
229244
'type' => AwsS3::TYPE_DIR
@@ -232,7 +247,7 @@ public function isDirectoryDataProvider(): array
232247
],
233248
[
234249
self::URL . 'some_directory',
235-
'some_directory/',
250+
'some_directory',
236251
true,
237252
[
238253
'type' => AwsS3::TYPE_DIR
@@ -241,7 +256,7 @@ public function isDirectoryDataProvider(): array
241256
],
242257
[
243258
self::URL . 'some_directory',
244-
'some_directory/',
259+
'some_directory',
245260
true,
246261
[
247262
'type' => AwsS3::TYPE_FILE
@@ -391,12 +406,12 @@ public function getRealPathSafetyDataProvider(): array
391406
public function testSearchDirectory(): void
392407
{
393408
$expression = '/*';
394-
$path = 'path/';
409+
$path = 'path';
395410
$subPaths = [
396-
['path' => 'path/1'],
397-
['path' => 'path/2']
411+
['path' => 'path/1', 'dirname' => self::URL],
412+
['path' => 'path/2', 'dirname' => self::URL]
398413
];
399-
$expectedResult = ['path/1', 'path/2'];
414+
$expectedResult = [self::URL . 'path/1', self::URL . 'path/2'];
400415
$this->adapterMock->expects(self::atLeastOnce())->method('has')
401416
->willReturnMap([
402417
[$path, true]
@@ -405,8 +420,10 @@ public function testSearchDirectory(): void
405420
->willReturnMap([
406421
[$path, ['type' => AwsS3::TYPE_DIR]]
407422
]);
408-
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')->with($path, false)
423+
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')
424+
->with($path, false)
409425
->willReturn($subPaths);
426+
410427
self::assertEquals($expectedResult, $this->driver->search($expression, $path));
411428
}
412429

@@ -415,13 +432,13 @@ public function testSearchDirectory(): void
415432
*/
416433
public function testSearchFiles(): void
417434
{
418-
$expression = "/*";
419-
$path = 'path/';
435+
$expression = '/*';
436+
$path = 'path';
420437
$subPaths = [
421-
['path' => 'path/1.jpg'],
422-
['path' => 'path/2.png']
438+
['path' => 'path/1.jpg', 'dirname' => self::URL],
439+
['path' => 'path/2.png', 'dirname' => self::URL]
423440
];
424-
$expectedResult = ['path/1.jpg', 'path/2.png'];
441+
$expectedResult = [self::URL . 'path/1.jpg', self::URL . 'path/2.png'];
425442

426443
$this->adapterMock->expects(self::atLeastOnce())->method('has')
427444
->willReturnMap([
@@ -433,6 +450,31 @@ public function testSearchFiles(): void
433450
]);
434451
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')->with($path, false)
435452
->willReturn($subPaths);
453+
436454
self::assertEquals($expectedResult, $this->driver->search($expression, $path));
437455
}
456+
457+
/**
458+
* @throws FileSystemException
459+
*/
460+
public function testCreateDirectory(): void
461+
{
462+
$this->adapterMock->expects(self::exactly(2))
463+
->method('has')
464+
->willReturnMap([
465+
['test', true],
466+
['test/test2', false]
467+
]);
468+
$this->adapterMock->expects(self::once())
469+
->method('getMetadata')
470+
->willReturnMap([
471+
['test', ['type' => AwsS3::TYPE_DIR]]
472+
]);
473+
$this->adapterMock->expects(self::once())
474+
->method('createDir')
475+
->with('test/test2')
476+
->willReturn(true);
477+
478+
self::assertTrue($this->driver->createDirectory(self::URL . 'test/test2/'));
479+
}
438480
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Model\Sales\Order\Shipment;
9+
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Sales\Model\ValidatorInterface;
12+
13+
/**
14+
* Validate if requested order items can be shipped according to bundle product shipment type
15+
*/
16+
class BundleShipmentTypeValidator implements ValidatorInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function validate($item)
22+
{
23+
$result = [];
24+
if (!$item->isDummy(true)) {
25+
return $result;
26+
}
27+
28+
$message = 'Cannot create shipment as bundle product "%1" has shipment type "%2". ' .
29+
'%3 should be shipped instead.';
30+
31+
if ($item->getHasChildren() && $item->getProductType() === Type::TYPE_BUNDLE) {
32+
$result[] = __(
33+
$message,
34+
$item->getSku(),
35+
__('Separately'),
36+
__('Bundle product options'),
37+
);
38+
}
39+
40+
if ($item->getParentItem() && $item->getParentItem()->getProductType() === Type::TYPE_BUNDLE) {
41+
$result[] = __(
42+
$message,
43+
$item->getParentItem()->getSku(),
44+
__('Together'),
45+
__('Bundle product itself'),
46+
);
47+
}
48+
49+
return $result;
50+
}
51+
}

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,11 @@
234234
</argument>
235235
</arguments>
236236
</type>
237+
<type name="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidator">
238+
<arguments>
239+
<argument name="validators" xsi:type="array">
240+
<item name="shipment_type" xsi:type="object">Magento\Bundle\Model\Sales\Order\Shipment\BundleShipmentTypeValidator</item>
241+
</argument>
242+
</arguments>
243+
</type>
237244
</config>

app/code/Magento/Bundle/i18n/en_US.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ Select...,Select...
105105
Status,Status
106106
Thumbnail,Thumbnail
107107
Type,Type
108+
"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."
109+
"Bundle product itself","Bundle product itself"
110+
"Bundle product options","Bundle product options"

app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityDateTest.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<severity value="BLOCKER"/>
1717
<testCaseId value="MC-10895"/>
1818
<group value="Catalog"/>
19-
<skip>
20-
<issueId value="MC-13817"/>
21-
</skip>
2219
<group value="mtf_migrated"/>
2320
</annotations>
2421

@@ -35,8 +32,9 @@
3532
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
3633
</after>
3734

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

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

6260
<!--Go to New Product page, add Attribute and check values-->
6361
<amOnPage url="{{AdminProductCreatePage.url('4', 'simple')}}" stepKey="goToCreateSimpleProductPage"/>

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ protected function setUp(): void
172172

173173
$this->productFactory = $this->getMockBuilder(
174174
\Magento\Catalog\Model\ResourceModel\ProductFactory::class
175-
)->addMethods(['getTypeId'])
175+
)->disableOriginalConstructor()
176+
->addMethods(['getTypeId'])
176177
->onlyMethods(['create'])
177178
->getMock();
178179

0 commit comments

Comments
 (0)