我正在使用visualstudio 2010服务引用来使用magento soap v2 api web服务。
php 5.3.8,magento 1.6安装在windows 7 iis 7.5 上
我可以登录并列出所有产品,但只要我放入过滤器,就会出现异常
在非对象上调用成员函数getBackend()
php错误日志:
PHP致命错误:调用C:\inetpub\wwwroot\Magento1620\app\code\core\Mage\Eav\Model\Entity\Abstract.PHP中的非对象上的成员函数getBackend(),位于第816行
static void TestMagentoSoapV2Wcf()
{
MagentoService magentoService = new MagentoService();
MageSvcRef.associativeEntity assoEntity = new MageSvcRef.associativeEntity();
assoEntity.key = "like";
assoEntity.value = "n2610";
MageSvcRef.complexFilter complexFilter = new MageSvcRef.complexFilter();
complexFilter.key = "sku";
complexFilter.value = assoEntity;
MageSvcRef.complexFilter[] compFilters = new MageSvcRef.complexFilter[1];
compFilters[0] = complexFilter;
MageSvcRef.filters filters = new MageSvcRef.filters();
filters.complex_filter = compFilters;
string sessionId = magentoService.login("zzc000", "zzc000");
var products = magentoService.catalogProductList(sessionId, filters, string.Empty);
}
请帮助
感谢
这似乎是一个Magento错误,但我不确定,因为我不是PHP开发人员,它可能只反映了Magento和PHP在windows 上的安装
修改这个文件
appcodecoreMageCatalogModelProductApiV2.php
57-62线
foreach ($filters->complex_filter as $_filter) {
$_value = $_filter->value;
$preparedFilters[$_filter->key] = array(
$_value->key => $_value->value
);
}
至
foreach ($filters->complex_filter as $_field => $_filter) {
$preparedFilters[$_field] = array(
$_filter->key => $_filter->value
);
}
我还注意到,在不同的V2.php文件中,这段代码的编写方式不同。客户API与产品相同,但订单API是这样写的
foreach ($filters->complex_filter as $_filter) {
$_value = $_filter->value;
if(is_object($_value)) {
$preparedFilters[][$_filter->key] = array(
$_value->key => $_value->value
);
} elseif(is_array($_value)) {
$preparedFilters[][$_filter->key] = array(
$_value['key'] => $_value['value']
);
} else {
$preparedFilters[][$_filter->key] = $_value;
}
}
有人能指出PHP中正确的数组用法吗?