简体   繁体   中英

Multiple complexFilter in Magento's api v2

Currently I'm having some difficulties with using new Magento's soap v2 from c# interface.

With php i was able to do something like this:

$params["created_at"]["from"] = date("Y-m-d H:i:s",Functions::convert_time($dataDa));
$params["created_at"]["to"] = date("Y-m-d H:i:s",Functions::convert_time($dataA));
MageInterface::getSingleton()->shipmentList($params); 

In this mode i was able to find list of orders which were created from $dataDa to $dataA without problems. With c# however it seems that only the last one of the selectors work.

My code:

var cpf = new complexFilter[2];
cpf[0] = new complexFilter
                    {
                        key = "created_at",
                        value = new associativeEntity
                        {
                            key = "to",
                            value = uxDataA.DateTime.ToString("yy-MM-dd HH:mm:ss")
                        }
                    });
cpf[1] = new complexFilter
                    {
                        key = "created_at",
                        value = new associativeEntity
                        {
                            key = "from",
                            value = uxDataDa.DateTime.ToString("yy-MM-dd HH:mm:ss")
                        }
                    });
var filters = new filters();
filters.complex_filter = cpf;
var risultato = mage.salesOrderList(sessionKey, filters); 

In this mode only created_at->from criteria is taken in consideration (it's like second complex filter override previous one with the same key). Ideas?

Thanks in advance.

This works for me :

private filters addFilter(filters filtresIn, string key, string op, string value)
    {
        filters filtres = filtresIn;
        if (filtres == null)
            filtres = new filters();

        complexFilter compfiltres = new complexFilter();
        compfiltres.key = key;
        associativeEntity ass = new associativeEntity();
        ass.key = op;
        ass.value = value;
        compfiltres.value = ass;

        List<complexFilter> tmpLst;
        if (filtres.complex_filter!=null)
            tmpLst = filtres.complex_filter.ToList();
        else tmpLst = new List<complexFilter>();

        tmpLst.Add(compfiltres);

        filtres.complex_filter = tmpLst.ToArray();

        return filtres;
    }

and call

{
Mage_Api_Model_Server_V2_HandlerPortTypeClient clientSoap = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();

        string sessionId = clientSoap.login(LOG, PASS);           
        filters filtres = new filters();    

        filtres = addFilter(filtres, "status", "eq", "processing");
        filtres = addFilter(filtres, "created_at", "from", "2014-09-07 08:00:00");
        filtres = addFilter(filtres, "created_at", "to", "2014-09-07 00:00:00");

        salesOrderEntity[] lst = clientSoap.salesOrderList(sessionId, filtres);
}

Solved, there was a bug (or the feature?) in mage\\sales\\order\\api\\v2.php

See more info in this thread: http://www.magentocommerce.com/boards/viewthread/70368/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM