Skip to content

Commit

Permalink
Merge pull request #61 from magento-nord/merchant_beta
Browse files Browse the repository at this point in the history
[Merchant beta][Nord] Import/Export bugs fixes
  • Loading branch information
Onischenko, Yaroslav(yonischenko) authored and Onischenko, Yaroslav(yonischenko) committed Oct 28, 2015
2 parents a7eb8f8 + c44266d commit b725daa
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 29 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
}
$categories[] = $categoryPath;
}
$dataRow[self::COL_CATEGORY] = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $categories);
$dataRow[self::COL_CATEGORY] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $categories);
unset($rowCategories[$productId]);

return true;
Expand Down Expand Up @@ -666,7 +666,7 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
self::COL_ATTR_SET,
self::COL_TYPE,
self::COL_CATEGORY,
'_product_websites',
self::COL_PRODUCT_WEBSITES,
],
$this->_getExportMainAttrCodes(),
[self::COL_ADDITIONAL_ATTRIBUTES],
Expand Down Expand Up @@ -1032,7 +1032,7 @@ protected function addMultirowData($dataRow, $multiRawData)
foreach ($multiRawData['rowWebsites'][$productId] as $productWebsite) {
$websiteCodes[] = $this->_websiteIdToCode[$productWebsite];
}
$dataRow['_product_websites'] =
$dataRow[self::COL_PRODUCT_WEBSITES] =
implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $websiteCodes);
$multiRawData['rowWebsites'][$productId] = [];
}
Expand Down
53 changes: 38 additions & 15 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,9 @@ protected function _saveProducts()
}
}

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

// 3. Categories phase
$categoriesString = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
$this->categoriesCache[$rowSku] = [];
if (!empty($categoriesString)) {
foreach ($this->categoryProcessor->upsertCategories($categoriesString) as $categoryId) {
$this->categoriesCache[$rowSku][$categoryId] = true;
}
$categoryIds = $this->processRowCategories($rowData);
if (!array_key_exists($rowData[Product::COL_SKU], $this->categoriesCache)) {
$this->categoriesCache[$rowData[Product::COL_SKU]] = [];
}
foreach ($categoryIds as $id) {
$this->categoriesCache[$rowData[Product::COL_SKU]][$id] = true;
}

// 4.1. Tier prices phase
Expand Down Expand Up @@ -1541,7 +1543,9 @@ protected function _saveProducts()
}
}
foreach ($storeIds as $storeId) {
$attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue;
if (!isset($attributes[$attrTable][$rowSku][$attrId][$storeId])) {
$attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue;
}
}
// restore 'backend_model' to avoid 'default' setting
$attribute->setBackendModel($backModel);
Expand Down Expand Up @@ -1574,7 +1578,24 @@ protected function _saveProducts()
}

/**
* @param $productSku
* @param array $rowData
* @return array
*/
protected function processRowCategories($rowData)
{
$categoriesString = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
$categoryIds = [];
if (!empty($categoriesString)) {
$categoryIds = $this->categoryProcessor->upsertCategories(
$categoriesString,
$this->getMultipleValueSeparator()
);
}
return $categoryIds;
}

/**
* @param string $productSku
* @return array
*/
public function getProductWebsites($productSku)
Expand All @@ -1583,7 +1604,7 @@ public function getProductWebsites($productSku)
}

/**
* @param $productSku
* @param string $productSku
* @return array
*/
public function getProductCategories($productSku)
Expand All @@ -1592,7 +1613,7 @@ public function getProductCategories($productSku)
}

/**
* @param $storeCode
* @param string $storeCode
* @return array|int|null|string
*/
public function getStoreIdByCode($storeCode)
Expand Down Expand Up @@ -2213,18 +2234,20 @@ private function _setStockUseConfigFieldsValues($rowData)
private function _customFieldsMapping($rowData)
{
foreach ($this->_fieldsMap as $systemFieldName => $fileFieldName) {
if (isset($rowData[$fileFieldName])) {
if (array_key_exists($fileFieldName, $rowData)) {
$rowData[$systemFieldName] = $rowData[$fileFieldName];
}
}

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

$rowData = $this->_setStockUseConfigFieldsValues($rowData);
if (isset($rowData['status'])) {
if (($rowData['status'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) || $rowData['status'] == 'yes') {
if (array_key_exists('status', $rowData)
&& $rowData['status'] != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
) {
if ($rowData['status'] == 'yes') {
$rowData['status'] = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
} else {
} elseif (!empty($rowData['status']) || $this->getRowScope($rowData) == self::SCOPE_DEFAULT) {
$rowData['status'] = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

class CategoryProcessor
{
/**
* Delimiter in import file between categories.
*/
const DELIMITER_CATEGORIES = '|';

/**
* Delimiter in category path.
*/
Expand Down Expand Up @@ -144,13 +139,14 @@ protected function upsertCategory($categoryPath)
* Returns IDs of categories by string path creating nonexistent ones.
*
* @param string $categoriesString
* @param string $categoriesSeparator
*
* @return array
*/
public function upsertCategories($categoriesString)
public function upsertCategories($categoriesString, $categoriesSeparator)
{
$categoriesIds = [];
$categories = explode(self::DELIMITER_CATEGORIES, $categoriesString);
$categories = explode($categoriesSeparator, $categoriesString);

foreach ($categories as $category) {
$categoriesIds[] = $this->upsertCategory($category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
$values = explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData[$attrCode]);
$valid = true;
foreach ($values as $value) {
$valid = $valid || isset($attrParams['options'][strtolower($value)]);
$valid = $valid && isset($attrParams['options'][strtolower($value)]);
}
if (!$valid) {
$this->_addMessages(
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/CatalogImportExport/Model/Import/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected function _validateFile()
&& method_exists($params['object'], $params['method'])
&& is_callable([$params['object'], $params['method']])
) {
$params['object']->{$params['method']}($filePath);
$params['object']->{$params['method']}($this->_directory->getAbsolutePath($filePath));
}
}
}
Expand Down Expand Up @@ -314,4 +314,12 @@ protected function _moveFile($tmpPath, $destPath)
return false;
}
}

/**
* {@inheritdoc}
*/
protected function chmod($file)
{
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function setUp()

public function testUpsertCategories()
{
$categoryIds = $this->categoryProcessor->upsertCategories(self::CHILD_CATEGORY_NAME);
$categoryIds = $this->categoryProcessor->upsertCategories(self::CHILD_CATEGORY_NAME, ',');
$this->assertArrayHasKey(self::CHILD_CATEGORY_ID, array_flip($categoryIds));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function testIsBooleanAttributeValid()
[
'type' => 'boolean',
'apply_to' => ['simple'],
'is_required' => false
'is_required' => false,
'options' => ['yes' => 0, 'no' => 1]
],
[
'product_type' => 'simple',
Expand Down

0 comments on commit b725daa

Please sign in to comment.