0

I'm trying to import products from csv by calling an external script. I've done the same for export and this has been smooth. However, import is failing, as it doesn't seem to properly translate the attribute options. Also Error messages aren't properly translated.

See this minimized code:

Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//already tried all of the following....
Mage::getSingleton('core/translate')
    ->setLocale(Mage::app()->getLocale()->getLocaleCode())
    ->init('adminhtml', true);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_ADMINHTML);
//very basic import code
$import = Mage::getModel('importexport/import');
$import->setEntity('catalog_product');
$import->validateSource("/tmp/test.csv");
foreach ($import->getErrors() as $errorCode => $rows) {
     echo $errorCode . ' in rows: ' . implode(', ', $rows);
}

Now, this gives all rows invalid. Strangely, I get something like this

0 in rows: 1, 1, 8, 8, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 44, 44{{{Orphan rows that will be skipped due default row errors}}{{Orphan rows that will be skipped due default row errors}}{{Orphan rows that will be skipped due default row errors}}{{Mage_ImportExport}}} in rows: 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47Checked rows: 47, checked entities: 9, invalid rows: 47, total errors: 5673

I debugged my way through the magento code base. The first Error "0" is actually Mage_ImportExport_Model_Import_Entity_Abstract saying:

 $this->addRowError(Mage::helper('importexport')->__("Invalid value for '%s'"), $rowNum, $attrCode);

And this again because it can't match an attribute option "Konfiguration verwenden" against the attributes options, because there something similar to the other error messagesgoes havoc with the translation, i.e. it has multile {{{/}}} seperated string.

Any clue? Sounds like I'm missing a single line.

regards Alex

1 Answer 1

2

OK. I learned this multi curly braces string is actually a data structure from magento used for inline translate. I forcefully switched of the inline translate with setTranslateInline(false), this did the trick. Import is still not error free, but this is likely another topic... for reference, working code is:

Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//already tried all of the following....
Mage::getSingleton('core/translate')
    ->setLocale(Mage::app()->getLocale()->getLocaleCode())
    ->init('adminhtml', true)
    ->setTranslateInline(false);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_ADMINHTML);
//very basic import code
$import = Mage::getModel('importexport/import');
$import->setEntity('catalog_product');
$import->validateSource("/tmp/test.csv");
foreach ($import->getErrors() as $errorCode => $rows) {
     echo $errorCode . ' in rows: ' . implode(', ', $rows);
}
1
  • Wow seriously? That's absurd. You'd think someone would abstract out a programmatic admin interface of some kind. Thanks though. My product rules can be applied programatically now.
    – CarComp
    Apr 2, 2018 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.