I want to load the product base image (main image) in a custom template.
When I use $this->helper('catalog/image')->init($_product, 'small_image'), it works perfectly.
But the base image shows the placeholder instead.
Can someone help me?
The base image cannot be shown in the product list because it is not loaded in the list.
For any other attribute this would be an easy task, just edit the attribute in the backend and set the flag 'Used in product listing' to Yes.
But, unfortunately, for some reason still unknown to me, you cannot do that for image attributes.
You have to do it manually in the db. (yes I've said it...modify the db manually against all rules that say not to).
First you need to identify the base image attribute.
select *
from
eav_attribute
where
attribute_code = 'image' and
entity_type_id IN
(select
entity_type_id
from
eav_entity_type
where
entity_type_code = 'catalog_product'
)
This should get you one row. Take the id column from the result (for me is 85) and run the following query that will set the attribute as used in product listing.
update
catalog_eav_attribute
set
used_in_product_listing = 1
where
attribute_id = 85
Replace 85 with the value you get from the first select then rebuild your indexes from System->Index Management.
Now you should be able to call the following code with success.
$this->helper('catalog/image')->init($_product, 'image')
Related
I have a PHP frontend with an image gallery. The data/metadata for the images is pulled from a sqlite database table.
Now I'd like the user to be able to tag the images, e.g. giving image1 the tags "boat" & "fish", and giving image2 some other or the same tags. How would I set up the database for this?
My idea is to create a new table where each row is a tag with an ID.
But how do I add these IDs into the image details table to connect both tables? Afaik I can't simply add a new column to the image table that contains the tag ids as an array, since sqlite doesn't support that.
How could I do this?
Yes, you would have to create a new table for tags.
In your case, best thing would be to create an intermediate table, (let's call it image_tag) which has an image_id and a tag_id column. Now if you want to let's say assign two tags to an image, you can just insert 2 records in the image_tag table containing that image's id and the ids of the tags.
This is called a many to many relationship as one image could have more than one tag and more than one image could have one tag.
Maybe this could give you a rough idea:
Image Table
id path
1 image.jpg
Tags Table
id name
1 fish
2 boat
image_tag Table
id image_id tag_id
1 1 1
1 1 2
For more info, please refer to this.
If you don't want to use child table then you can add tag in same row same table using serialize fields.
Like,
$returnValue = serialize(array('fish','boat'));
ID IMAGE TAG
1 Image.jpg a:2:{i:0;s:4:"fish";i:1;s:4:"boat";}
And you can simply read this $returnValue = unserialize($row['TAG']);
I'm having a problem with magento partial reindexing in the EE. When the indexers are set to on save (in system->configuration->(Advanced)Index management) the url_rewrites don't update.
If I save a product in the backend, then look in the table enterprise_catalog_product_rewrite there is no entry for this product and I guess because of this there is no entry in enterprise_url_rewrite which means it doesn't work.
I can see the product in the listing but the url is not SEO friendly and if the url key is entered in the browser it will not display the product.
I've been searching information on how this partial indexing works but there seems to be nothing except how better it is.
I've tried truncating url rewrite related tables manually (like this) but it just messed everything up, so I reverted the database.
I had the same problem where catalog_product_entity_url_key would contain the correct data for each store, and enterprise_url_rewrite would contain the correct request_path > target_path pairs. But no matches would happen because enterprise_catalog_product_rewrite was missing an entry for the given product, or had an entry which was pointing to a url_rewrite_id which didn't exist anymore in enterprise_url_rewrite.
My solution was to rebuild the enterprise_catalog_product_rewrite table with this query:
REPLACE INTO enterprise_catalog_product_rewrite
(`product_id`, `store_id`, `url_rewrite_id`)
(SELECT cpeuk.entity_id as product_id, cpeuk.store_id, eur.url_rewrite_id
FROM catalog_product_entity_url_key cpeuk
INNER JOIN enterprise_url_rewrite eur
ON cpeuk.value = eur.identifier)
The new UNIQUE index of Magento CE 1.8 changes the URL keys in the URL rewrite table. If you have multiple store views and import your products, (so that for each store view the URL key is saved) you automatically have duplicated keys. The update script is smart enough to not throw an error, but to rename all the keys so you’ll end up with something like:
- http://de.example.com/someproduct.html
- http://en.example.com/someproduct1.html
- http://nl.example.com/someproduct2.html
To avoid that, the URL rewrites have to be fixed before the update so that there is one rewrite per product and URL key, and the store views use “Use default”. You can manage that with a single SQL query before the update:
DELETE nondefault
FROM catalog_product_entity_varchar AS nondefault
INNER JOIN catalog_product_entity_varchar AS def ON def.value = nondefault.value
AND def.entity_id = nondefault.entity_id
WHERE def.attribute_id =86
AND nondefault.attribute_id =86
AND nondefault.store_id <>0
AND def.store_id =0
Note that 86 is the ID of the URL key attribute. If you already have updated your system without running this query first, you have to remove the wrongly created URL keys first. This can be done with the following query:
DELETE url_table
FROM catalog_product_entity_url_key url_table
INNER JOIN catalog_product_entity_varchar old_url_table ON url_table.store_id = old_url_table.store_id
AND url_table.store_id <>0
AND old_url_table.store_id <>0
AND url_table.attribute_id = old_url_table.attribute_id
AND url_table.entity_id = old_url_table.entity_id;
I hope this helps! The following link might help you if you have further questions:
http://www.code4business.de/update-magento-enterprise-edition-1-13-0-2/
I've created a new attribute set from "Default" attribute set.But the media_gallery attribute is missing in the new attribute set.So the image uploader is not showing in product edit section.How do I add that system attribute to the set?
This is at least strange. I would suggest trying to re-create an attribute set based on "Default" to check if the problem will happen again.
In any ways, if you want to add a media_gallery attribute to your existing attribute set you have to add a record to eav_entity_attribute table, where relation of EAV entity to attribute set and group is stored:
INSERT INTO eav_entity_attribute
SET entity_type_id = 4,
attribute_set_id = [YOUR_ATTRIBUTE_SET_ID],
attribute_group_id = [YOUR_ATTRIBUTE_GROUP_ID],
attribute_id = [ID_OF_YOUR_MEDIA_GALLERY_ATTRIBUTE by default 82],
sort_order = 4
The ID_OF_YOUR_MEDIA_GALLERY_ATTRIBUTE can be found in eav_attribute table using the following query:
SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'media_gallery'
The YOUR_ATTRIBUTE_SET_ID can be found in eav_attribute_set table using the following query:
SELECT attribute_set_id FROM eav_attribute_set WHERE attribute_set_name = '[GIVEN_NAME_OF_YOUR_ATTRIBUTE_SET]'
And the YOUR_ATTRIBUTE_GROUP_ID can be found in eav_attribute_group table using the following query:
SELECT attribute_group_id FROM eav_attribute_group WHERE attribute_set_id = [YOUR_ATTRIBUTE_SET_ID] AND attribute_group_name = 'Images'
You can also use PHP to assign attributes to attribute sets:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->addAttributeToSet(
'catalog_product', $attributeSetName, $groupName, $attributeCode
);
It is not a programming question, rather it is the question about using Magento as an end-user. I think the question will be deleted soon. However, until it is not, at least this answer may help to solve the problem, thus making people happier.
So all you need is just go to Magento's admin panel -> Catalog -> Attributes -> Manage Attribute Sets. Then select your set to open edit page for it. Drag the media_gallery attribute from the "Unassigned Attributes" list to the appropriate group in the "Groups" list. Save the attribute set.
That's all :)
i have several attribute sets in my magento store. (v. 1.6.2)
When i make a new product "socks" is the default attribute set. But i would like "clothing" to be the default.
How can i change this?
I hope anyone can help.
Original question didn't seem to get answered here and I was looking for what Ronny also wanted.
Found there has been an extension released that does it simply for you.
http://www.magentocommerce.com/magento-connect/default-attribute-set.html
Unfortunately, it's not possible. You should create new product.
To change an existing product attribute set, you can Create a new Attribute Set that contain all the attributes you need
You can either install this extension (Change Attribute Set) or make the changes in the database (you will need to know the products id and attribute set id)
To manually change (Always backup before making changes):
Go to eav_attribute_set table and look for the attribute_set_id of the newly create attribute set (you could also get this in the admin by look at the url www.xxxx/edit/id/10/key/xxx on Edit Attribute Set 'xxxx' page)
After you have a list of all the product ids and corresponding attribute set ids, then go to the table below and update those fields
Table Name : catalog_product_entity
Field Name : attribute_set_id
Field Name : entity_id // is product_id
Another way is to delete those product and recreate using the new attribute set.
It is possible to accomplish what you want by editing the database directly. Only do this if you are comfortable with MySQL commands or another tool like phpMyAdmin.
To make this change you will need to do two things.
Get the ID of your new attribute set, in this case your "clothing" attribute set. You can locate the id in the eav_attribute_set database table or in the browser URL when editing the attribute set from the Magento admin area. I prefer to just use the database since we need to go in there anyways to make the change.Table Name : eav_attribute_set
Column Name: attribute_set_id
Look for the row in the table that has the name you used when you created the new set - it should be pretty obvious, you'll see all the attribute set names in the column called attribute_set_name
Once you have the preferred attribute set ID you then need to visit the eav_entity_type table and update the value in default_attribute_set_id column for the row whereentity_type_id = 4 and entity_type_code = catalog_product. In a fresh installation of Magento, the value to look for in this column is also 4.
Table Name : eav_entity_type
Column Name: default_attribute_set_id
Done! Once you've changed the id value you will notice your preferred attribute set is the one selected by default the next time you go to create a new product. I believe this is what the question was asking for.
NOTE: This should work for both Magento 1 and 2. At the time of writing this post the current Magento versions are: 1.9.2.4 and 2.0.7
Suppose a table for products in database. Now product has an "image" field where i will place the image name "image.jpg". Now i want to display more than one images of same product. image1.jpg, image2.jpg , image3.jpg.How can i add these records into that product table in single field and how to implement it in PHP to display those images. And the same scenario in terms of size of product i.e medium, large, extra large etc.
I will assume you have already weighed the pros and cons of storing a file name instead of storing a BLOB.
This sounds like a 1-to-many relationship. You will want a table that holds -- at a minimum -- the file name and a foreign key (FK) for the product table. Then you can have multiple images pointing to the same product FK. After that, in order to get the image for a single product, you would just do a query such as:
SELECT img.fileName
FROM image_table AS img
JOIN product_table prod ON prod.id = img.prod_id
WHERE prod.id = ID_THAT_YOU_WANT
I'm ignoring issues with SQL injection, but you shouldn't. Don't just append the ID to the query.