Skip to content

Commit 6f19a3d

Browse files
author
Oleksii Korshenko
authored
Merge pull request #620 from magento-folks/bugfix
[Folks] Bugfix
2 parents 1387fe0 + 2029e00 commit 6f19a3d

File tree

24 files changed

+581
-59
lines changed

24 files changed

+581
-59
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ protected function _prepareTierPriceIndex($entityIds = null)
491491
null
492492
)->join(
493493
['e' => $this->getTable('catalog_product_entity')],
494-
"i.entity_id=e.$linkField",
494+
"i.entity_id=e.entity_id",
495495
[]
496496
)->where(
497497
'e.type_id=?',
@@ -502,7 +502,7 @@ protected function _prepareTierPriceIndex($entityIds = null)
502502

503503
$select = $connection->select()->from(
504504
['tp' => $this->getTable('catalog_product_entity_tier_price')],
505-
[$linkField]
505+
['e.entity_id']
506506
)->join(
507507
['e' => $this->getTable('catalog_product_entity')],
508508
"tp.{$linkField} = e.{$linkField}",
@@ -523,11 +523,11 @@ protected function _prepareTierPriceIndex($entityIds = null)
523523
)->columns(
524524
new \Zend_Db_Expr('MIN(tp.value)')
525525
)->group(
526-
["tp.{$linkField}", 'cg.customer_group_id', 'cw.website_id']
526+
['e.entity_id', 'cg.customer_group_id', 'cw.website_id']
527527
);
528528

529529
if (!empty($entityIds)) {
530-
$select->where("tp.{$linkField} IN(?)", $entityIds);
530+
$select->where('e.entity_id IN(?)', $entityIds);
531531
}
532532

533533
$query = $select->insertFromSelect($this->_getTierPriceIndexTable());

app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function _construct()
8585
$widget = $this->registry->registry('current_widget_instance');
8686
if ($widget) {
8787
$widgetParameters = $widget->getWidgetParameters();
88-
} elseif($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) {
88+
} elseif ($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) {
8989
$widgetParameters = $widgetOptions->getWidgetValues();
9090
}
9191

@@ -100,6 +100,7 @@ protected function _construct()
100100
public function render(AbstractElement $element)
101101
{
102102
$this->element = $element;
103+
$this->rule->getConditions()->setJsFormObject($this->getHtmlId());
103104
return $this->toHtml();
104105
}
105106

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
* Test class for \Magento\CatalogWidget\Block\Product\Widget\Conditions
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class ConditionsTest extends \PHPUnit_Framework_TestCase
2021
{
@@ -175,4 +176,116 @@ public function testConstructWithParamsFromBlock()
175176
]
176177
);
177178
}
179+
180+
/**
181+
* @return void
182+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
183+
*/
184+
public function testRender()
185+
{
186+
$data = ['area' => 'backend'];
187+
$abstractElementMock = $this->getMock(
188+
\Magento\Framework\Data\Form\Element\AbstractElement::class,
189+
['getContainer'],
190+
[],
191+
'',
192+
false
193+
);
194+
$eventManagerMock = $this->getMock(
195+
\Magento\Framework\Event\ManagerInterface::class,
196+
[],
197+
[],
198+
'',
199+
false
200+
);
201+
$scopeConfigMock = $this->getMock(
202+
\Magento\Framework\App\Config\ScopeConfigInterface::class,
203+
[],
204+
[],
205+
'',
206+
false
207+
);
208+
$fieldsetMock = $this->getMock(
209+
\Magento\Framework\Data\Form\Element\Fieldset::class,
210+
[],
211+
[],
212+
'',
213+
false
214+
);
215+
$combineMock = $this->getMock(
216+
\Magento\Rule\Model\Condition\Combine::class,
217+
[],
218+
[],
219+
'',
220+
false
221+
);
222+
$resolverMock = $this->getMock(
223+
\Magento\Framework\View\Element\Template\File\Resolver::class,
224+
[],
225+
[],
226+
'',
227+
false
228+
);
229+
$filesystemMock = $this->getMock(
230+
\Magento\Framework\Filesystem::class,
231+
['getDirectoryRead'],
232+
[],
233+
'',
234+
false
235+
);
236+
$validatorMock = $this->getMock(
237+
\Magento\Framework\View\Element\Template\File\Validator::class,
238+
[],
239+
[],
240+
'',
241+
false
242+
);
243+
$templateEnginePoolMock = $this->getMock(
244+
\Magento\Framework\View\TemplateEnginePool::class,
245+
[],
246+
[],
247+
'',
248+
false
249+
);
250+
$templateEngineMock = $this->getMock(
251+
\Magento\Framework\View\TemplateEngineInterface::class,
252+
[],
253+
[],
254+
'',
255+
false
256+
);
257+
$directoryReadMock = $this->getMock(
258+
\Magento\Framework\Filesystem\Directory\ReadInterface::class,
259+
[],
260+
[],
261+
'',
262+
false
263+
);
264+
265+
$this->ruleMock->expects($this->once())->method('getConditions')->willReturn($combineMock);
266+
$combineMock->expects($this->once())->method('setJsFormObject')->willReturnSelf();
267+
$abstractElementMock->expects($this->any())->method('getContainer')->willReturn($fieldsetMock);
268+
$filesystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($directoryReadMock);
269+
$validatorMock->expects($this->once())->method('isValid')->willReturn(true);
270+
$this->contextMock->expects($this->once())->method('getEnginePool')->willReturn($templateEnginePoolMock);
271+
$templateEnginePoolMock->expects($this->once())->method('get')->willReturn($templateEngineMock);
272+
$templateEngineMock->expects($this->once())->method('render')->willReturn('html');
273+
274+
$this->widgetConditions = $this->objectManagerHelper->getObject(
275+
Conditions::class,
276+
[
277+
'context' => $this->contextMock,
278+
'registry' => $this->registryMock,
279+
'rule' => $this->ruleMock,
280+
'_eventManager' => $eventManagerMock,
281+
'_filesystem' => $filesystemMock,
282+
'_scopeConfig' => $scopeConfigMock,
283+
'validator' => $validatorMock,
284+
'resolver' => $resolverMock,
285+
'data' => $data
286+
]
287+
);
288+
289+
$this->assertEquals($this->widgetConditions->render($abstractElementMock), 'html');
290+
}
178291
}

app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\OfflineShipping\Model\Quote\Address;
77

8-
use Magento\Quote\Model\Quote\Address;
9-
108
class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInterface
119
{
1210
/**
@@ -48,7 +46,8 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
4846
$quote->getCustomerGroupId(),
4947
$quote->getCouponCode()
5048
);
51-
49+
$shippingAddress = $quote->getShippingAddress();
50+
$shippingAddress->setFreeShipping(0);
5251
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
5352
foreach ($items as $item) {
5453
if ($item->getNoDiscount()) {
@@ -66,10 +65,14 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
6665
$itemFreeShipping = (bool)$item->getFreeShipping();
6766
$addressFreeShipping = $addressFreeShipping && $itemFreeShipping;
6867

68+
if ($addressFreeShipping && !$item->getAddress()->getFreeShipping()) {
69+
$item->getAddress()->setFreeShipping(true);
70+
}
71+
6972
/** Parent free shipping we apply to all children*/
7073
$this->applyToChildren($item, $itemFreeShipping);
7174
}
72-
return $addressFreeShipping;
75+
return (bool)$shippingAddress->getFreeShipping();
7376
}
7477

7578
/**
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
class FreeShippingTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\OfflineShipping\Model\Quote\Address\FreeShipping
15+
*/
16+
private $model;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
20+
*/
21+
private $storeManagerMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\OfflineShipping\Model\SalesRule\Calculator
25+
*/
26+
private $calculatorMock;
27+
28+
protected function setUp()
29+
{
30+
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
31+
$this->calculatorMock = $this->getMock(
32+
\Magento\OfflineShipping\Model\SalesRule\Calculator::class,
33+
[],
34+
[],
35+
'',
36+
false
37+
);
38+
39+
$this->model = new \Magento\OfflineShipping\Model\Quote\Address\FreeShipping(
40+
$this->storeManagerMock,
41+
$this->calculatorMock
42+
);
43+
}
44+
45+
public function testIsFreeShippingIfNoItems()
46+
{
47+
$quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
48+
$this->assertFalse($this->model->isFreeShipping($quoteMock, []));
49+
}
50+
51+
public function testIsFreeShipping()
52+
{
53+
$storeId = 100;
54+
$websiteId = 200;
55+
$customerGroupId = 300;
56+
$objectManagerMock = new ObjectManagerHelper($this);
57+
$quoteMock = $this->getMock(
58+
\Magento\Quote\Model\Quote::class,
59+
['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'],
60+
[],
61+
'',
62+
false
63+
);
64+
$itemMock = $this->getMock(
65+
\Magento\Quote\Model\Quote\Item::class,
66+
[
67+
'getNoDiscount',
68+
'getParentItemId',
69+
'getFreeShipping',
70+
'getAddress',
71+
'isChildrenCalculated',
72+
'getHasChildren',
73+
'getChildren'
74+
],
75+
[],
76+
'',
77+
false
78+
);
79+
80+
$quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
81+
$storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class);
82+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
83+
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
84+
85+
$quoteMock->expects($this->once())->method('getCustomerGroupId')->willReturn($customerGroupId);
86+
$quoteMock->expects($this->once())->method('getCouponCode')->willReturn(null);
87+
88+
$this->calculatorMock->expects($this->once())
89+
->method('init')
90+
->with($websiteId, $customerGroupId, null)
91+
->willReturnSelf();
92+
93+
$itemMock->expects($this->once())->method('getNoDiscount')->willReturn(false);
94+
$itemMock->expects($this->once())->method('getParentItemId')->willReturn(false);
95+
$this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf();
96+
$itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true);
97+
98+
$addressMock = $objectManagerMock->getObject(\Magento\Quote\Model\Quote\Address::class);
99+
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock);
100+
$itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock);
101+
102+
$itemMock->expects($this->once())->method('getHasChildren')->willReturn(true);
103+
$itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true);
104+
105+
$childMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['setFreeShipping'], [], '', false);
106+
$childMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf();
107+
$itemMock->expects($this->once())->method('getChildren')->willReturn([$childMock]);
108+
109+
$this->assertTrue($this->model->isFreeShipping($quoteMock, [$itemMock]));
110+
}
111+
}

app/code/Magento/Sales/Block/Status/Grid/Column/State.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public function getFrameCallback()
4949
*/
5050
public function decorateState($value, $row, $column, $isExport)
5151
{
52+
$status = $row->getStatus();
5253
if ($value) {
53-
$cell = $value . '[' . $this->_config->getStateLabel($value) . ']';
54+
$cell = $value . '[' . $this->_config->getStateLabelByStateAndStatus($value, $status) . ']';
5455
} else {
5556
$cell = $value;
5657
}

app/code/Magento/Sales/Model/Order/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,22 @@ protected function _getStatuses($visibility)
256256
}
257257
return $this->statuses[(bool) $visibility];
258258
}
259+
260+
/**
261+
* Retrieve label by state and status
262+
*
263+
* @param string $state
264+
* @param string $status
265+
* @return \Magento\Framework\Phrase|string
266+
*/
267+
public function getStateLabelByStateAndStatus($state, $status)
268+
{
269+
foreach ($this->_getCollection() as $item) {
270+
if ($item->getData('state') == $state && $item->getData('status') == $status) {
271+
$label = $item->getData('label');
272+
return __($label);
273+
}
274+
}
275+
return $state;
276+
}
259277
}

app/code/Magento/Sales/Setup/UpgradeSchema.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
7676
'sales_shipment_grid',
7777
];
7878
foreach ($tables as $table) {
79-
$setup->getConnection()->modifyColumn(
80-
$setup->getTable($table),
79+
$salesConnection = $setup->getConnection(self::$connectionName);
80+
$salesConnection->modifyColumn(
81+
$installer->getTable($table, self::$connectionName),
8182
'customer_group_id',
8283
['type' => 'integer']
8384
);

0 commit comments

Comments
 (0)