magento web service filter product list error Call

2019-08-02 15:43发布

I'm using visual studio 2010 service reference to consume magento soap v2 api web service.

php 5.3.8, magento 1.6 install on windows 7 iis 7.5

I can log in and list all the product, but as soon as i put a filter there is an exception

Call to a member function getBackend() on a non-object

php error log:

PHP Fatal error: Call to a member function getBackend() on a non-object in C:\inetpub\wwwroot\Magento1620\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 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);
    }

Please help

Thanks

标签: magento
1条回答
We Are One
2楼-- · 2019-08-02 16:14

It seems to be a Magento bug, but I'm not sure since I'm not a PHP developer, it may only reflect Magento and PHP install on windows

modify this file

\app\code\core\Mage\Catalog\Model\Product\Api\V2.php

line 57-62

foreach ($filters->complex_filter as $_filter) {                
            $_value = $_filter->value;
            $preparedFilters[$_filter->key] = array(
                $_value->key => $_value->value
            );
        }

to

foreach ($filters->complex_filter as $_field => $_filter) {
            $preparedFilters[$_field] = array(
                    $_filter->key => $_filter->value
            );
        }

I also notice that in different V2.php file, this piece of code is written differently. The customer API is the same as product, but the order API is written like this

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;
            }
        }

anyone can point out the correct array usage in PHP?

查看更多
登录 后发表回答