Skip to content

Commit 9fbaad7

Browse files
authored
Merge pull request #437 from magento-falcons/MAGETWO-58913
Fixed issues: - MAGETWO-58457: Can not install Magento 2.1.1 EE via GUI from composer project - MAGETWO-58104: If custom text area attribute is created, you can't export bundle product. - for 2.2 - MAGETWO-58394: [Github] magento/framework depends on zendframework/zend-stdlib but it's missing from composer.json #6442 - MAGETWO-58316: [Github] Customer Import - Invalid data for insert #4291
2 parents 7988331 + b59f60d commit 9fbaad7

File tree

14 files changed

+765
-35
lines changed

14 files changed

+765
-35
lines changed

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/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
/**

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,6 @@ protected function _prepareDataForUpdate(array $rowData)
370370

371371
// attribute values
372372
foreach (array_intersect_key($rowData, $this->_attributes) as $attributeCode => $value) {
373-
if ($newCustomer && !strlen($value)) {
374-
continue;
375-
}
376-
377373
$attributeParameters = $this->_attributes[$attributeCode];
378374
if ('select' == $attributeParameters['type']) {
379375
$value = isset($attributeParameters['options'][strtolower($value)])

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ protected function setUp()
3333
*/
3434
public function testPrepareData()
3535
{
36+
$parsedAdditionalAttributes = 'text_attribute=!@#$%^&*()_+1234567890-=|\\:;"\'<,>.?/'
37+
. ',text_attribute2=,';
38+
$allAdditionalAttributes = $parsedAdditionalAttributes . ',weight_type=0,price_type=1';
3639
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
3740
$collection = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
3841
$select = $collection->getConnection()->select()
@@ -42,7 +45,7 @@ public function testPrepareData()
4245
$select = (string)$collection->getSelect();
4346
$this->model->prepareData($collection, array_values($ids));
4447
$this->assertEquals($select, (string)$collection->getSelect());
45-
$result = $this->model->addData([], $ids['bundle-product']);
48+
$result = $this->model->addData(['additional_attributes' => $allAdditionalAttributes], $ids['bundle-product']);
4649
$this->assertArrayHasKey('bundle_price_type', $result);
4750
$this->assertArrayHasKey('bundle_shipment_type', $result);
4851
$this->assertArrayHasKey('bundle_sku_type', $result);
@@ -51,5 +54,6 @@ public function testPrepareData()
5154
$this->assertArrayHasKey('bundle_values', $result);
5255
$this->assertContains('sku=simple,', $result['bundle_values']);
5356
$this->assertEquals([], $this->model->addData([], $ids['simple']));
57+
$this->assertEquals($parsedAdditionalAttributes, $result['additional_attributes']);
5458
}
5559
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Catalog\Setup\CategorySetup $installer */
8+
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9+
->create(\Magento\Catalog\Setup\CategorySetup::class);
10+
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
11+
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
12+
->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
13+
$attribute->setData(
14+
[
15+
'attribute_code' => 'text_attribute',
16+
'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
17+
'is_global' => 1,
18+
'is_user_defined' => 1,
19+
'frontend_input' => 'textarea',
20+
'is_unique' => 0,
21+
'is_required' => 0,
22+
'is_searchable' => 0,
23+
'is_visible_in_advanced_search' => 0,
24+
'is_comparable' => 0,
25+
'is_filterable' => 0,
26+
'is_filterable_in_search' => 0,
27+
'is_used_for_promo_rules' => 0,
28+
'is_html_allowed_on_front' => 1,
29+
'is_visible_on_front' => 0,
30+
'used_in_product_listing' => 0,
31+
'used_for_sort_by' => 0,
32+
'frontend_label' => ['Text Attribute'],
33+
'backend_type' => 'text',
34+
]
35+
);
36+
$attribute->save();
37+
/* Assign attribute to attribute set */
38+
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testExport()
8383
$this->assertContains('Option 4 ""!@#$%^&*', $exportData);
8484
$this->assertContains('test_option_code_2', $exportData);
8585
$this->assertContains('max_characters=10', $exportData);
86+
$this->assertContains('text_attribute=!@#$%^&*()_+1234567890-=|\\:;""\'<,>.?/', $exportData);
8687
}
8788

8889
/**

dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
require dirname(dirname(__DIR__)) . '/Catalog/_files/category.php';
1010
require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php';
1111
require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute.php';
12+
require dirname(dirname(__DIR__)) . '/Catalog/_files/product_text_attribute.php';
1213

1314
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
1415

16+
/** @var \Magento\Catalog\Model\Product $productModel */
1517
$productModel = $objectManager->create(\Magento\Catalog\Model\Product::class);
1618

1719
$customOptions = [
@@ -52,6 +54,8 @@
5254
'simple'
5355
)->setPrice(
5456
10
57+
)->addData(
58+
['text_attribute' => '!@#$%^&*()_+1234567890-=|\\:;"\'<,>.?/']
5559
)->setTierPrice(
5660
[0 => ['website_id' => 0, 'cust_group' => 0, 'price_qty' => 3, 'price' => 8]]
5761
)->setVisibility(
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
email,_website,_store,confirmation,created_at,created_in,default_billing,default_shipping,disable_auto_group_change,dob,firstname,gender,group_id,lastname,middlename,password_hash,prefix,rp_token,rp_token_created_at,store_id,suffix,taxvat,website_id,password
2-
AnthonyANealy@magento.com,base,admin,,5/6/2012 15:53,Admin,1,1,0,,Anthony,Male,1,Nealy,A.,6a9c9bfb2ba88a6ad2a64e7402df44a763e0c48cd21d7af9e7e796cd4677ee28:RF,,,,0,,,1,
3-
LoriBBanks@magento.com,admin,admin,,5/6/2012 15:59,Admin,3,3,0,,Lori,Female,1,Banks,B.,7ad6dbdc83d3e9f598825dc58b84678c7351e4281f6bc2b277a32dcd88b9756b:pz,,,,0,,,0,
2+
AnthonyANealy@magento.com,base,admin,,5/6/2012 15:53,Admin,1,1,0,5/6/2010,Anthony,Male,1,Nealy,A.,6a9c9bfb2ba88a6ad2a64e7402df44a763e0c48cd21d7af9e7e796cd4677ee28:RF,,,,0,,,1,
3+
LoriBBanks@magento.com,admin,admin,,5/6/2012 15:59,Admin,3,3,0,5/6/2010,Lori,Female,1,Banks,B.,7ad6dbdc83d3e9f598825dc58b84678c7351e4281f6bc2b277a32dcd88b9756b:pz,,,,0,,,0,
44
CharlesTAlston@teleworm.us,base,admin,,5/6/2012 16:13,Admin,4,4,0,,Jhon,Female,1,Doe,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
55
customer@example.com,base,admin,,5/6/2012 16:15,Admin,4,4,0,,Firstname,Male,1,Lastname,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
66
julie.worrell@example.com,base,admin,,5/6/2012 16:19,Admin,4,4,0,,Julie,Female,1,Worrell,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
7-
david.lamar@example.com,base,admin,,5/6/2012 16:25,Admin,4,4,0,,David,Male,1,Lamar,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
7+
david.lamar@example.com,base,admin,,5/6/2012 16:25,Admin,4,4,0,,David,,1,Lamar,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,

lib/internal/Magento/Framework/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"ext-openssl": "*",
2121
"lib-libxml": "*",
2222
"ext-xsl": "*",
23-
"symfony/process": "~2.1"
23+
"symfony/process": "~2.1",
24+
"zendframework/zend-stdlib": "~2.4.6",
25+
"zendframework/zend-http": "~2.4.6"
2426
},
2527
"suggest": {
2628
"ext-imagick": "Use Image Magick >=3.0.0 as an optional alternative image processing library"

0 commit comments

Comments
 (0)