0

I'm facing a strange issue or may be i'm not clear about how magento saves values in to DB.

I have created a custom attribute for the product namely "seller_id" its properties are as follows.

enter image description here

Following are the frontend properties enter image description here

Please read my Edit.

And i'm using a custom code to save product to the DB. Where i use

$product->setSellerId(23);
$product->save();

The code seems to be working properly. After running the code when i check the product details from adminpanel, i can see that value is set for seller_id.

The problem is when i try to access this attribute from the product listing page it is not returning the saved value. So i went to Attribute configuration section and set "Used in Product Listing Page" to "Yes". You can see this in the second image. But still its not returning the saved value.

As per my understanding since seller_id's input type is "TextField", the value should be saved in "catalog_product_entity_varchar". Querying the "eav_attribute" table reveled that seller_id's attribute_id is 136. So i executed following sql in the Db.

SELECT * FROM `catalog_product_entity_varchar` WHERE attribute_id=136

To my surprise it returned an empty result set. So i went back to the adminpanel opened a product details page (Catalog->Manage Products) clicked "Edit" and Clicked "Save" button for a product (Please note that i can see value for seller_id in Adminpanel for a product).

After saving the details for product i tried executing the above query once again and now its returning a row for product which i have just saved. And also now i'm able to get the value for seller_id in the product listing page.

So question is why values is not getting saved in "catalog_product_entity_varchar" table even if i'm doing $product->save();. How the value is showing in adminpanel even though its not getting saved table?

EDIT : This particular attribute "seller_id" was created long time ago. While the attribute created the option "Used in Product Listing" was set to "No". But now i need to access it in the Product Listing page. So i set this option to Yes and did Reindexing. But still seller_id is not accessible in the product listing page.

  • When we create an attribute with type "TextField" its value will be stored into catalog_product_entity_text table. Since my attribute was created long time ago all the datas where saved in this table. When i changed the property of this attribute to use "Used in Product Listing" magento will update its backend type to "Varchar" so from now onwards when we query the database magento will look in varchar table instead of text table. I thought that after changing the attribute property running the index will update all existing data from text to varchar. but its not happening for some reason. – nikhil Dec 2 '16 at 5:11
0

Try $product->setData('seller_id',23); instead of $product->setSellerId(23);

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.