簡體   English   中英

使用C#中的Magento SOAP API V2獲取給定產品ID的制造商名稱

[英]Getting the Manufacturer's Name for a Given Product ID using Magento SOAP API V2 in C#

給定產品代碼,我需要獲得制造商的名稱 以下代碼存根返回制造商的ID(值,如109、120等)。 有沒有辦法讓制造商的名稱插入ID? 我可以看到在PHP中有一些很好的例子可以解決這個問題,但是我正在C#中尋找答案。 任何幫助將不勝感激! 謝謝您的期待!

當前代碼是:

        public bool GetProductInfo(salesOrderItemEntity objProduct, ref StructProductInfo structProductInfo)
        {
            bool bSuccess = false;

            catalogProductRequestAttributes attrib = new catalogProductRequestAttributes();

            attrib.additional_attributes = new string[] { "manufacturer" };

            catalogProductReturnEntity objProductInfo = null;

            objProductInfo = mservice.catalogProductInfo(mlogin, objProduct.product_id, "default", attrib, null);

            if (null != objProductInfo)
            {
                associativeEntity[] assoc = objProductInfo.additional_attributes;
                structProductInfo.ManufacturerCode = assoc[0].value;
                bSuccess = true;
            }

            return bSuccess;
        }

默認情況下,制造商為整數“ eav_attribute”,這就是為什么您將獲得整數值的原因。

您需要加入以磁電機設置的制造商數據。

不確定從API端獲取該數據的方法。

也許嘗試使用屬性選項而不是其他屬性,然后獲取該選項的標簽。

想通了如何做到這一點。 “ 102”是“制造商”的屬性代碼。 將其與catalogProductAttributeOptions()結合使用,我建立了一個基於哈希表的小型查詢,以獲取制造商的名稱(給定制造商的代碼)。

public void CreateManufacturerLookup()
{
    mhtManufacturers.Clear();  // mhtManufacturers is a hashtable declared with class scope

    catalogAttributeOptionEntity[] caoe = mservice.catalogProductAttributeOptions(mlogin, "102", "default");  // mlogin is the session ID and is available at class scope

    if (caoe.Length > 0)
    {
        for (int i = 0; i < caoe.Length; i++)
        {
            mhtManufacturers.Add(caoe[i].value, caoe[i].label);
        }
    }
}

因此,可以通過以下方式獲得制造商的名稱:

sManufacturerName = (string) mhtManufacturers[sManufacturerCode];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM