Skip to content

Commit

Permalink
UPDATE Item import (category creation error/logging)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Bächtle committed Sep 13, 2013
1 parent 824a780 commit 87d457b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public function getLabel()
*/
public function getVersion()
{
return '1.4.1';
return '1.4.2';
}

/**
Expand Down
34 changes: 27 additions & 7 deletions Components/Import/Entity/PlentymarketsImportEntityItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ protected function setCategories()
{
// Root category id (out of the shop)
$parentId = $this->Shop->getCategory()->getId();

// Trigger to indiate an error while creating new category
$addError = false;

// Split path into single names
$categoryPathNames = explode(';', $Category->ItemCategoryPathNames);
Expand All @@ -366,21 +369,38 @@ protected function setCategories()

try
{
// Create
$CategoryModel = self::$CategoryApi->create($params);

// Log
PlentymarketsLogger::getInstance()->message('Sync:Item:Category', 'Added category "' . $categoryName . '" with parentId ' . $parentId);

// Id to connect with the item
$parentId = $CategoryModel->getId();
}
catch (Exception $e)
catch (Exception $E)
{
// Log
PlentymarketsLogger::getInstance()->error('Sync:Item:Category', 'Cannot create category "' . $categoryName . '" with parentId ' . $parentId);
PlentymarketsLogger::getInstance()->error('Sync:Item:Category', $E->getMessage());

// Set the trigger - the category will not be connected with the item
$addError = true;
}

$parentId = $CategoryModel->getId();
}
}

// Add mapping and save into the object
PlentymarketsMappingController::addCategory($parentId, $Category->ItemCategoryPath);
$this->categories[] = array(
'id' => $parentId
);
// Only create a mapping and connect the cateory to the item,
// of nothing went wrong during creation
if (!$addError)
{
// Add mapping and save into the object
PlentymarketsMappingController::addCategory($parentId, $Category->ItemCategoryPath);
$this->categories[] = array(
'id' => $parentId
);
}
}
}
}
Expand Down

0 comments on commit 87d457b

Please sign in to comment.