Skip to content

Commit 752c8b2

Browse files
committed
Merge remote-tracking branch 'magento2/develop' into MAGETWO-48048
2 parents 6bb0840 + 3fa0347 commit 752c8b2

File tree

134 files changed

+2525
-1057
lines changed

Some content is hidden

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

134 files changed

+2525
-1057
lines changed

app/code/Magento/Braintree/Observer/DataAssignObserver.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Event\Observer;
99
use Magento\Payment\Observer\AbstractDataAssignObserver;
10+
use Magento\Quote\Api\Data\PaymentInterface;
1011

1112
/**
1213
* Class DataAssignObserver
@@ -31,13 +32,19 @@ class DataAssignObserver extends AbstractDataAssignObserver
3132
public function execute(Observer $observer)
3233
{
3334
$data = $this->readDataArgument($observer);
35+
36+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
37+
if (!is_array($additionalData)) {
38+
return;
39+
}
40+
3441
$paymentInfo = $this->readPaymentModelArgument($observer);
3542

3643
foreach ($this->additionalInformationList as $additionalInformationKey) {
37-
if ($data->getDataByKey($additionalInformationKey) !== null) {
44+
if (isset($additionalData[$additionalInformationKey])) {
3845
$paymentInfo->setAdditionalInformation(
3946
$additionalInformationKey,
40-
$data->getDataByKey($additionalInformationKey)
47+
$additionalData[$additionalInformationKey]
4148
);
4249
}
4350
}

app/code/Magento/Braintree/Test/Unit/Observer/DataAssignObserverTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Payment\Model\InfoInterface;
1111
use Magento\Payment\Observer\AbstractDataAssignObserver;
1212
use Magento\Braintree\Observer\DataAssignObserver;
13+
use Magento\Quote\Api\Data\PaymentInterface;
1314

1415
/**
1516
* Class DataAssignObserverTest
@@ -30,8 +31,10 @@ public function testExecute()
3031
$paymentInfoModel = $this->getMock(InfoInterface::class);
3132
$dataObject = new DataObject(
3233
[
33-
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
34-
'device_data' => self::DEVICE_DATA,
34+
PaymentInterface::KEY_ADDITIONAL_DATA => [
35+
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
36+
'device_data' => self::DEVICE_DATA
37+
]
3538
]
3639
);
3740
$observerContainer->expects(static::atLeastOnce())

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,40 @@ public function getAddImagesButton()
122122
*/
123123
public function getImagesJson()
124124
{
125-
if (is_array($this->getElement()->getImages())) {
126-
$value = $this->getElement()->getImages();
125+
$value = $this->getElement()->getImages();
126+
if (is_array($value) &&
127+
array_key_exists('images', $value) &&
128+
is_array($value['images']) &&
129+
count($value['images'])
130+
) {
127131
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
128-
if (is_array($value['images']) && count($value['images']) > 0) {
129-
foreach ($value['images'] as &$image) {
130-
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
131-
$fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
132-
$image['size'] = $fileHandler['size'];
133-
}
134-
return $this->_jsonEncoder->encode($value['images']);
132+
$images = $this->sortImagesByPosition($value['images']);
133+
foreach ($images as &$image) {
134+
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
135+
$fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
136+
$image['size'] = $fileHandler['size'];
135137
}
138+
return $this->_jsonEncoder->encode($images);
136139
}
137140
return '[]';
138141
}
139142

143+
/**
144+
* Sort images array by position key
145+
*
146+
* @param array $images
147+
* @return array
148+
*/
149+
private function sortImagesByPosition($images)
150+
{
151+
if (is_array($images)) {
152+
usort($images, function ($imageA, $imageB) {
153+
return ($imageA['position'] < $imageB['position']) ? -1 : 1;
154+
});
155+
}
156+
return $images;
157+
}
158+
140159
/**
141160
* @return string
142161
*/

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public function copy(\Magento\Catalog\Model\Product $product)
4747
$product->getWebsiteIds();
4848
$product->getCategoryIds();
4949

50+
/** @var \Magento\Catalog\Model\Product $duplicate */
5051
$duplicate = $this->productFactory->create();
5152
$duplicate->setData($product->getData());
53+
$duplicate->setOptions([]);
5254
$duplicate->setIsDuplicate(true);
5355
$duplicate->setOriginalId($product->getEntityId());
5456
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);

app/code/Magento/Catalog/Model/Product/Option/Type/File/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
\Magento\Framework\File\Size $fileSize
3939
) {
4040
$this->scopeConfig = $scopeConfig;
41-
$this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
41+
$this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
4242
$this->fileSize = $fileSize;
4343
}
4444

app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Category\Collection;
77

8+
/**
9+
* Class Factory
10+
* @deprecated
11+
*/
812
class Factory
913
{
1014
/**

app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Catalog\Model\ResourceModel\Category;
77

88
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
9+
use Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory as CategoryFlatCollectionFactory;
10+
use Magento\Framework\App\ObjectManager;
911

1012
/**
1113
* Category flat model
@@ -68,6 +70,7 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource
6870
* Category collection factory
6971
*
7072
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
73+
* @deprecated
7174
*/
7275
protected $_categoryCollectionFactory;
7376

@@ -78,6 +81,11 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource
7881
*/
7982
protected $_categoryFactory;
8083

84+
/**
85+
* @var CategoryFlatCollectionFactory
86+
*/
87+
private $categoryFlatCollectionFactory;
88+
8189
/**
8290
* Class constructor
8391
*
@@ -399,7 +407,7 @@ public function getCategories($parent, $recursionLevel = 0, $sorted = false, $as
399407
);
400408
$parentPath = $this->getConnection()->fetchOne($select);
401409

402-
$collection = $this->_categoryCollectionFactory
410+
$collection = $this->getCategoryFlatCollectionFactory()
403411
->create()
404412
->addNameToResult()
405413
->addUrlRewriteToResult()
@@ -690,4 +698,19 @@ public function getProductsPosition($category)
690698

691699
return $this->getConnection()->fetchPairs($select, $bind);
692700
}
701+
702+
/**
703+
* Get instance of CategoryFlatCollectionFactory
704+
*
705+
* @return CategoryFlatCollectionFactory
706+
*/
707+
private function getCategoryFlatCollectionFactory()
708+
{
709+
if (!$this->categoryFlatCollectionFactory instanceof CategoryFlatCollectionFactory) {
710+
$this->categoryFlatCollectionFactory = ObjectManager::getInstance()
711+
->get(CategoryFlatCollectionFactory::class);
712+
}
713+
714+
return $this->categoryFlatCollectionFactory;
715+
}
693716
}

app/code/Magento/Catalog/Model/Webapi/Product/Option/Type/File/Processor.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Api\Data\ImageContentInterface;
10-
use Magento\Catalog\Model\Product\Option\Type\File\ValidateFactory;
1110
use Magento\Framework\Api\ImageProcessor;
1211
use Magento\Framework\Filesystem;
1312

@@ -20,7 +19,7 @@ class Processor
2019
protected $imageProcessor;
2120

2221
/** @var string */
23-
protected $destinationFolder = '/custom_options/quote';
22+
protected $destinationFolder = 'custom_options/quote';
2423

2524
/**
2625
* @param Filesystem $filesystem
@@ -40,9 +39,8 @@ public function __construct(
4039
*/
4140
protected function saveFile(ImageContentInterface $imageContent)
4241
{
43-
$uri = $this->filesystem->getUri(DirectoryList::MEDIA);
4442
$filePath = $this->imageProcessor->processImageContent($this->destinationFolder, $imageContent);
45-
return $uri . $this->destinationFolder . $filePath;
43+
return $this->destinationFolder . $filePath;
4644
}
4745

4846
/**
@@ -54,8 +52,8 @@ public function processFileContent(ImageContentInterface $imageContent)
5452
{
5553
$filePath = $this->saveFile($imageContent);
5654

57-
$fileAbsolutePath = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath($filePath);
58-
$fileHash = md5($this->filesystem->getDirectoryRead(DirectoryList::ROOT)->readFile($filePath));
55+
$fileAbsolutePath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($filePath);
56+
$fileHash = md5($this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->readFile($filePath));
5957
$imageSize = getimagesize($fileAbsolutePath);
6058
$result = [
6159
'type' => $imageContent->getType(),

app/code/Magento/Catalog/Model/Webapi/Product/Option/Type/File/Validator.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,59 @@ public function testGetImagesJson()
8282
['file_1.jpg', 'catalog/product/image_1.jpg'],
8383
['file_2.jpg', 'catalog/product/image_2.jpg']
8484
];
85-
// @codingStandardsIgnoreStart
86-
$encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\/\/magento2.dev\/pub\/media\/catalog\/product\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\/\/magento2.dev\/pub\/media\/catalog\/product\/image`_2.jpg","size":399659}]';
87-
// @codingStandardsIgnoreEnd
85+
86+
$sizeMap = [
87+
['catalog/product/image_1.jpg', ['size' => 399659]],
88+
['catalog/product/image_2.jpg', ['size' => 879394]]
89+
];
90+
91+
$imagesResult = [
92+
[
93+
'value_id' => '2',
94+
'file' => 'file_2.jpg',
95+
'media_type' => 'image',
96+
'position' => '0',
97+
'url' => 'url_to_the_image/image_2.jpg',
98+
'size' => 879394
99+
],
100+
[
101+
'value_id' => '1',
102+
'file' => 'file_1.jpg',
103+
'media_type' => 'image',
104+
'position' => '1',
105+
'url' => 'url_to_the_image/image_1.jpg',
106+
'size' => 399659
107+
]
108+
];
109+
88110
$images = [
89111
'images' => [
90112
[
91113
'value_id' => '1',
92114
'file' => 'file_1.jpg',
93115
'media_type' => 'image',
116+
'position' => '1'
94117
] ,
95118
[
96119
'value_id' => '2',
97120
'file' => 'file_2.jpg',
98121
'media_type' => 'image',
122+
'position' => '0'
99123
]
100124
]
101125
];
102-
$firstStat = ['size' => 879394];
103-
$secondStat = ['size' => 399659];
126+
104127
$this->content->setElement($this->galleryMock);
105-
$this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
128+
$this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
106129
$this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
107130

108131
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
109-
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
132+
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
110133

111-
$this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
112-
$this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
113-
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
134+
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
135+
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
114136

115-
$this->assertSame($encodedString, $this->content->getImagesJson());
137+
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
116138
}
117139

118140
public function testGetImagesJsonWithoutImages()

0 commit comments

Comments
 (0)