5

We are creating product programtically & inserting values for default attributes with help of below code.

how i can add values for custom attributes .

attribute code : delivery_info , attribute label : Delivery & Return Info

protected function _createProduct($type, $doSave=true, $originalProduct) 
    {

        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

        $product = Mage::getModel('catalog/product');       
        $product->setName($originalProduct->getName()); 
        $product->setDescription('what ever you need here')
                ->setPrice(599)
                ->setTaxClassId(0)    // Taxable Goods by default
                ->setWeight(1)
        ;                   

        if ($doSave)
            $product->save();

        return $product;
    }
2
  • 1
    is it dropdown Attribute ?? Commented Mar 16, 2017 at 12:39
  • @MurtuzaZabuawala its textfield attribute..... Commented Mar 16, 2017 at 12:44

2 Answers 2

2

Just like you do for any other attribute.

 $product->setDeliveryInfo('content goes here');

Just make sure the attribute exists in your database before doing that.

1
  • Before i tried setDelivery_Info Thanks , worked peRFectly today also as always:) Commented Mar 16, 2017 at 12:43
2

As Marius suggested first one is magic method to set data

 $product->setDeliveryInfo('Your Data');

And second one is set data method

 $product->setData('delivery_info','Your data'); //key value pair

and save product and your job is done

Above method will work only if it is a text ,textarea attribute for select and multiselect you need to pass attribute optionId in data

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.