Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection of improvements #368

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public function processCategoryImport($data, $behavior = NULL)
$entityAdapter->setUnsetEmptyFields($this->getUnsetEmptyFields());
$entityAdapter->setSymbolEmptyFields($this->getSymbolEmptyFields());
$entityAdapter->setSymbolIgnoreFields($this->getSymbolIgnoreFields());
$entityAdapter->setAllowRenameFiles($this->getAllowRenameFiles());
$this->setEntityAdapter($entityAdapter);
$validationResult = $this->validateSource($data);
if ($this->getProcessedRowsCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AvS_FastSimpleImport_Model_Import_Entity_Category extends Mage_ImportExpor
* Size of bunch - part of entities to save in one step.
*/
const BUNCH_SIZE = 20;
protected $_useConfigAttributes = array('available_sort_by', 'default_sort_by', 'filter_price_range');

/**
* Data row scopes.
Expand Down Expand Up @@ -191,6 +192,9 @@ class AvS_FastSimpleImport_Model_Import_Entity_Category extends Mage_ImportExpor
/** @var bool|string */
protected $_symbolIgnoreFields = false;

/** @var bool */
protected $_allowRenameFiles = true;

protected $_defaultAttributeSetId = 0;

public function setIgnoreDuplicates($ignore)
Expand All @@ -215,6 +219,22 @@ public function setUnsetEmptyFields($value) {
}


/**
* @param string $bValue
* @return $this
*/
public function setAllowRenameFiles($bValue) {
$this->_allowRenameFiles = $bValue;
return $this;
}

/**
* @return bool
*/
public function getAllowRenameFiles() {
return $this->_allowRenameFiles;
}

/**
* @param string $value
* @return $this
Expand Down Expand Up @@ -669,6 +689,7 @@ protected function _getUploader()
$this->_fileUploader->init();
$this->_fileUploader->removeValidateCallback('catalog_product_image');
$this->_fileUploader->setFilesDispersion(false);
$this->_fileUploader->setAllowRenameFiles($this->getAllowRenameFiles());

$tmpDir = Mage::getConfig()->getOptions()->getMediaDir() . '/import';
$destDir = Mage::getConfig()->getOptions()->getMediaDir() . '/catalog/category';
Expand Down Expand Up @@ -834,6 +855,20 @@ protected function _getCategoryName($rowData)
return end($categoryParts);
}

protected function isAttributeUsingConfig($attrCode, $rowData)
{
if (!in_array($attrCode, $this->_useConfigAttributes)) {
return false;
}

$key = 'use_config_' . $attrCode;
if (!empty($rowData[$key])) {
return true;
}

return false;
}

/**
* Validate data row.
*
Expand Down Expand Up @@ -920,7 +955,8 @@ public function validateRow(array $rowData, $rowNum)
foreach ($this->_attributes as $attrCode => $attrParams) {
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
$this->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
} elseif ($attrParams['is_required'] && !isset($this->_categoriesWithRoots[$root][$category])) {
} elseif ($attrParams['is_required'] && !isset($this->_categoriesWithRoots[$root][$category])
&& !$this->isAttributeUsingConfig($attrCode, $rowData)) {
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
}
}
Expand Down Expand Up @@ -1405,7 +1441,14 @@ protected function _saveOnTab()
$onTapRow['smart_attributes'] = serialize($onTapRow['smart_attributes']);
}

if (count($onTapRow) <= 1) {
// Remove all not needed entries
$isValidEntry = false;
foreach ($onTapRow as $key => $value) {
if ($value !== '' && $key !== 'category_id') {
$isValidEntry = true;
}
}
if ($isValidEntry === false) {
unset($onTapData[$catId]);
}
}
Expand Down
Loading