Skip to content

Commit 668f1b7

Browse files
Merge branch 'develop' of https://github.com/magento/magento2ce into MPI-PR-2704
2 parents 609387e + 15d3681 commit 668f1b7

File tree

20 files changed

+619
-41
lines changed

20 files changed

+619
-41
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function addPriceFilter($product, $searchMin, $useRegularPrice = false)
295295
if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
296296
$this->addPriceData();
297297
if ($useRegularPrice) {
298-
$minimalPriceExpression = 'price';
298+
$minimalPriceExpression = self::INDEX_TABLE_ALIAS . '.price';
299299
} else {
300300
$this->getCatalogRuleProcessor()->addPriceData($this, 'selection.product_id');
301301
$minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, minimal_price))';

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/TierPriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testModifyMeta()
6969
'data' => [
7070
'config' => [
7171
'visible' => true,
72-
'validation' => ['validate-number' => true],
72+
'validation' => ['validate-zero-or-greater' => true],
7373
],
7474
],
7575
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/TierPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function getUpdatedTierPriceStructure(array $priceMeta)
9797
$priceMeta['arguments']['data']['config']['visible'] = $firstOption
9898
&& $firstOption['value'] == ProductPriceOptionsInterface::VALUE_FIXED;
9999
$priceMeta['arguments']['data']['config']['validation'] = [
100-
'validate-number' => true,
100+
'validate-zero-or-greater' => true
101101
];
102102
return [
103103
'price_value' => [

app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,30 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
2727
*/
2828
protected $defaultShippingAddress = null;
2929

30+
/**
31+
* @var \Magento\Directory\Model\TopDestinationCountries
32+
*/
33+
private $topDestinationCountries;
34+
3035
/**
3136
* @param \Magento\Checkout\Block\Checkout\AttributeMerger $merger
3237
* @param \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection
3338
* @param \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection
39+
* @param \Magento\Directory\Model\TopDestinationCountries $topDestinationCountries
3440
* @codeCoverageIgnore
3541
*/
3642
public function __construct(
3743
\Magento\Checkout\Block\Checkout\AttributeMerger $merger,
3844
\Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection,
39-
\Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection
45+
\Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection,
46+
\Magento\Directory\Model\TopDestinationCountries $topDestinationCountries = null
4047
) {
4148
$this->merger = $merger;
4249
$this->countryCollection = $countryCollection;
4350
$this->regionCollection = $regionCollection;
51+
$this->topDestinationCountries = $topDestinationCountries ?:
52+
\Magento\Framework\App\ObjectManager::getInstance()
53+
->get(\Magento\Directory\Model\TopDestinationCountries::class);
4454
}
4555

4656
/**
@@ -105,11 +115,12 @@ public function process($jsLayout)
105115

106116
if (!isset($jsLayout['components']['checkoutProvider']['dictionaries'])) {
107117
$jsLayout['components']['checkoutProvider']['dictionaries'] = [
108-
'country_id' => $this->countryCollection->loadByStore()->toOptionArray(),
118+
'country_id' => $this->countryCollection->loadByStore()->setForegroundCountries(
119+
$this->topDestinationCountries->getTopDestinations()
120+
)->toOptionArray(),
109121
'region_id' => $this->regionCollection->addAllowedCountriesFilter()->toOptionArray(),
110122
];
111123
}
112-
113124
if (isset($jsLayout['components']['block-summary']['children']['block-shipping']['children']
114125
['address-fieldsets']['children'])
115126
) {

app/code/Magento/Checkout/Test/Unit/Block/Cart/LayoutProcessorTest.php

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
*/
66
namespace Magento\Checkout\Test\Unit\Block\Cart;
77

8+
89
class LayoutProcessorTest extends \PHPUnit_Framework_TestCase
910
{
11+
12+
/**
13+
* @var \Magento\Checkout\Block\Cart\LayoutProcessor
14+
*/
15+
private $layoutProcessor;
16+
1017
/**
1118
* @var \Magento\Checkout\Block\Cart\LayoutProcessor
1219
*/
@@ -27,35 +34,45 @@ class LayoutProcessorTest extends \PHPUnit_Framework_TestCase
2734
*/
2835
protected $regionCollection;
2936

37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
protected $topDestinationCountries;
41+
3042
protected function setUp()
3143
{
32-
$this->merger = $this->getMock(\Magento\Checkout\Block\Checkout\AttributeMerger::class, [], [], '', false);
33-
$this->countryCollection = $this->getMock(
34-
\Magento\Directory\Model\ResourceModel\Country\Collection::class,
35-
[],
36-
[],
37-
'',
38-
false
39-
);
40-
$this->regionCollection = $this->getMock(
41-
\Magento\Directory\Model\ResourceModel\Region\Collection::class,
42-
[],
43-
[],
44-
'',
45-
false
46-
);
47-
48-
$this->model = new \Magento\Checkout\Block\Cart\LayoutProcessor(
49-
$this->merger,
50-
$this->countryCollection,
51-
$this->regionCollection
44+
$this->merger = $this->getMockBuilder(\Magento\Checkout\Block\Checkout\AttributeMerger::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
$this->countryCollection =
48+
$this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Country\Collection::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
$this->regionCollection =
52+
$this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Region\Collection::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$this->topDestinationCountries =
56+
$this->getMockBuilder(\Magento\Directory\Model\TopDestinationCountries::class)
57+
->disableOriginalConstructor()
58+
->getMock();
59+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60+
$this->layoutProcessor = $objectManager->getObject(
61+
\Magento\Checkout\Block\Cart\LayoutProcessor::class,
62+
[
63+
'merger' => $this->merger,
64+
'countryCollection' => $this->countryCollection,
65+
'regionCollection' => $this->regionCollection,
66+
'topDestinationCountries' => $this->topDestinationCountries
67+
]
5268
);
5369
}
5470

5571
public function testProcess()
5672
{
5773
$countries = [];
5874
$regions = [];
75+
$topDestinationCountries = ['UA','AF'];
5976

6077
$layout = [];
6178
$layout['components']['block-summary']['children']['block-shipping']['children']
@@ -67,11 +84,19 @@ public function testProcess()
6784
['children']['address-fieldsets']['children'];
6885

6986
$this->countryCollection->expects($this->once())->method('loadByStore')->willReturnSelf();
87+
$this->countryCollection
88+
->expects($this->once())
89+
->method('setForegroundCountries')
90+
->with($topDestinationCountries)
91+
->willReturnSelf();
7092
$this->countryCollection->expects($this->once())->method('toOptionArray')->willReturn($countries);
7193

7294
$this->regionCollection->expects($this->once())->method('addAllowedCountriesFilter')->willReturnSelf();
7395
$this->regionCollection->expects($this->once())->method('toOptionArray')->willReturn($regions);
7496

97+
$this->topDestinationCountries->expects($this->once())->method('getTopDestinations')
98+
->willReturn($topDestinationCountries);
99+
75100
$layoutMerged = $layout;
76101
$layoutMerged['components']['block-summary']['children']['block-shipping']['children']
77102
['address-fieldsets']['children']['fieldThree'] = ['param' => 'value'];
@@ -111,12 +136,11 @@ public function testProcess()
111136
'value' => null
112137
]
113138
];
114-
115139
$this->merger->expects($this->once())
116140
->method('merge')
117141
->with($elements, 'checkoutProvider', 'shippingAddress', $layoutPointer)
118142
->willReturn($layoutMergedPointer);
119143

120-
$this->assertEquals($layoutMerged, $this->model->process($layout));
144+
$this->assertEquals($layoutMerged, $this->layoutProcessor->process($layout));
121145
}
122146
}

app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
namespace Magento\Directory\Model\ResourceModel\Country;
10+
1011
use Magento\Directory\Model\AllowedCountries;
1112
use Magento\Framework\App\ObjectManager;
1213
use Magento\Store\Model\ScopeInterface;
@@ -116,6 +117,24 @@ public function __construct(
116117
*/
117118
protected $_foregroundCountries = [];
118119

120+
/**
121+
* Add top destinition countries to head of option array
122+
*
123+
* @param $emptyLabel
124+
* @param $options
125+
* @return array
126+
*/
127+
private function addForegroundCountriesToOptionArray($emptyLabel, $options)
128+
{
129+
if ($emptyLabel !== false && count($this->_foregroundCountries) !== 0 &&
130+
count($options) === count($this->_foregroundCountries)
131+
) {
132+
$options[] = ['value' => '', 'label' => $emptyLabel];
133+
return $options;
134+
}
135+
return $options;
136+
}
137+
119138
/**
120139
* Define main table
121140
*
@@ -240,7 +259,6 @@ public function addCountryIdFilter($countryId)
240259
public function toOptionArray($emptyLabel = ' ')
241260
{
242261
$options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso2_code']);
243-
244262
$sort = [];
245263
foreach ($options as $data) {
246264
$name = (string)$this->_localeLists->getCountryTranslation($data['value']);
@@ -257,6 +275,7 @@ public function toOptionArray($emptyLabel = ' ')
257275
$isRegionVisible = (bool)$this->helperData->isShowNonRequiredState();
258276
$options = [];
259277
foreach ($sort as $label => $value) {
278+
$options = $this->addForegroundCountriesToOptionArray($emptyLabel, $options);
260279
$option = ['value' => $value, 'label' => $label];
261280
if ($this->helperData->isRegionRequired($value)) {
262281
$option['is_region_required'] = true;
@@ -268,8 +287,7 @@ public function toOptionArray($emptyLabel = ' ')
268287
}
269288
$options[] = $option;
270289
}
271-
272-
if (count($options) > 0 && $emptyLabel !== false) {
290+
if ($emptyLabel !== false && count($options) > 0) {
273291
array_unshift($options, ['value' => '', 'label' => $emptyLabel]);
274292
}
275293

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Model;
8+
9+
use Magento\Store\Model\ScopeInterface;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
12+
/**
13+
* Class TopDestinationCountries
14+
*/
15+
class TopDestinationCountries
16+
{
17+
const CONFIG_DESTINATIONS_PATH = 'general/country/destinations';
18+
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private $scopeConfig;
23+
24+
/**
25+
* @param ScopeConfigInterface $scopeConfig
26+
*/
27+
public function __construct(ScopeConfigInterface $scopeConfig)
28+
{
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* Retrieve list of top destinations countries
34+
*
35+
* @return array
36+
*/
37+
public function getTopDestinations()
38+
{
39+
$destinations = (string)$this->scopeConfig->getValue(
40+
self::CONFIG_DESTINATIONS_PATH,
41+
ScopeInterface::SCOPE_STORE
42+
);
43+
return !empty($destinations) ? explode(',', $destinations) : [];
44+
}
45+
}

app/code/Magento/Directory/Test/Unit/Model/ResourceModel/Country/CollectionTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
1818
*/
1919
protected $_model;
2020

21+
/**
22+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
23+
*/
24+
protected $scopeConfigMock;
25+
2126
protected function setUp()
2227
{
2328
$connection = $this->getMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, [], [], '', false);
@@ -44,7 +49,7 @@ protected function setUp()
4449
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface::class
4550
);
4651
$entityFactory = $this->getMock(\Magento\Framework\Data\Collection\EntityFactory::class, [], [], '', false);
47-
$scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
52+
$this->scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
4853
$logger = $this->getMock(\Psr\Log\LoggerInterface::class);
4954
$countryFactory = $this->getMock(
5055
\Magento\Directory\Model\ResourceModel\CountryFactory::class,
@@ -67,15 +72,13 @@ protected function setUp()
6772
'localeLists' => $localeListsMock,
6873
'fetchStrategy' => $fetchStrategy,
6974
'entityFactory' => $entityFactory,
70-
'scopeConfig' => $scopeConfigMock,
75+
'scopeConfig' => $this->scopeConfigMock,
7176
'countryFactory' => $countryFactory,
7277
'resource' => $resource,
7378
'helperData' => $helperDataMock
7479
];
75-
$this->_model = $objectManager->getObject(
76-
\Magento\Directory\Model\ResourceModel\Country\Collection::class,
77-
$arguments
78-
);
80+
$this->_model = $objectManager
81+
->getObject(\Magento\Directory\Model\ResourceModel\Country\Collection::class, $arguments);
7982
}
8083

8184
/**
@@ -93,7 +96,8 @@ public function testToOptionArray($optionsArray, $emptyLabel, $foregroundCountri
9396

9497
$this->_model->setForegroundCountries($foregroundCountries);
9598
$result = $this->_model->toOptionArray($emptyLabel);
96-
$this->assertEquals(count($optionsArray) + (int)(!empty($emptyLabel)), count($result));
99+
$this->assertCount(count($optionsArray) + (int)(!empty($emptyLabel) && !empty($foregroundCountries)) +
100+
(int)(!empty($emptyLabel)), $result);
97101
foreach ($expectedResults as $index => $expectedResult) {
98102
$this->assertEquals($expectedResult, $result[$index]['label']);
99103
}
@@ -114,7 +118,8 @@ public function toOptionArrayDataProvider()
114118
[$optionsArray, false, [], ['AD', 'US', 'ES', 'BZ']],
115119
[$optionsArray, false, 'US', ['US', 'AD', 'ES', 'BZ']],
116120
[$optionsArray, false, ['US', 'BZ'], ['US', 'BZ', 'AD', 'ES']],
117-
[$optionsArray, ' ', 'US', [' ', 'US', 'AD', 'ES', 'BZ']]
121+
[$optionsArray, ' ', 'US', [' ', 'US', ' ', 'AD', 'ES', 'BZ']],
122+
[$optionsArray, ' ', [], [' ', 'AD', 'US', 'ES', 'BZ']]
118123
];
119124
}
120125
}

0 commit comments

Comments
 (0)