Skip to content

Commit 041f539

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'develop' of https://github.com/magento/magento2ce into MAGETWO-62468-1
2 parents e7934e0 + e7f5340 commit 041f539

File tree

57 files changed

+2207
-76
lines changed

Some content is hidden

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

57 files changed

+2207
-76
lines changed

app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ protected function processDeletedImages($product, array &$images)
2929
if (!empty($image['removed'])) {
3030
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
3131
$recordsToDelete[] = $image['value_id'];
32-
$filesToDelete[] = ltrim($image['file'], '/');
32+
// only delete physical files if they are not used by any other products
33+
if (!$this->resourceModel->countImageUses($image['file']) > 1) {
34+
$filesToDelete[] = ltrim($image['file'], '/');
35+
}
3336
}
3437
}
3538
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,16 +2195,22 @@ public function addMediaGalleryData()
21952195
$linkField = $this->getProductEntityMetadata()->getLinkField();
21962196
$items = $this->getItems();
21972197

2198-
$select->where('entity.' . $linkField . ' IN (?)', array_map(function ($item) {
2199-
return $item->getId();
2200-
}, $items));
2201-
2198+
$select->where(
2199+
'entity.' . $linkField . ' IN (?)',
2200+
array_map(
2201+
function ($item) use ($linkField) {
2202+
return $item->getData($linkField);
2203+
},
2204+
$items
2205+
)
2206+
);
22022207
foreach ($this->getConnection()->fetchAll($select) as $row) {
22032208
$mediaGalleries[$row[$linkField]][] = $row;
22042209
}
22052210

22062211
foreach ($items as $item) {
2207-
$mediaEntries = isset($mediaGalleries[$item->getId()]) ? $mediaGalleries[$item->getId()] : [];
2212+
$mediaEntries = isset($mediaGalleries[$item->getData($linkField)]) ?
2213+
$mediaGalleries[$item->getData($linkField)] : [];
22082214
$this->getGalleryReadHandler()->addMediaDataToProduct($item, $mediaEntries);
22092215
}
22102216

app/code/Magento/Catalog/Model/ResourceModel/Product/Gallery.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,21 @@ public function getProductImages($product, $storeIds)
449449

450450
return $this->getConnection()->fetchAll($select);
451451
}
452+
453+
/**
454+
* Counts uses of this image.
455+
*
456+
* @param string $image
457+
* @return int
458+
*/
459+
public function countImageUses($image)
460+
{
461+
$select = $this->getConnection()->select()
462+
->from([$this->getMainTableAlias() => $this->getMainTable()])
463+
->where(
464+
'value = ?',
465+
$image
466+
);
467+
return count($this->getConnection()->fetchAll($select));
468+
}
452469
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ public function testAddProductCategoriesFilter()
224224
public function testAddMediaGalleryData()
225225
{
226226
$attributeId = 42;
227-
$itemId = 4242;
228-
$linkField = 'entity_id';
229-
$mediaGalleriesMock = [[$linkField => $itemId]];
227+
$rowId = 4;
228+
$linkField = 'row_id';
229+
$mediaGalleriesMock = [[$linkField => $rowId]];
230230
$itemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
231231
->disableOriginalConstructor()
232+
->setMethods(['getData'])
232233
->getMock();
233234
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
234235
->disableOriginalConstructor()
@@ -248,13 +249,13 @@ public function testAddMediaGalleryData()
248249
$this->galleryResourceMock->expects($this->once())->method('createBatchBaseSelect')->willReturn($selectMock);
249250
$attributeMock->expects($this->once())->method('getAttributeId')->willReturn($attributeId);
250251
$this->entityMock->expects($this->once())->method('getAttribute')->willReturn($attributeMock);
251-
$itemMock->expects($this->atLeastOnce())->method('getId')->willReturn($itemId);
252-
$selectMock->expects($this->once())->method('where')->with('entity.' . $linkField . ' IN (?)', [$itemId]);
252+
$itemMock->expects($this->atLeastOnce())->method('getData')->willReturn($rowId);
253+
$selectMock->expects($this->once())->method('where')->with('entity.' . $linkField . ' IN (?)', [$rowId]);
253254
$this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadataMock);
254255
$metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
255256

256257
$this->connectionMock->expects($this->once())->method('fetchAll')->with($selectMock)->willReturn(
257-
[['entity_id' => $itemId]]
258+
[['row_id' => $rowId]]
258259
);
259260
$this->galleryReadHandlerMock->expects($this->once())->method('addMediaDataToProduct')
260261
->with($itemMock, $mediaGalleriesMock);

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/GalleryTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,33 @@ public function testDeleteGalleryValueInStore()
443443

444444
$this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId);
445445
}
446+
447+
public function testCountImageUses()
448+
{
449+
$results = [
450+
[
451+
'value_id' => '1',
452+
'attribute_id' => 90,
453+
'value' => '/d/o/download_7.jpg',
454+
'media_type' => 'image',
455+
'disabled' => '0',
456+
],
457+
];
458+
459+
$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
460+
$this->select->expects($this->at(0))->method('from')->with(
461+
[
462+
'main' => 'table',
463+
],
464+
'*'
465+
)->willReturnSelf();
466+
$this->select->expects($this->at(1))->method('where')->with(
467+
'value = ?',
468+
1
469+
)->willReturnSelf();
470+
$this->connection->expects($this->once())->method('fetchAll')
471+
->with($this->select)
472+
->willReturn($results);
473+
$this->assertEquals($this->resource->countImageUses(1), count($results));
474+
}
446475
}

app/code/Magento/Sales/Model/Order/Address/Renderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function __construct(
4848
*/
4949
public function format(Address $address, $type)
5050
{
51+
$this->addressConfig->setStore($address->getOrder()->getStoreId());
5152
$formatType = $this->addressConfig->getFormatByCode($type);
5253
if (!$formatType || !$formatType->getRenderer()) {
5354
return null;
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Test\Unit\Model\Order\Address;
7+
8+
use Magento\Sales\Model\Order\Address\Renderer as OrderAddressRenderer;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
use Magento\Customer\Model\Address\Config as CustomerAddressConfig;
11+
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
use Magento\Sales\Model\Order\Address as OrderAddress;
13+
use Magento\Sales\Model\Order;
14+
use Magento\Customer\Block\Address\Renderer\RendererInterface as CustomerAddressBlockRenderer;
15+
use Magento\Framework\DataObject;
16+
17+
class RendererTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @var OrderAddressRenderer
21+
*/
22+
private $orderAddressRenderer;
23+
24+
/**
25+
* @var ObjectManagerHelper
26+
*/
27+
private $objectManagerHelper;
28+
29+
/**
30+
* @var CustomerAddressConfig|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
private $customerAddressConfigMock;
33+
34+
/**
35+
* @var EventManager|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $eventManagerMock;
38+
39+
/**
40+
* @var OrderAddress|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $orderAddressMock;
43+
44+
/**
45+
* @var Order|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $orderMock;
48+
49+
/**
50+
* @var CustomerAddressBlockRenderer|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $customerAddressBlockRendererMock;
53+
54+
protected function setUp()
55+
{
56+
$this->customerAddressConfigMock = $this->getMockBuilder(CustomerAddressConfig::class)
57+
->disableOriginalConstructor()
58+
->getMock();
59+
$this->eventManagerMock = $this->getMockBuilder(EventManager::class)
60+
->getMockForAbstractClass();
61+
$this->orderAddressMock = $this->getMockBuilder(OrderAddress::class)
62+
->disableOriginalConstructor()
63+
->getMock();
64+
$this->orderMock = $this->getMockBuilder(Order::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$this->customerAddressBlockRendererMock = $this->getMockBuilder(CustomerAddressBlockRenderer::class)
68+
->getMockForAbstractClass();
69+
70+
$this->orderAddressMock->expects(static::any())
71+
->method('getOrder')
72+
->willReturn($this->orderMock);
73+
74+
$this->objectManagerHelper = new ObjectManagerHelper($this);
75+
$this->orderAddressRenderer = $this->objectManagerHelper->getObject(
76+
OrderAddressRenderer::class,
77+
[
78+
'addressConfig' => $this->customerAddressConfigMock,
79+
'eventManager' => $this->eventManagerMock
80+
]
81+
);
82+
}
83+
84+
public function testFormat()
85+
{
86+
$type = 'html';
87+
$formatType = new DataObject(['renderer' => $this->customerAddressBlockRendererMock]);
88+
$addressData = ['address', 'data'];
89+
$result = 'result string';
90+
91+
$this->setStoreExpectations(1);
92+
$this->customerAddressConfigMock->expects(static::atLeastOnce())
93+
->method('getFormatByCode')
94+
->with($type)
95+
->willReturn($formatType);
96+
$this->eventManagerMock->expects(static::once())
97+
->method('dispatch')
98+
->with('customer_address_format', ['type' => $formatType, 'address' => $this->orderAddressMock]);
99+
$this->orderAddressMock->expects(static::atLeastOnce())
100+
->method('getData')
101+
->willReturn($addressData);
102+
$this->customerAddressBlockRendererMock->expects(static::once())
103+
->method('renderArray')
104+
->with($addressData, null)
105+
->willReturn($result);
106+
107+
$this->assertEquals($result, $this->orderAddressRenderer->format($this->orderAddressMock, $type));
108+
}
109+
110+
public function testFormatNoRenderer()
111+
{
112+
$type = 'html';
113+
114+
$this->setStoreExpectations(1);
115+
$this->customerAddressConfigMock->expects(static::atLeastOnce())
116+
->method('getFormatByCode')
117+
->with($type)
118+
->willReturn(null);
119+
$this->eventManagerMock->expects(static::never())
120+
->method('dispatch');
121+
122+
$this->assertEquals(null, $this->orderAddressRenderer->format($this->orderAddressMock, $type));
123+
}
124+
125+
/**
126+
* Set expectations for store
127+
*
128+
* @param string|int $storeId
129+
* @return void
130+
*/
131+
private function setStoreExpectations($storeId)
132+
{
133+
$this->orderMock->expects(static::atLeastOnce())
134+
->method('getStoreId')
135+
->willReturn($storeId);
136+
$this->customerAddressConfigMock->expects(static::atLeastOnce())
137+
->method('setStore')
138+
->with($storeId)
139+
->willReturnSelf();
140+
}
141+
}

app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="order/view/tab/info.phtml">
2424
<block class="Magento\Sales\Block\Adminhtml\Order\View\Messages" name="order_messages"/>
2525
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="order/view/info.phtml"/>
26+
<container name="order_additional_info"/>
2627
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="order/view/items.phtml">
2728
<arguments>
2829
<argument name="columns" xsi:type="array">

app/code/Magento/Sales/view/adminhtml/templates/order/view/tab/info.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
</div>
4141
</section>
4242

43+
<?php echo $block->getChildHtml('order_additional_info') ?>
44+
4345
<?php echo $block->getGiftOptionsHtml() ?>
4446

4547
<section class="admin__page-section">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// /**
2+
// * Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
// * See COPYING.txt for license details.
4+
// */
5+
6+
//
7+
// Order Case Info
8+
// ---------------------------------------------
9+
10+
.order-case-table {
11+
&:extend(.abs-order-tables all);
12+
&:extend(.abs-order-tbody-border all);
13+
}

app/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<preference for="Magento\Framework\Search\Adapter\Mysql\Field\FieldInterface" type="Magento\Framework\Search\Adapter\Mysql\Field\Field"/>
1919
<preference for="Magento\Framework\Search\Adapter\Aggregation\AggregationResolverInterface" type="Magento\Framework\Search\Adapter\Aggregation\AggregationResolver"/>
2020
<preference for="Magento\Framework\App\RequestInterface" type="Magento\Framework\App\Request\Http" />
21+
<preference for="Magento\Framework\App\PlainTextRequestInterface" type="Magento\Framework\App\Request\Http" />
22+
<preference for="Magento\Framework\App\RequestContentInterface" type="Magento\Framework\App\Request\Http" />
2123
<preference for="Magento\Framework\App\Request\PathInfoProcessorInterface" type="Magento\Store\App\Request\PathInfoProcessor" />
2224
<preference for="Magento\Framework\App\ResponseInterface" type="Magento\Framework\App\Response\Http" />
2325
<preference for="Magento\Framework\App\RouterListInterface" type="Magento\Framework\App\RouterList" />

dev/tests/functional/.htaccess.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##############################################
2-
## Allow access to command.php and website.php
3-
<FilesMatch "command.php|website.php|export.php|pathChecker.php|deleteMagentoGeneratedCode.php">
2+
## Allow access to command.php, website.php, export.php, pathChecker.php, deleteMagentoGeneratedCode.php and log.php
3+
<FilesMatch "command.php|website.php|export.php|pathChecker.php|deleteMagentoGeneratedCode.php|log.php">
44
order allow,deny
55
allow from all
66
</FilesMatch>

dev/tests/functional/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"magento/mtf": "1.0.0-rc52",
3+
"magento/mtf": "1.0.0-rc53",
44
"php": "~5.6.5|7.0.2|~7.0.6",
55
"phpunit/phpunit": "~4.8.0|~5.5.0",
66
"phpunit/phpunit-selenium": ">=1.2"

0 commit comments

Comments
 (0)