duanjiu1003 2009-06-15 15:58
浏览 15
已采纳

Magento API上传的产品没有出现在前端 - 除非它们在后端重新保存

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.

@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");
        }
  • 写回答

3条回答 默认 最新

  • duan0403788996 2009-06-15 22:22
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度