Magento 1.5, numeric SKUs and productIdentifierType

独自空忆成欢 提交于 2019-12-01 08:11:39

问题


In Magento 1.5, accessing the catalogProductInfo API call from C# like this works with non-numeric SKUs:

catalogProductRequestAttributes fetchattrib = new catalogProductRequestAttributes();
fetchattrib.attributes = new string[] { "name", "description", "and_so_on"};
fetchattrib.additional_attributes = new string[] { "custom_attribs_go_here"};

string storeView = null;
string productIdentifierType = null;
catalogProductReturnEntity ret = m_magentoClient.catalogProductInfo(
    sessionId, sku, storeView, fetchattrib, productIdentifierType);

But with numeric SKUs I get 'Product not exists' errors.
Presumably this is because Magento cannot tell whether you are passing it a product_id or an SKU. Setting the productIdentifierType to 'sku' should fix that, in theory, according to all the documentation I can find:

...
string productIdentifierType = "sku";
...

But it doesn't fix it.
In fact it seems to make it worse, Magento then stops finding non-numeric SKUS.
So presumably "sku" is not the right value to pass.

Anyone got any ideas?


回答1:


Short answer is that there's a bug somewhere preventing the last param of product.update from being set properly (or maybe Varien haven't yet implemented it), which also presents a problem for the method product.info.

A quick workaround (if you don't mind losing the option to update by ID) is just to set the $identifierType in the Product API update() method ):

In app/code/core/Mage/Catalog/Model/Product/Api.php l.198

public function update($productId, $productData, $store = null, $identifierType = 'sku')

And finally load the product within the if ($idBySku) condition of the method getProduct() around l.427 of app/code/core/Mage/Catalog/Helper/Product.php

$productId = $idBySku;
$product->load($productId);

It's a bit of a fudge. I'll have a look for a better workaround as an override; otherwise, maybe someone else can post a better solution.




回答2:


There is a workaround for pure numeric or mixed SKU, that works quiet well for me.

Just add a whitespace at the end of your SKU. Magento will interpret the value as a SKU, because whitespace is non numeric. Internaly Magento trims the whitespace later

This works perfectly from Magento 1.4.x - 1.9. (Edit: Thanks at Brett for testing with 1.9)

Example:

    catalogProductReturnEntity ret = m_magentoClient.catalogProductInfo(sessionId, sku+" ", storeView, fetchattrib, productIdentifierType); 


来源:https://stackoverflow.com/questions/6748142/magento-1-5-numeric-skus-and-productidentifiertype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!