Skip to content

Commit efff276

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into PR-develop
2 parents 65114d3 + 6af7f78 commit efff276

File tree

83 files changed

+2008
-316
lines changed

Some content is hidden

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

83 files changed

+2008
-316
lines changed

app/code/Magento/Braintree/Helper/Country.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
namespace Magento\Braintree\Helper;
77

88
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
9+
use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig;
910

1011
/**
1112
* Class Country
1213
*/
1314
class Country
1415
{
1516
/**
16-
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
17+
* @var CollectionFactory
1718
*/
1819
private $collectionFactory;
1920

2021
/**
21-
* @var \Magento\Braintree\Model\Adminhtml\System\Config\Country
22+
* @var CountryConfig
2223
*/
2324
private $countryConfig;
2425

@@ -28,13 +29,11 @@ class Country
2829
private $countries;
2930

3031
/**
31-
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory
32-
* @param \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
32+
* @param CollectionFactory $factory
33+
* @param CountryConfig $countryConfig
3334
*/
34-
public function __construct(
35-
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory,
36-
\Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
37-
) {
35+
public function __construct(CollectionFactory $factory, CountryConfig $countryConfig)
36+
{
3837
$this->collectionFactory = $factory;
3938
$this->countryConfig = $countryConfig;
4039
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\PayPal\ConfigProvider::PAYPAL_CODE</argument>
2323
<argument name="infoBlockType" xsi:type="string">BraintreePayPalInfo</argument>
2424
<argument name="valueHandlerPool" xsi:type="object">BraintreePayPalValueHandlerPool</argument>
25+
<argument name="validatorPool" xsi:type="object">BraintreePayPalValidatorPool</argument>
2526
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
2627
</arguments>
2728
</virtualType>
@@ -474,7 +475,7 @@
474475
</arguments>
475476
</virtualType>
476477

477-
<!-- Value validators infrastructure -->
478+
<!-- Braintree validators infrastructure -->
478479
<virtualType name="BraintreeCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
479480
<arguments>
480481
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
@@ -487,6 +488,22 @@
487488
</argument>
488489
</arguments>
489490
</virtualType>
491+
<!-- Braintree validators infrastructure -->
492+
493+
<!-- Braintree PayPal validators -->
494+
<virtualType name="BraintreePayPalCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
495+
<arguments>
496+
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\PayPal\Config</argument>
497+
</arguments>
498+
</virtualType>
499+
<virtualType name="BraintreePayPalValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
500+
<arguments>
501+
<argument name="validators" xsi:type="array">
502+
<item name="country" xsi:type="string">BraintreePayPalCountryValidator</item>
503+
</argument>
504+
</arguments>
505+
</virtualType>
506+
<!-- END Braintree PayPal validators -->
490507

491508
<type name="Magento\Braintree\Block\Info">
492509
<arguments>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ define([
1212
'Magento_Checkout/js/model/quote',
1313
'Magento_Checkout/js/model/full-screen-loader',
1414
'Magento_Checkout/js/model/payment/additional-validators',
15-
'Magento_Vault/js/view/payment/vault-enabler'
16-
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators, VaultEnabler) {
15+
'Magento_Vault/js/view/payment/vault-enabler',
16+
'Magento_Checkout/js/action/create-billing-address'
17+
], function (
18+
$,
19+
_,
20+
Component,
21+
Braintree,
22+
quote,
23+
fullScreenLoader,
24+
additionalValidators,
25+
VaultEnabler,
26+
createBillingAddress
27+
) {
1728
'use strict';
1829

1930
return Component.extend({
@@ -172,14 +183,16 @@ define([
172183
var billingAddress = {
173184
street: [address.streetAddress],
174185
city: address.locality,
175-
regionCode: address.region,
176186
postcode: address.postalCode,
177187
countryId: address.countryCodeAlpha2,
188+
email: customer.email,
178189
firstname: customer.firstName,
179190
lastname: customer.lastName,
180191
telephone: customer.phone
181192
};
182193

194+
billingAddress['region_code'] = address.region;
195+
billingAddress = createBillingAddress(billingAddress);
183196
quote.billingAddress(billingAddress);
184197
},
185198

app/code/Magento/Braintree/view/frontend/web/template/payment/form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
<input type="checkbox"
110110
name="vault[is_enabled]"
111111
class="checkbox"
112-
data-bind="attr: {'id': getCode() + '_vault_enabler'}, checked: vaultEnabler.isActivePaymentTokenEnabler"/>
113-
<label class="label" data-bind="attr: {'for': getCode() + '_vault_enabler'}">
112+
data-bind="attr: {'id': getCode() + '_enable_vault'}, checked: vaultEnabler.isActivePaymentTokenEnabler"/>
113+
<label class="label" data-bind="attr: {'for': getCode() + '_enable_vault'}">
114114
<span><!-- ko i18n: 'Save for later use.'--><!-- /ko --></span>
115115
</label>
116116
<div class="field-tooltip toggle">

app/code/Magento/Braintree/view/frontend/web/template/payment/paypal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
<input type="checkbox"
3333
name="vault[is_enabled]"
3434
class="checkbox"
35-
data-bind="attr: {'id': getCode() + '_vault_enabler'}, checked: vaultEnabler.isActivePaymentTokenEnabler"/>
36-
<label class="label" data-bind="attr: {'for': getCode() + '_vault_enabler'}">
35+
data-bind="attr: {'id': getCode() + '_enable_vault'}, checked: vaultEnabler.isActivePaymentTokenEnabler"/>
36+
<label class="label" data-bind="attr: {'for': getCode() + '_enable_vault'}">
3737
<span><!-- ko i18n: 'Save for later use.'--><!-- /ko --></span>
3838
</label>
3939
<div class="field-tooltip toggle">

app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ private function getShipmentTypeValue($type)
331331
protected function cleanNotBundleAdditionalAttributes($dataRow)
332332
{
333333
if (!empty($dataRow['additional_attributes'])) {
334-
$additionalAttributes = explode(
335-
ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
336-
$dataRow['additional_attributes']
337-
);
334+
$additionalAttributes = $this->parseAdditionalAttributes($dataRow['additional_attributes']);
338335
$dataRow['additional_attributes'] = $this->getNotBundleAttributes($additionalAttributes);
339336
}
340337

@@ -349,17 +346,38 @@ protected function cleanNotBundleAdditionalAttributes($dataRow)
349346
*/
350347
protected function getNotBundleAttributes($additionalAttributes)
351348
{
352-
$cleanedAdditionalAttributes = '';
353-
foreach ($additionalAttributes as $attribute) {
354-
list($attributeCode, $attributeValue) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attribute);
355-
if (!in_array('bundle_' . $attributeCode, $this->getBundleColumns())) {
356-
$cleanedAdditionalAttributes .= $attributeCode
357-
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
358-
. $attributeValue
359-
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
349+
$filteredAttributes = [];
350+
foreach ($additionalAttributes as $code => $value) {
351+
if (!in_array('bundle_' . $code, $this->getBundleColumns())) {
352+
$filteredAttributes[] = $code . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $value;
360353
}
361354
}
355+
return implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $filteredAttributes);
356+
}
362357

363-
return rtrim($cleanedAdditionalAttributes, ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
358+
/**
359+
* Retrieves additional attributes as array code=>value.
360+
*
361+
* @param string $additionalAttributes
362+
* @return array
363+
*/
364+
private function parseAdditionalAttributes($additionalAttributes)
365+
{
366+
$attributeNameValuePairs = explode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalAttributes);
367+
$preparedAttributes = [];
368+
$code = '';
369+
foreach ($attributeNameValuePairs as $attributeData) {
370+
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
371+
if (strpos($attributeData, ImportProductModel::PAIR_NAME_VALUE_SEPARATOR) === false) {
372+
if (!$code) {
373+
continue;
374+
}
375+
$preparedAttributes[$code] .= ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . $attributeData;
376+
continue;
377+
}
378+
list($code, $value) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
379+
$preparedAttributes[$code] = $value;
380+
}
381+
return $preparedAttributes;
364382
}
365383
}

app/code/Magento/BundleImportExport/Test/Unit/Model/Export/Product/RowCustomizerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,16 @@ public function testAddHeaderColumns()
178178
public function testAddData()
179179
{
180180
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
181-
$attributes = 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values,shipment_type=1';
181+
$attributes = 'attribute=1,sku_type=1,attribute2="Text",price_type=1,price_view=1,weight_type=1,'
182+
. 'values=values,shipment_type=1,attribute3=One,Two,Three';
182183
$dataRow = [
183184
'sku' => 'sku1',
184185
'additional_attributes' => $attributes
185186
];
186187
$preparedRow = $preparedData->addData($dataRow, 1);
187188
$expected = [
188189
'sku' => 'sku1',
189-
'additional_attributes' => 'attribute=1',
190+
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
190191
'bundle_price_type' => 'fixed',
191192
'bundle_shipment_type' => 'separately',
192193
'bundle_sku_type' => 'fixed',

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
125125
$attribute->setFrontendInput($existingModel->getFrontendInput());
126126

127127
if (is_array($attribute->getFrontendLabels())) {
128-
$frontendLabel[0] = $existingModel->getDefaultFrontendLabel();
128+
$defaultFrontendLabel = $attribute->getDefaultFrontendLabel();
129+
$frontendLabel[0] = !empty($defaultFrontendLabel)
130+
? $defaultFrontendLabel
131+
: $existingModel->getDefaultFrontendLabel();
129132
foreach ($attribute->getFrontendLabels() as $item) {
130133
$frontendLabel[$item->getStoreId()] = $item->getLabel();
131134
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testToHtml()
5353
->disableOriginalConstructor()
5454
->setMethods(['dispatch'])
5555
->getMock();
56-
$eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true));
56+
$eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true));
5757

5858
$scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
5959
->setMethods(['getValue'])

app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testGetProductsCount()
186186

187187
protected function generalGetProductCollection()
188188
{
189-
$this->eventManager->expects($this->once())->method('dispatch')
189+
$this->eventManager->expects($this->exactly(2))->method('dispatch')
190190
->will($this->returnValue(true));
191191
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
192192
->willReturn(false);

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Product\Attribute\Repository;
1313
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1414
use Magento\Catalog\Api\Data\ProductAttributeInterface;
15+
use Magento\Eav\Api\Data\AttributeFrontendLabelInterface;
1516

1617
/**
1718
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -288,4 +289,42 @@ public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()
288289

289290
$this->model->save($attributeMock);
290291
}
292+
293+
public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload()
294+
{
295+
$labelMock = $this->getMock(AttributeFrontendLabelInterface::class);
296+
$labelMock->expects($this->any())->method('getStoreId')->willReturn(1);
297+
$labelMock->expects($this->any())->method('getLabel')->willReturn('Store Scope Label');
298+
299+
$attributeId = 1;
300+
$attributeCode = 'existing_attribute_code';
301+
$attributeMock = $this->getMock(Attribute::class, [], [], '', false);
302+
$attributeMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
303+
$attributeMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
304+
$attributeMock->expects($this->any())->method('getDefaultFrontendLabel')->willReturn('Default Label');
305+
$attributeMock->expects($this->any())->method('getFrontendLabels')->willReturn([$labelMock]);
306+
$attributeMock->expects($this->any())->method('getOptions')->willReturn([]);
307+
308+
309+
$existingModelMock = $this->getMock(Attribute::class, [], [], '', false);
310+
$existingModelMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
311+
$existingModelMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
312+
313+
$this->eavAttributeRepositoryMock->expects($this->any())
314+
->method('get')
315+
->with(ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode)
316+
->willReturn($existingModelMock);
317+
318+
$attributeMock->expects($this->once())
319+
->method('setDefaultFrontendLabel')
320+
->with(
321+
[
322+
0 => 'Default Label',
323+
1 => 'Store Scope Label'
324+
]
325+
);
326+
$this->attributeResourceMock->expects($this->once())->method('save')->with($attributeMock);
327+
328+
$this->model->save($attributeMock);
329+
}
291330
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,20 +2416,34 @@ private function _parseAdditionalAttributes($rowData)
24162416
if (empty($rowData['additional_attributes'])) {
24172417
return $rowData;
24182418
}
2419+
$rowData = array_merge($rowData, $this->parseAdditionalAttributes($rowData['additional_attributes']));
2420+
return $rowData;
2421+
}
24192422

2420-
$attributeNameValuePairs = explode($this->getMultipleValueSeparator(), $rowData['additional_attributes']);
2421-
foreach ($attributeNameValuePairs as $attributeNameValuePair) {
2422-
$separatorPosition = strpos($attributeNameValuePair, self::PAIR_NAME_VALUE_SEPARATOR);
2423-
if ($separatorPosition !== false) {
2424-
$key = substr($attributeNameValuePair, 0, $separatorPosition);
2425-
$value = substr(
2426-
$attributeNameValuePair,
2427-
$separatorPosition + strlen(self::PAIR_NAME_VALUE_SEPARATOR)
2428-
);
2429-
$rowData[$key] = $value === false ? '' : $value;
2423+
/**
2424+
* Retrieves additional attributes as array code=>value.
2425+
*
2426+
* @param string $additionalAttributes
2427+
* @return array
2428+
*/
2429+
private function parseAdditionalAttributes($additionalAttributes)
2430+
{
2431+
$attributeNameValuePairs = explode($this->getMultipleValueSeparator(), $additionalAttributes);
2432+
$preparedAttributes = [];
2433+
$code = '';
2434+
foreach ($attributeNameValuePairs as $attributeData) {
2435+
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
2436+
if (strpos($attributeData, self::PAIR_NAME_VALUE_SEPARATOR) === false) {
2437+
if (!$code) {
2438+
continue;
2439+
}
2440+
$preparedAttributes[$code] .= $this->getMultipleValueSeparator() . $attributeData;
2441+
continue;
24302442
}
2443+
list($code, $value) = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
2444+
$preparedAttributes[$code] = $value;
24312445
}
2432-
return $rowData;
2446+
return $preparedAttributes;
24332447
}
24342448

24352449
/**

0 commit comments

Comments
 (0)