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
Pankaj Sharma
1,3912 gold badges21 silver badges41 bronze badges
2 Answers 2
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
Kingshuk Deb
1,2142 gold badges11 silver badges31 bronze badges
-
Thanks kingshuk, Do you have any idea of getData from custom attribute ?Pankaj Sharma– Pankaj Sharma2017年04月24日 07:26:49 +00:00Commented Apr 24, 2017 at 7:26
-
$productObj->getAttributeCode();Do you mean this?Kingshuk Deb– Kingshuk Deb2017年04月24日 07:30:26 +00:00Commented Apr 24, 2017 at 7:30 -
Let me check this onePankaj Sharma– Pankaj Sharma2017年04月24日 07:31:09 +00:00Commented Apr 24, 2017 at 7:31
-
not its not working for me, i am not able to get attribute like this.Pankaj Sharma– Pankaj Sharma2017年04月24日 09:50:49 +00:00Commented 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.Kingshuk Deb– Kingshuk Deb2017年04月24日 09:57:04 +00:00Commented Apr 24, 2017 at 9:57
You can set it like:
$prodcut->setAttributeName(1);
$prodcut->save();
answered Apr 24, 2017 at 6:42
BornCoder
1,5185 gold badges20 silver badges46 bronze badges
default