tags:

views:

2198

answers:

3

I’m uploading products via the Magento API and they are not showing up in the frontend. I have to go into the backend, open them up, change nothing, save the product and then it will appear.

Any idea why? I assume the act of saving it in the back end, is saving some extra flags in the DB, I just don’t know what.

+1  A: 

I've seen a lot of cases where something inserted into the Magento databases manually, or via the API, will have a missing attribute that, for whatever reason, is set to a default value when saved in the Magento UI. The UI is setting the default values properly, whereas the API or database inserts don't set the attribute.

So, in your case, my first line of debugging would be

  1. "Upload" [sic] a product with the API (what API methods are you using? Or are you using a custom API?)
  2. Take a snapshot of the attribute values for that product
  3. Save the product via the Magento UI
  4. Take a snapshot of the attribute values for that product
  5. Diff #2 and #4
  6. Ensure that your "upload" [sic] method sets any attributes that are present in #4 but not #2

Magento uses an Entity Attribute Value modeling scheme, which optimizing for database flexibility rather than querying. Long story short, you can run the following queries to get your basic product attribute values.

You'll want to replace every instance of [3455] with the a product id from your database. You can get this ID by examining the URL of a proudct in the Magento Admin UI. You can run the query without the WHERE clauses, although the default indexing isn't optimized for this use case, and you'll get a slowish query depending on your database size.

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_varchar.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_varchar ON catalog_product_entity.entity_id = catalog_product_entity_varchar.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_varchar.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455

UNION

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_text.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_text ON catalog_product_entity.entity_id = catalog_product_entity_text.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_text.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455

UNION

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_datetime.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_datetime ON catalog_product_entity.entity_id = catalog_product_entity_datetime.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_datetime.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455

UNION

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_decimal.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_decimal ON catalog_product_entity.entity_id = catalog_product_entity_decimal.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_decimal.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455

UNION

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_gallery.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_gallery ON catalog_product_entity.entity_id = catalog_product_entity_gallery.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_gallery.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455

UNION

SELECT eav_attribute.frontend_label, eav_attribute.attribute_code,
catalog_product_entity_int.value
FROM catalog_product_entity
LEFT JOIN catalog_product_entity_int ON catalog_product_entity.entity_id = catalog_product_entity_int.entity_id
LEFT JOIN eav_attribute on catalog_product_entity_int.attribute_id = eav_attribute.attribute_id
WHERE catalog_product_entity.entity_id = 3455;
Alan Storm
Thanks Alan! its very kind of you to post this. This has been very frustrating, ill try what you say and come back with the results.
Dan
I used your SQL to compare and there where quite a few extra properties that were set with empty strings. So I set all of them. And that didnt seem to have an effect. In the wend it boiled down to me setting mageProduct.websites = new[] { "base" };
Dan
A: 

@Steve Madsen. here is the code, I don't think I'm missing anything crucial, as the backend interface would prompt me of it, then I open of the product.

public void Import(Product product)
        {
            var mageProduct = new catalogProductCreateEntity();
            mageProduct.name = product.Name;
            mageProduct.description = product.Description;
            mageProduct.price = product.Price.ToString();
            mageProduct.short_description = product.ShortDescription;
            mageProduct.description = product.Description;
            mageProduct.status = "1";
            mageProduct.weight = "0";
            mageProduct.tax_class_id = "2";

            mageProduct.gift_message_available = "0";


            var additionalattributes = new associativeEntity[4];

            var entity = new associativeEntity();
            entity.key = "ship_price";
            entity.value = product.PostageCost;
            additionalattributes[0] = entity;

            entity = new associativeEntity();
            entity.key = "depth_cm";
            entity.value = product.Depth;
            additionalattributes[1] = entity;

            entity = new associativeEntity();
            entity.key = "height_cm";
            entity.value = product.Height;
            additionalattributes[2] = entity;

            entity = new associativeEntity();
            entity.key = "width_cm";
            entity.value = product.Width;
            additionalattributes[3] = entity;

            mageProduct.additional_attributes = additionalattributes;

            _m.catalogProductCreate(MageSessionProvider.GetSession(), "simple", "26", product.SKU, mageProduct);

            var stock = new catalogInventoryStockItemUpdateEntity();
            stock.manage_stock = 0;
            stock.qty = "0";

            _m.catalogInventoryStockItemUpdate(MageSessionProvider.GetSession(), product.SKU, stock);
            Console.WriteLine(product.Name + " imported");
        }
Dan
A: 

"I used your SQL to compare and there where quite a few extra properties that were set with empty strings. So I set all of them. And that didn't seem to have an effect. In the end it boiled down to me setting mageProduct.websites = new[] { "base" }; – Dan Jun 16 at 14:12"

Thanks Dan! This worked for me. The class code sample shows mageProduct.websites = new[] { "0" }; which is incorrect, I changed it to mageProduct.websites = new[] { "base" }; and it works.