Skip to content

Commit 3117397

Browse files
authored
Merge pull request #5675 from magento-chaika/Chaika-PR-2020-05-17
Chaika-PR-2020-05-17
2 parents 9e5c867 + 2be8b6e commit 3117397

File tree

21 files changed

+614
-116
lines changed

21 files changed

+614
-116
lines changed

app/code/Magento/Braintree/view/adminhtml/web/js/vault.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ define([
131131
this.createPublicHashSelector();
132132

133133
this.$selector.find('[name="payment[public_hash]"]').val(this.publicHash);
134-
this.$container.find('#' + this.getNonceSelectorName()).val(nonce);
134+
$('#' + this.getNonceSelectorName()).val(nonce);
135135
},
136136

137137
/**
@@ -140,7 +140,7 @@ define([
140140
createPublicHashSelector: function () {
141141
var $input;
142142

143-
if (this.$container.find('#' + this.getNonceSelectorName()).size() === 0) {
143+
if ($('#' + this.getNonceSelectorName()).length === 0) {
144144
$input = $('<input>').attr(
145145
{
146146
type: 'hidden',
@@ -149,7 +149,7 @@ define([
149149
}
150150
);
151151

152-
$input.appendTo(this.$container);
152+
$input.appendTo($('#edit_form'));
153153
$input.prop('disabled', false);
154154
}
155155
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Plugin;
9+
10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
13+
use Magento\Framework\App\ObjectManager;
14+
15+
/**
16+
* Category Save Plugin updates default sort by
17+
*/
18+
class DefaultSortByUpdateCategorySavePlugin
19+
{
20+
/**
21+
* @var ExtensibleDataObjectConverter
22+
*/
23+
private $extensibleDataObjectConverter;
24+
25+
/**
26+
* @var string
27+
*/
28+
private static $defaultSortByFromKey = 'default_sort_by';
29+
30+
/**
31+
* DefaultSortByUpdateCategorySavePlugin constructor.
32+
*
33+
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
34+
*/
35+
public function __construct(
36+
ExtensibleDataObjectConverter $extensibleDataObjectConverter
37+
) {
38+
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter ?? ObjectManager::getInstance()
39+
->get(ExtensibleDataObjectConverter::class);
40+
}
41+
42+
/**
43+
* Before save
44+
*
45+
* @param CategoryRepositoryInterface $subject
46+
* @param CategoryInterface $category
47+
* @return void
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function beforeSave(
51+
CategoryRepositoryInterface $subject,
52+
CategoryInterface $category
53+
): void {
54+
$existingData = $this->extensibleDataObjectConverter
55+
->toNestedArray($category, [], CategoryInterface::class);
56+
57+
if (isset($existingData['default_sort_by']) &&
58+
is_array($existingData['default_sort_by'])) {
59+
$category->setCustomAttribute(
60+
self::$defaultSortByFromKey,
61+
$existingData['default_sort_by'][0]
62+
);
63+
}
64+
}
65+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\Plugin;
9+
10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
13+
use Magento\Catalog\Model\Plugin\DefaultSortByUpdateCategorySavePlugin;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class DefaultSortByUpdateCategorySavePluginTest extends TestCase
17+
{
18+
/**
19+
* @var string
20+
*/
21+
private static $defaultSortByFromKey = 'default_sort_by';
22+
23+
/**
24+
* Extensible DataObject Converter mock
25+
*
26+
* @var ExtensibleDataObjectConverter|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $extensibleDataObjectConverterMock;
29+
30+
/**
31+
* CategoryInterface mock
32+
*
33+
* @var CategoryInterface|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $categoryInterfaceMock;
36+
37+
/**
38+
* CategoryRepositoryInterface mock
39+
*
40+
* @var CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $subjectMock;
43+
44+
/**
45+
* Category Save plugin
46+
*
47+
* @var DefaultSortByUpdateCategorySavePlugin
48+
*/
49+
private $categorySavePlugin;
50+
51+
protected function setUp()
52+
{
53+
$this->extensibleDataObjectConverterMock = $this
54+
->getMockBuilder(ExtensibleDataObjectConverter::class)
55+
->disableOriginalConstructor()
56+
->setMethods(['toNestedArray'])
57+
->getMock();
58+
59+
$this->subjectMock = $this
60+
->getMockBuilder(CategoryRepositoryInterface::class)
61+
->disableOriginalConstructor()
62+
->getMockForAbstractClass();
63+
64+
$this->categoryInterfaceMock = $this
65+
->getMockBuilder(CategoryInterface::class)
66+
->disableOriginalConstructor()
67+
->setMethods(['setCustomAttribute'])
68+
->getMockForAbstractClass();
69+
70+
$this->categorySavePlugin = new DefaultSortByUpdateCategorySavePlugin(
71+
$this->extensibleDataObjectConverterMock
72+
);
73+
}
74+
75+
/**
76+
* @return void
77+
*/
78+
public function testBeforeSaveWithDefaultSortByData(): void
79+
{
80+
$existingData = [
81+
'parent_id' => 2,
82+
'name' => 'test category 002',
83+
'is_active' => true,
84+
'position' => 1,
85+
'level' => 2,
86+
'children' => '',
87+
'created_at' => '2020-03-05 22:04:01',
88+
'updated_at' => '2020-04-16 23:57:22',
89+
'available_sort_by' => [],
90+
'include_in_menu' => true,
91+
'default_sort_by' => [
92+
0 => 'position'
93+
]
94+
];
95+
$this->categoryInterfaceMock
96+
->expects($this->once())
97+
->method('setCustomAttribute')
98+
->with(
99+
$this->equalTo(self::$defaultSortByFromKey),
100+
$existingData['default_sort_by'][0]
101+
)
102+
->willReturnSelf();
103+
$this->extensibleDataObjectConverterMock
104+
->expects($this->once())
105+
->method('toNestedArray')
106+
->with(
107+
$this->equalTo($this->categoryInterfaceMock),
108+
[],
109+
CategoryInterface::class
110+
)
111+
->willReturn($existingData);
112+
$this->categorySavePlugin->beforeSave(
113+
$this->subjectMock,
114+
$this->categoryInterfaceMock
115+
);
116+
}
117+
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,4 +1332,7 @@
13321332
</argument>
13331333
</arguments>
13341334
</type>
1335+
<type name="Magento\Catalog\Api\CategoryRepositoryInterface">
1336+
<plugin name="DefaultSortByUpdateCategorySavePlugin" type="Magento\Catalog\Model\Plugin\DefaultSortByUpdateCategorySavePlugin"/>
1337+
</type>
13351338
</config>

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Customer\Helper\Address as AddressHelper;
1111
use Magento\Customer\Model\Session;
1212
use Magento\Directory\Helper\Data as DirectoryHelper;
13+
use Magento\Directory\Model\AllowedCountries;
14+
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\Exception\NoSuchEntityException;
1517

@@ -92,23 +94,32 @@ class AttributeMerger
9294
*/
9395
private $topCountryCodes;
9496

97+
/**
98+
* @var AllowedCountries|null
99+
*/
100+
private $allowedCountryReader;
101+
95102
/**
96103
* @param AddressHelper $addressHelper
97104
* @param Session $customerSession
98105
* @param CustomerRepository $customerRepository
99106
* @param DirectoryHelper $directoryHelper
107+
* @param AllowedCountries $allowedCountryReader
100108
*/
101109
public function __construct(
102110
AddressHelper $addressHelper,
103111
Session $customerSession,
104112
CustomerRepository $customerRepository,
105-
DirectoryHelper $directoryHelper
113+
DirectoryHelper $directoryHelper,
114+
?AllowedCountries $allowedCountryReader = null
106115
) {
107116
$this->addressHelper = $addressHelper;
108117
$this->customerSession = $customerSession;
109118
$this->customerRepository = $customerRepository;
110119
$this->directoryHelper = $directoryHelper;
111120
$this->topCountryCodes = $directoryHelper->getTopCountryCodes();
121+
$this->allowedCountryReader =
122+
$allowedCountryReader ?: ObjectManager::getInstance()->get(AllowedCountries::class);
112123
}
113124

114125
/**
@@ -289,6 +300,7 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
289300
'dataScope' => $lineIndex,
290301
'provider' => $providerName,
291302
'validation' => $isFirstLine
303+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
292304
? array_merge(
293305
['required-entry' => (bool)$attributeConfig['required']],
294306
$attributeConfig['validation']
@@ -329,7 +341,11 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
329341
protected function getDefaultValue($attributeCode): ?string
330342
{
331343
if ($attributeCode === 'country_id') {
332-
return $this->directoryHelper->getDefaultCountry();
344+
$defaultCountryId = $this->directoryHelper->getDefaultCountry();
345+
if (!in_array($defaultCountryId, $this->allowedCountryReader->getAllowedCountries())) {
346+
$defaultCountryId = null;
347+
}
348+
return $defaultCountryId;
333349
}
334350

335351
$customer = $this->getCustomer();

app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ define([
192192
* @returns {Boolean} - initial visibility state.
193193
*/
194194
resolveInitialPasswordVisibility: function () {
195-
if (checkoutData.getInputFieldEmailValue() !== '' && checkoutData.getCheckedEmailValue() === '') {
196-
return true;
197-
}
198-
199195
if (checkoutData.getInputFieldEmailValue() !== '') {
200196
return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
201197
}

app/code/Magento/Checkout/view/frontend/web/template/form/element/email.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
data-bind="
2424
textInput: email,
2525
hasFocus: emailFocused,
26+
afterRender: emailHasChanged,
2627
mageInit: {'mage/trim-input':{}}"
2728
name="username"
2829
data-validate="{required:true, 'validate-email':true}"

app/code/Magento/Customer/Model/Vat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Vat
4444
* WSDL of VAT validation service
4545
*
4646
*/
47-
const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl';
47+
const VAT_VALIDATION_WSDL_URL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
4848

4949
/**
5050
* Config path to option that enables/disables automatic group assignment based on VAT

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function convertToProductData(int $productId, array $indexData, int $sto
190190
$attributeValues = [$productId => $attributeValues];
191191
}
192192
$attributeValues = $this->prepareAttributeValues($productId, $attribute, $attributeValues, $storeId);
193-
$productAttributes += $this->convertAttribute($attribute, $attributeValues);
193+
$productAttributes += $this->convertAttribute($attribute, $attributeValues, $storeId);
194194
}
195195

196196
return $productAttributes;
@@ -201,9 +201,10 @@ private function convertToProductData(int $productId, array $indexData, int $sto
201201
*
202202
* @param Attribute $attribute
203203
* @param array $attributeValues
204+
* @param int $storeId
204205
* @return array
205206
*/
206-
private function convertAttribute(Attribute $attribute, array $attributeValues): array
207+
private function convertAttribute(Attribute $attribute, array $attributeValues, int $storeId): array
207208
{
208209
$productAttributes = [];
209210

@@ -212,7 +213,7 @@ private function convertAttribute(Attribute $attribute, array $attributeValues):
212213
$productAttributes[$attribute->getAttributeCode()] = $retrievedValue;
213214

214215
if ($attribute->getIsSearchable()) {
215-
$attributeLabels = $this->getValuesLabels($attribute, $attributeValues);
216+
$attributeLabels = $this->getValuesLabels($attribute, $attributeValues, $storeId);
216217
$retrievedLabel = $this->retrieveFieldValue($attributeLabels);
217218
if ($retrievedLabel) {
218219
$productAttributes[$attribute->getAttributeCode() . '_value'] = $retrievedLabel;
@@ -294,20 +295,21 @@ private function isAttributeDate(Attribute $attribute): bool
294295
*
295296
* @param Attribute $attribute
296297
* @param array $attributeValues
298+
* @param int $storeId
297299
* @return array
298300
*/
299-
private function getValuesLabels(Attribute $attribute, array $attributeValues): array
301+
private function getValuesLabels(Attribute $attribute, array $attributeValues, int $storeId): array
300302
{
301303
$attributeLabels = [];
302304

303-
$options = $this->getAttributeOptions($attribute);
305+
$options = $this->getAttributeOptions($attribute, $storeId);
304306
if (empty($options)) {
305307
return $attributeLabels;
306308
}
307309

308310
foreach ($options as $option) {
309-
if (\in_array($option->getValue(), $attributeValues)) {
310-
$attributeLabels[] = $option->getLabel();
311+
if (\in_array($option['value'], $attributeValues)) {
312+
$attributeLabels[] = $option['label'];
311313
}
312314
}
313315

@@ -318,16 +320,23 @@ private function getValuesLabels(Attribute $attribute, array $attributeValues):
318320
* Retrieve options for attribute
319321
*
320322
* @param Attribute $attribute
323+
* @param int $storeId
321324
* @return array
322325
*/
323-
private function getAttributeOptions(Attribute $attribute): array
326+
private function getAttributeOptions(Attribute $attribute, int $storeId): array
324327
{
325-
if (!isset($this->attributeOptionsCache[$attribute->getId()])) {
326-
$options = $attribute->getOptions() ?? [];
327-
$this->attributeOptionsCache[$attribute->getId()] = $options;
328+
if (!isset($this->attributeOptionsCache[$storeId][$attribute->getId()])) {
329+
$attributeStoreId = $attribute->getStoreId();
330+
/**
331+
* Load array format of options.
332+
* $attribute->getOptions() loads options into data objects which can be costly.
333+
*/
334+
$options = $attribute->usesSource() ? $attribute->setStoreId($storeId)->getSource()->getAllOptions() : [];
335+
$this->attributeOptionsCache[$storeId][$attribute->getId()] = $options;
336+
$attribute->setStoreId($attributeStoreId);
328337
}
329338

330-
return $this->attributeOptionsCache[$attribute->getId()];
339+
return $this->attributeOptionsCache[$storeId][$attribute->getId()];
331340
}
332341

333342
/**

0 commit comments

Comments
 (0)