for people having problems with the code above,
like: calling the getModelInstance () member function for a non-object
you need to add the following to the top of the file:
include 'app/Mage.php'; Mage::app();
edit:
im using magento 1.8.1.0 and the code still doesn't work
I had to add the following line to $ newItem, so the check passes
->setAttributeCode($attCode)
Jorg van rossem
source share