Skip to content

Commit 965f169

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-59761-remove-object-from-theme-cache
2 parents 0844fbd + e7f5340 commit 965f169

File tree

72 files changed

+3306
-201
lines changed

Some content is hidden

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

72 files changed

+3306
-201
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">

app/code/Magento/Tax/Model/Config.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Config
2323

2424
const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
2525

26+
const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
27+
2628
const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
2729

2830
// tax classes
@@ -68,6 +70,7 @@ class Config
6870

6971
const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
7072

73+
/** @deprecated */
7174
const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
7275

7376
const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
@@ -85,6 +88,7 @@ class Config
8588

8689
const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
8790

91+
/** @deprecated */
8892
const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
8993

9094
const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
@@ -468,6 +472,7 @@ public function displayCartShippingBoth($store = null)
468472
/**
469473
* @param null|string|bool|int|Store $store
470474
* @return bool
475+
* @deprecated
471476
*/
472477
public function displayCartDiscountInclTax($store = null)
473478
{
@@ -481,6 +486,7 @@ public function displayCartDiscountInclTax($store = null)
481486
/**
482487
* @param null|string|bool|int|Store $store
483488
* @return bool
489+
* @deprecated
484490
*/
485491
public function displayCartDiscountExclTax($store = null)
486492
{
@@ -494,6 +500,7 @@ public function displayCartDiscountExclTax($store = null)
494500
/**
495501
* @param null|string|bool|int|Store $store
496502
* @return bool
503+
* @deprecated
497504
*/
498505
public function displayCartDiscountBoth($store = null)
499506
{
@@ -663,6 +670,7 @@ public function displaySalesShippingBoth($store = null)
663670
/**
664671
* @param null|string|bool|int|Store $store
665672
* @return bool
673+
* @deprecated
666674
*/
667675
public function displaySalesDiscountInclTax($store = null)
668676
{
@@ -676,6 +684,7 @@ public function displaySalesDiscountInclTax($store = null)
676684
/**
677685
* @param null|string|bool|int|Store $store
678686
* @return bool
687+
* @deprecated
679688
*/
680689
public function displaySalesDiscountExclTax($store = null)
681690
{
@@ -689,6 +698,7 @@ public function displaySalesDiscountExclTax($store = null)
689698
/**
690699
* @param null|string|bool|int|Store $store
691700
* @return bool
701+
* @deprecated
692702
*/
693703
public function displaySalesDiscountBoth($store = null)
694704
{
@@ -753,6 +763,25 @@ public function crossBorderTradeEnabled($store = null)
753763
);
754764
}
755765

766+
/**
767+
* Check if admin notification related to misconfiguration of "Apply Discount On Prices" should be ignored.
768+
*
769+
* Warning is displayed in case when "Catalog Prices" = "Excluding Tax"
770+
* AND "Apply Discount On Prices" = "Including Tax"
771+
* AND "Apply Customer Tax" = "After Discount"
772+
*
773+
* @param null|string|Store $store
774+
* @return bool
775+
*/
776+
public function isWrongApplyDiscountSettingIgnored($store = null)
777+
{
778+
return (bool)$this->_scopeConfig->getValue(
779+
self::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
780+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
781+
$store
782+
);
783+
}
784+
756785
/**
757786
* Check if do not show notification about wrong display settings
758787
*

0 commit comments

Comments
 (0)