Skip to content

Instantly share code, notes, and snippets.

@paales
Created December 12, 2013 20:15
Show Gist options
  • Save paales/7934644 to your computer and use it in GitHub Desktop.
Save paales/7934644 to your computer and use it in GitHub Desktop.
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
index 6c815ed68827dded619ecac227eda53ec860abf6..aa8e7d3812d7179fc254b47cbacbf89295a8a3f0 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
@@ -278,13 +278,17 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
$this->_dataSourceModel->cleanBunches();
while ($source->valid() || $bunchRows) {
+ //if the row scope isn't default we aren't finished with this entity
+ if ($startNewBunch && $source->valid() && !$this->_isRowScopeDefault($source->current())) {
+ $startNewBunch = false;
+ }
+
if ($startNewBunch || !$source->valid()) {
$this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows);
- $bunchRows = $nextRowBackup;
+ $bunchRows = array();
$productDataSize = strlen(serialize($bunchRows));
$startNewBunch = false;
- $nextRowBackup = array();
}
if ($source->valid()) {
if ($this->_errorsCount >= $this->_errorsLimit) { // errors limit check
@@ -300,12 +304,11 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
$isBunchSizeExceeded = ($bunchSize > 0 && count($bunchRows) >= $bunchSize);
+ $bunchRows[$source->key()] = $rowData;
+ $productDataSize += $rowSize;
+
if (($productDataSize + $rowSize) >= $maxDataSize || $isBunchSizeExceeded) {
$startNewBunch = true;
- $nextRowBackup = array($source->key() => $rowData);
- } else {
- $bunchRows[$source->key()] = $rowData;
- $productDataSize += $rowSize;
}
}
$source->next();
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
index ab7336200218967e7af784bbc4cffab8aae7a3bb..1bb5213d95594c8abe8a8e302fdae19b2a678bbc 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
@@ -514,6 +514,16 @@ class Mage_ImportExport_Model_Import_Entity_Customer extends Mage_ImportExport_M
}
/**
+ * Returns boolean TRUE if row scope is default (fundamental) scope.
+ *
+ * @param array $rowData
+ * @return bool
+ */
+ protected function _isRowScopeDefault(array $rowData) {
+ return strlen(trim($rowData[self::COL_EMAIL])) ? true : false;
+ }
+
+ /**
* Obtain scope of the row from row data.
*
* @param array $rowData
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
index fcf6d8d2c0f54623ec8bfe3de7f73701e2edc5bb..ea50836fd79e35699d7a61550ad7f8385d39d29c 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
@@ -1814,6 +1814,20 @@ class Mage_ImportExport_Model_Import_Entity_Product extends Mage_ImportExport_Mo
return $this->_oldSku;
}
+
+ /**
+ * Returns boolean TRUE if row scope is default (fundamental) scope.
+ *
+ * @param array $rowData
+ * @return bool
+ */
+ protected function _isRowScopeDefault(array $rowData) {
+ if (isset($rowData[self::COL_SKU]) && strlen(trim($rowData[self::COL_SKU]))) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Obtain scope of the row from row data.
*
@leo-leung
Copy link

It is such a great patch if you need to import product with many lines in multiple sites(scope)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment