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?

asked Apr 24, 2017 at 6:22

2 Answers 2

3

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');
answered Apr 24, 2017 at 6:55
7
  • Thanks kingshuk, Do you have any idea of getData from custom attribute ? Commented Apr 24, 2017 at 7:26
  • $productObj->getAttributeCode(); Do you mean this? Commented Apr 24, 2017 at 7:30
  • Let me check this one Commented Apr 24, 2017 at 7:31
  • not its not working for me, i am not able to get attribute like this. Commented Apr 24, 2017 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. Commented Apr 24, 2017 at 9:57
1

You can set it like:

$prodcut->setAttributeName(1);

$prodcut->save();

answered Apr 24, 2017 at 6:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.