Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:39:44+00:00 2026-06-09T16:39:44+00:00

I am using the following code in order to add images to an existing

  • 0

I am using the following code in order to add images to an existing product in Magento.

Mage::app()->setCurrentStore($target_store);
$product = Mage::getModel("catalog/product")->loadByAttribute($sku);
$product->addImageToMediaGallery(
    $local_img_path,
    array('image', 'thumbnail', 'small_image'),
    false,
    false
);
$product->save();

Once I execute this for all the products I need to update/add, I reindex all and clear cache. The images do not show up in the admin area for the product. However the image does show on the frontend product detail page, but not on the small images on the category list page.

Checking the database, there are the following 3 relevant entries for the product in catalog_product_entity_varchar:

value_id  entity_type_id  attribute_id  store_id  entity_id  value
888509    4               79            4         35743      /t/e/tempimg_791.jpg
888332    4               80            4         35743      /t/e/tempimg_791.jpg
888333    4               81            4         35743      /t/e/tempimg_791.jpg

There are the base, small, and thumb images for the frontend store. Now if I run the following SQL query to find all rows in catalog_product_entity_varchar having store_id 4 and attribute_id 79 that do not have a corresponding entry with store_id 0, and creates a corresponding row:

INSERT INTO catalog_product_entity_varchar
(entity_type_id, attribute_id, store_id, entity_id, value) 
SELECT DISTINCT 4, 79, 0, entity_id, value
FROM catalog_product_entity_varchar AS cpev
WHERE attribute_id = 79
AND store_id != 0
AND entity_id
IN (
    SELECT entity_id
    FROM catalog_product_entity_varchar
    WHERE store_id = 4
    AND attribute_id = 79
    AND entity_id NOT 
    IN (
        SELECT entity_id
        FROM catalog_product_entity_varchar
        WHERE store_id = 0
        AND attribute_id = 79
    )
) ON DUPLICATE KEY UPDATE value = cpev.value;

And then do the same again twice, replacing the 79’s with 80 and then again with 81, I get the following relevant rows in catalog_product_entity_varchar:

value_id  entity_type_id  attribute_id  store_id  entity_id  value
888509    4               79            4         35743      /t/e/tempimg_791.jpg
888332    4               80            4         35743      /t/e/tempimg_791.jpg
888333    4               81            4         35743      /t/e/tempimg_791.jpg
888605    4               79            0         35743      /t/e/tempimg_791.jpg
888606    4               80            0         35743      /t/e/tempimg_791.jpg
888607    4               81            0         35743      /t/e/tempimg_791.jpg

the images now show up in the front end on the category listings, but STILL not in the admin area for the product.

Now, I execute the following query, to add an entry into catalog_product_entity_media_gallery representing the image already set in the previous queries:

INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, value)
SELECT 82, entity_id, value FROM catalog_product_entity_varchar AS cpev
WHERE attribute_id = 79 AND store_id = 0 AND
entity_id IN (
    SELECT entity_id
    FROM catalog_product_entity_varchar
    WHERE store_id = 4
      AND attribute_id = 79
      AND entity_id NOT IN (
        SELECT entity_id
        FROM catalog_product_entity_media_gallery
        WHERE attribute_id = 82
    )
) ON DUPLICATE KEY UPDATE value = cpev.value;

Once this is done, and a reindex/recache is completed. the Images show up in admin.

There must be a proper way that does not result in me needing to execute 4 SQL queries manually to get the images working properly after an import! What am I doing wrong?

Thanks people.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:39:46+00:00Added an answer on June 9, 2026 at 4:39 pm

    Embarrassing and infuriating – I fixed it by deleting app/code/core/Mage and replacing it with a freshly downloaded copy of that folder. Looks like some of the core files had been edited, and broken in the process.

    The moral of the story – Don’t Edit the Core.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code: db_update('nodesequence_nodes') ->fields(array( 'order' => 1, )) ->condition('nid', 1, '=') ->condition('nsid',
I'm using the following code to scan a folder for images: <?php $dir =
I was using the following Code in order to export a dataset to xlsx.
Dear Folk's i'm using the following code in order to send the bytes of
I'm using the following code with the javax.swing.text.html.parser.ParserDelegator in order to parse hyperlinks from
I'm using the following code to access an HTML data attribute: HTML <p class=add-favorites-to-list>
i have the following code: seatContainer.getChildAt(order.seats[i]) i want to add a child to this
I'm using the following code: $query = $dbh->prepare(INSERT into crm_order_errors .SET (order_id, number_of_attempts, last_attempt)
Using following code I try to get updated list of checkbuttons' corresponding text values,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.