2

I created a custom Yes/No attribute for products and assigned it to default attribute group. I have to save value of Yes/No attribute programmatically. is it possible? if Yes, How can I manage product value programmatically?

1

Use this if you dont want to save the whole product. Its much faster.

$productObj->setData('attribute_code', 1); //$value = 1 for yes and $value = 0 for No.
$productObj->getResource()->saveAttribute($productObj, 'attribute_code');
  • Thanks kingshuk, Do you have any idea of getData from custom attribute ? – Pankaj Sharma Apr 24 '17 at 7:26
  • $productObj->getAttributeCode(); Do you mean this? – Kingshuk Deb Apr 24 '17 at 7:30
  • Let me check this one – Pankaj Sharma Apr 24 '17 at 7:31
  • not its not working for me, i am not able to get attribute like this. – Pankaj Sharma Apr 24 '17 at 9:50
  • Probably that attribute has no value assigned yet. Either set it to YES or No then save the product and check on frontend. You should be able to get it. – Kingshuk Deb Apr 24 '17 at 9:57
0

You can set it like:

$prodcut->setAttributeName(1);

$prodcut->save();

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.