Magento api v2中的多个复杂过滤器

时间:2009-12-17 10:51:39

标签: c# web-services magento

目前我在从c#界面使用新的Magento的soap v2时遇到了一些困难。

使用php,我能够做到这样的事情:

$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); 

在这种模式下,我能够找到从$ dataDa到$ dataA创建的订单列表而没有任何问题。然而,使用c#似乎只有最后一个选择器才能工作。

我的代码:

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

在此模式下,仅考虑条件中的created_at->(就像第二个复杂过滤器使用相同的键覆盖前一个过滤器)。想法?

提前致谢。

2 个答案:

答案 0 :(得分:4)

这对我有用:

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

并致电

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

答案 1 :(得分:0)

解决了,mage \ sales \ order \ api \ v2.php中有一个错误(或功能?)

在此主题中查看更多信息:http://www.magentocommerce.com/boards/viewthread/70368/