I have created a script that tests importing products programmatically into Magento. Unfortunately, I'm having trouble updating a product's custom attribute value - in this case "manufacturer." When I run the below code, I receive a fatal error with method "Invalid method." Does anyone know what I'm doing wrong?

ini_set('display_errors', 1);

    $product = Mage::getModel('catalog/product');
    $rand = rand(1, 9999);
    ->setAttributeSetId(4) // default attribute set
    ->setSku('example_sku' . $rand) // generate a random SKU
    ->setUrlKey('test-product-123') // set url key

    ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) // visible in catalog and search

        'use_config_manage_stock' => 0, // use global config?
        'manage_stock'            => 1, // should we manage stock or not?
        'is_in_stock'             => 1,
        'qty'                     => 5,

    ->setName('Test Product #' . $rand) // add string attribute
    ->setShortDescription('Description') // add text attribute

    // set up prices
    ->setTaxClassId(2)    // Taxable Goods by default

$optionId = Mage::getModel('eav/entity_attribute')->_getAttributeCode('manufacturer', 'PATAGONIA');


I was able to solve my question and update my "manufacturer" attribute using the following code:

$attrCode = 'manufacturer';
$valueText = ('PATAGONIA');
$valueId = Mage::getModel('catalog/product')->getResource()->getAttribute($attrCode)->getSource()->getOptionId($valueText);
$product->setData($attrCode, $valueId);
  • Please accept your own answer :)
    – sv3n
    Jul 6 '17 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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