Skip to content

Commit b725daa

Browse files
Onischenko, Yaroslav(yonischenko)Onischenko, Yaroslav(yonischenko)
Onischenko, Yaroslav(yonischenko)
authored and
Onischenko, Yaroslav(yonischenko)
committed
Merge pull request #61 from magento-nord/merchant_beta
[Merchant beta][Nord] Import/Export bugs fixes
2 parents a7eb8f8 + c44266d commit b725daa

File tree

7 files changed

+57
-29
lines changed

7 files changed

+57
-29
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
632632
}
633633
$categories[] = $categoryPath;
634634
}
635-
$dataRow[self::COL_CATEGORY] = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $categories);
635+
$dataRow[self::COL_CATEGORY] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $categories);
636636
unset($rowCategories[$productId]);
637637

638638
return true;
@@ -666,7 +666,7 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
666666
self::COL_ATTR_SET,
667667
self::COL_TYPE,
668668
self::COL_CATEGORY,
669-
'_product_websites',
669+
self::COL_PRODUCT_WEBSITES,
670670
],
671671
$this->_getExportMainAttrCodes(),
672672
[self::COL_ADDITIONAL_ATTRIBUTES],
@@ -1032,7 +1032,7 @@ protected function addMultirowData($dataRow, $multiRawData)
10321032
foreach ($multiRawData['rowWebsites'][$productId] as $productWebsite) {
10331033
$websiteCodes[] = $this->_websiteIdToCode[$productWebsite];
10341034
}
1035-
$dataRow['_product_websites'] =
1035+
$dataRow[self::COL_PRODUCT_WEBSITES] =
10361036
implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $websiteCodes);
10371037
$multiRawData['rowWebsites'][$productId] = [];
10381038
}

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

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,9 @@ protected function _saveProducts()
13721372
}
13731373
}
13741374

1375-
$this->websitesCache[$rowSku] = [];
1375+
if (!array_key_exists($rowSku, $this->websitesCache)) {
1376+
$this->websitesCache[$rowSku] = [];
1377+
}
13761378
// 2. Product-to-Website phase
13771379
if (!empty($rowData[self::COL_PRODUCT_WEBSITES])) {
13781380
$websiteCodes = explode($this->getMultipleValueSeparator(), $rowData[self::COL_PRODUCT_WEBSITES]);
@@ -1383,12 +1385,12 @@ protected function _saveProducts()
13831385
}
13841386

13851387
// 3. Categories phase
1386-
$categoriesString = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
1387-
$this->categoriesCache[$rowSku] = [];
1388-
if (!empty($categoriesString)) {
1389-
foreach ($this->categoryProcessor->upsertCategories($categoriesString) as $categoryId) {
1390-
$this->categoriesCache[$rowSku][$categoryId] = true;
1391-
}
1388+
$categoryIds = $this->processRowCategories($rowData);
1389+
if (!array_key_exists($rowData[Product::COL_SKU], $this->categoriesCache)) {
1390+
$this->categoriesCache[$rowData[Product::COL_SKU]] = [];
1391+
}
1392+
foreach ($categoryIds as $id) {
1393+
$this->categoriesCache[$rowData[Product::COL_SKU]][$id] = true;
13921394
}
13931395

13941396
// 4.1. Tier prices phase
@@ -1541,7 +1543,9 @@ protected function _saveProducts()
15411543
}
15421544
}
15431545
foreach ($storeIds as $storeId) {
1544-
$attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue;
1546+
if (!isset($attributes[$attrTable][$rowSku][$attrId][$storeId])) {
1547+
$attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue;
1548+
}
15451549
}
15461550
// restore 'backend_model' to avoid 'default' setting
15471551
$attribute->setBackendModel($backModel);
@@ -1574,7 +1578,24 @@ protected function _saveProducts()
15741578
}
15751579

15761580
/**
1577-
* @param $productSku
1581+
* @param array $rowData
1582+
* @return array
1583+
*/
1584+
protected function processRowCategories($rowData)
1585+
{
1586+
$categoriesString = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
1587+
$categoryIds = [];
1588+
if (!empty($categoriesString)) {
1589+
$categoryIds = $this->categoryProcessor->upsertCategories(
1590+
$categoriesString,
1591+
$this->getMultipleValueSeparator()
1592+
);
1593+
}
1594+
return $categoryIds;
1595+
}
1596+
1597+
/**
1598+
* @param string $productSku
15781599
* @return array
15791600
*/
15801601
public function getProductWebsites($productSku)
@@ -1583,7 +1604,7 @@ public function getProductWebsites($productSku)
15831604
}
15841605

15851606
/**
1586-
* @param $productSku
1607+
* @param string $productSku
15871608
* @return array
15881609
*/
15891610
public function getProductCategories($productSku)
@@ -1592,7 +1613,7 @@ public function getProductCategories($productSku)
15921613
}
15931614

15941615
/**
1595-
* @param $storeCode
1616+
* @param string $storeCode
15961617
* @return array|int|null|string
15971618
*/
15981619
public function getStoreIdByCode($storeCode)
@@ -2213,18 +2234,20 @@ private function _setStockUseConfigFieldsValues($rowData)
22132234
private function _customFieldsMapping($rowData)
22142235
{
22152236
foreach ($this->_fieldsMap as $systemFieldName => $fileFieldName) {
2216-
if (isset($rowData[$fileFieldName])) {
2237+
if (array_key_exists($fileFieldName, $rowData)) {
22172238
$rowData[$systemFieldName] = $rowData[$fileFieldName];
22182239
}
22192240
}
22202241

22212242
$rowData = $this->_parseAdditionalAttributes($rowData);
22222243

22232244
$rowData = $this->_setStockUseConfigFieldsValues($rowData);
2224-
if (isset($rowData['status'])) {
2225-
if (($rowData['status'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) || $rowData['status'] == 'yes') {
2245+
if (array_key_exists('status', $rowData)
2246+
&& $rowData['status'] != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
2247+
) {
2248+
if ($rowData['status'] == 'yes') {
22262249
$rowData['status'] = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
2227-
} else {
2250+
} elseif (!empty($rowData['status']) || $this->getRowScope($rowData) == self::SCOPE_DEFAULT) {
22282251
$rowData['status'] = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
22292252
}
22302253
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
class CategoryProcessor
99
{
10-
/**
11-
* Delimiter in import file between categories.
12-
*/
13-
const DELIMITER_CATEGORIES = '|';
14-
1510
/**
1611
* Delimiter in category path.
1712
*/
@@ -144,13 +139,14 @@ protected function upsertCategory($categoryPath)
144139
* Returns IDs of categories by string path creating nonexistent ones.
145140
*
146141
* @param string $categoriesString
142+
* @param string $categoriesSeparator
147143
*
148144
* @return array
149145
*/
150-
public function upsertCategories($categoriesString)
146+
public function upsertCategories($categoriesString, $categoriesSeparator)
151147
{
152148
$categoriesIds = [];
153-
$categories = explode(self::DELIMITER_CATEGORIES, $categoriesString);
149+
$categories = explode($categoriesSeparator, $categoriesString);
154150

155151
foreach ($categories as $category) {
156152
$categoriesIds[] = $this->upsertCategory($category);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
142142
$values = explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData[$attrCode]);
143143
$valid = true;
144144
foreach ($values as $value) {
145-
$valid = $valid || isset($attrParams['options'][strtolower($value)]);
145+
$valid = $valid && isset($attrParams['options'][strtolower($value)]);
146146
}
147147
if (!$valid) {
148148
$this->_addMessages(

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected function _validateFile()
223223
&& method_exists($params['object'], $params['method'])
224224
&& is_callable([$params['object'], $params['method']])
225225
) {
226-
$params['object']->{$params['method']}($filePath);
226+
$params['object']->{$params['method']}($this->_directory->getAbsolutePath($filePath));
227227
}
228228
}
229229
}
@@ -314,4 +314,12 @@ protected function _moveFile($tmpPath, $destPath)
314314
return false;
315315
}
316316
}
317+
318+
/**
319+
* {@inheritdoc}
320+
*/
321+
protected function chmod($file)
322+
{
323+
return;
324+
}
317325
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/CategoryProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function setUp()
110110

111111
public function testUpsertCategories()
112112
{
113-
$categoryIds = $this->categoryProcessor->upsertCategories(self::CHILD_CATEGORY_NAME);
113+
$categoryIds = $this->categoryProcessor->upsertCategories(self::CHILD_CATEGORY_NAME, ',');
114114
$this->assertArrayHasKey(self::CHILD_CATEGORY_ID, array_flip($categoryIds));
115115
}
116116

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/ValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function testIsBooleanAttributeValid()
8383
[
8484
'type' => 'boolean',
8585
'apply_to' => ['simple'],
86-
'is_required' => false
86+
'is_required' => false,
87+
'options' => ['yes' => 0, 'no' => 1]
8788
],
8889
[
8990
'product_type' => 'simple',

0 commit comments

Comments
 (0)