Magento News

 

Magento: Bug Found – “Invalid option ID specified …” on Export

Version Tested: 1.4.1.1 Not sure if this bug exists yet in any other versions.

I was doing a product export today with Magento’s built-in export profile “Export All Products”. I noticed that there were hundreds of errors like this:

"Invalid option ID specified for region_code (59), skipping the record. (Line 134, SKU: AV71146)"

So, I checked everything I could to make sure it was setup properly: I checked the product, and a value was assigned (it’s a dropdown in my case), I checked the attribute itself to make sure that “59″ was a valid option id, I checked the database to make sure nothing looked out of whack both on the product, and the option and values. Everything seemed fine.

I then decided to search the code for “skipping the record”, and I came across this file: app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php. Lines 434-440 are displayed below:

if ($attribute->usesSource()) {
  $option = $attribute->getSource()->getOptionText($value);
  if ($value && empty($option)) {
    $message = Mage::helper('catalog')->__("Invalid option ID specified for %s (%s), skipping the record.", $field, $value);
    $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);
    continue;
  }

I did some logging and found out that the getOptionText() method was indeed returning the proper values. The kicker is this: One of the values for this particular attribute is the number zero ’0′. So, the second line sets $option to 0. Then, when it runs if ($value && empty($option)), it then assumes $option is actually empty because it’s 0, thus throwing the error on the export results.

The Problem: You cannot use the number 0 as an option for a dropdown or multiselect attribute option.
The Fix: Rename the option, or better yet, Magento should fix the code to allow for 0 as an option.


Magento: Bug Found – “Invalid option ID specified …” on Export

Possibly Related Posts:


 

Leave a Reply