2

我正在通过 Magento API 上传产品,但它们没有出现在前端。我必须进入后端,打开它们,什么都不做,保存产品,然后它就会出现。

知道为什么吗?我假设将它保存在后端的行为是在数据库中保存一些额外的标志,我只是不知道是什么。

@史蒂夫马德森。这是代码,我认为我没有遗漏任何重要的东西,因为后端界面会提示我,然后我打开产品。

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");
        }
4

3 回答 3

3

我已经看到很多手动或通过 API 插入 Magento 数据库的内容会缺少属性,无论出于何种原因,当保存在 Magento UI 中时,该属性被设置为默认值。UI 正在正确设置默认值,而 API 或数据库插入未设置属性。

所以,在你的情况下,我的第一行调试是

  1. “上传” [原文如此] 使用 API 的产品(您使用的是什么 API 方法?或者您使用的是自定义 API?)
  2. 对该产品的属性值进行快照
  3. 通过 Magento UI 保存产品
  4. 对该产品的属性值进行快照
  5. 区分 #2 和 #4
  6. 确保您的“上传”[原文如此] 方法设置了 #4 中存在但不 #2 中的任何属性

Magento 使用实体属性值建模方案,该方案针对数据库灵活性而不是查询进行了优化。长话短说,您可以运行以下查询来获取您的基本产品属性值。

您需要用数据库中的产品 ID 替换 [3455] 的每个实例。您可以通过在 Magento Admin UI 中检查产品的 URL 来获取此 ID。您可以在没有WHERE 子句的情况下运行查询,尽管默认索引并未针对此用例进行优化,并且根据您的数据库大小,您将获得较慢的查询。

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;
于 2009-06-15T22:22:02.683 回答
1

“我使用你的 SQL 进行比较,那里有很多用空字符串设置的额外属性。所以我设置了所有这些属性。这似乎没有效果。最后归结为我设置 mageProduct .websites = new[] { "base" }; – Dan Jun 16 at 14:12"

谢谢丹!这对我有用。类代码示例显示 mageProduct.websites = new[] { "0" }; 这是不正确的,我将其更改为 mageProduct.websites = new[] { "base" }; 它有效。

于 2009-09-16T18:00:27.177 回答
1

这个页面是最有帮助的。在执行 CSV 导入时,我发现我必须添加:_product_websites 并确保将其设置为每个导入产品的基础。还要确保将 is_in_stock 的字段设置为 1,之后我发现导入工作正常。

对我有用的最小字段列表是:sku、_store、_attribute_set、_type、_category、_root_category、description、msrp_display_actual_price_type、msrp_enabled、name、short_description、qty、is_in_stock、status、tax_class_id、visibility、price、weight、_product_websites

样本记录:

ku,_store,_attribute_set,_type,_category,_root_category,description,msrp_display_actual_price_type,msrp_enabled,name,short_description,status,tax_class_id,visibility,price,weight,_product_websites,qty,is_in_stock
CC0003,,Default,simple,Specialist Therapeutics,Products,Conn Test #3,Use config,Use config,Conn Test #3,ConnTest,1,0,4,0,1,base,3000,1
于 2013-02-15T16:33:32.277 回答