将过滤器添加到 Magento Web 服务 API

发布于 2024-11-04 04:17:53 字数 633 浏览 5 评论 0原文

我正在尝试调用 Magento SOAP API 并获取特定时间段内的订单列表。我可以连接到 API 并获取所有订单的列表,但我(一辈子)无法弄清楚如何过滤结果......有什么想法吗?我返回所有订单的代码如下...

$proxy = new SoapClient('http://lalala.freelunchlabs.com/api/v2_soap/?wsdl');

// create authorized session id using api user name and api key
$sessionId = $proxy->login('myusername', 'mypassword');

$filters = array(
    'created_at' => array( '>' => '2011-04-21 02:13:00'),
    'created_at' => array( '<' => '2011-04-21 02:22:00')
);

 // Get order list
$orderinfo = $proxy->salesOrderList($sessionId,array($filters));

print_r($orderinfo);

提前致谢!

查克

I am trying to call the Magento SOAP API and get a list of orders within a certain time period. I can connect to API and get a list of all the orders just fine but I can't (for the life of me) figure out how to filter the results... Any ideas? My Code that return all the orders is below...

$proxy = new SoapClient('http://lalala.freelunchlabs.com/api/v2_soap/?wsdl');

// create authorized session id using api user name and api key
$sessionId = $proxy->login('myusername', 'mypassword');

$filters = array(
    'created_at' => array( '>' => '2011-04-21 02:13:00'),
    'created_at' => array( '<' => '2011-04-21 02:22:00')
);

 // Get order list
$orderinfo = $proxy->salesOrderList($sessionId,array($filters));

print_r($orderinfo);

Thanks in advance!

Chuck

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心奴独伤 2024-11-11 04:17:53

我没有使用 Magento SOAP 2 Api 的经验,但如果 V2 中的过滤器与 V1 中的过滤器工作方式相同,您可以尝试以下操作:

$filters = array(
    'created_at' => array(
        'from' => '2011-04-21 02:13:00',
        'to' => '2011-04-21 02:22:00'
    )
);

I got no experience with the Magento SOAP 2 Api, but if the filters in V2 work the same way as with V1, you could try this:

$filters = array(
    'created_at' => array(
        'from' => '2011-04-21 02:13:00',
        'to' => '2011-04-21 02:22:00'
    )
);
听,心雨的声音 2024-11-11 04:17:53

在 Magento API v2 中,您需要像这样调整“过滤器”数组:

$params = array('complex_filter'=>
    array(
        array('key'=>'created_at','value'=>array('key' =>'from','value' => '2012-07-05 01:01:01'))
    )
);

虽然他们的 API 在此处显示了 API v2 的示例:

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/introduction#api_version_v2

该文档没有指出(如据我所知)在使用条件语句时,您需要将“filter”替换为“complex_filter”。

例如,您可以替换

'key'=>'from"

'key'=>'to'

or

'key'=>'eq'

您可以使用的更完整的条件列表如下:

http://100101.kurodust.net/2008/10/24/magento-api-calls-filter-parameters/

In v2 of the Magento API you need to adjust your 'filters' array like so:

$params = array('complex_filter'=>
    array(
        array('key'=>'created_at','value'=>array('key' =>'from','value' => '2012-07-05 01:01:01'))
    )
);

While their API shows an example of the API v2 here:

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/introduction#api_version_v2

this documentation doesn't indicate (as far as I can tell) that you need to replace 'filter' with 'complex_filter' when using conditional statements.

For example, you could replace

'key'=>'from"

with

'key'=>'to'

or

'key'=>'eq'

A more complete list of conditionals that you can use is here:

http://100101.kurodust.net/2008/10/24/magento-api-calls-filter-parameters/

失与倦" 2024-11-11 04:17:53

我认为不幸的是这里只显示了 PHP 代码。一般来说,使用 SOAP 和 Web 服务的好处之一是语言/实现的独立性。

为了引导其他人朝着正确的方向前进,我提供了适合我的 XML。无论您使用哪种语言进行 SOAP 调用,请求中的以下 XML 格式都应该有效。

例如,使用 Java 和 Apache Axis 2,这是我的 SOAPEnvelope 对象的内容。获取状态为“正在处理”的所有订单的列表:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <salesOrderList xmlns="urn:Magento">
            <sessionId xmlns="">12345asdf</sessionId>
            <filters xmlns="">
                <filter>
                    <associativeEntity>
                        <key>status</key>
                        <value>processing</value>
                    </associativeEntity>
                </filter>
            </filters>
        </salesOrderList>
    </soapenv:Body>
</soapenv:Envelope>

注意,这是 Magento 的 SOAP v2 格式。

I think it's unfortunate that only PHP code is shown here. One of the benefits of using SOAP and web services in general is language/implementation independence.

In order to steer others in the right direction I'm providing the XML that works for me. Whatever language you're using to make your SOAP calls, the following XML format in your request should work.

For example, using Java and Apache Axis 2, this is the contents of my SOAPEnvelope object. Get a list of all orders with status 'processing':

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <salesOrderList xmlns="urn:Magento">
            <sessionId xmlns="">12345asdf</sessionId>
            <filters xmlns="">
                <filter>
                    <associativeEntity>
                        <key>status</key>
                        <value>processing</value>
                    </associativeEntity>
                </filter>
            </filters>
        </salesOrderList>
    </soapenv:Body>
</soapenv:Envelope>

Note, this is the SOAP v2 format for Magento.

刘备忘录 2024-11-11 04:17:53

我使用了它并且它在 SOAP API v2 中工作:

$params = array('complex_filter'=>
    array(
        array('key'=>'created_at','value'=>array('key' =>'from','value' => '2013-05-03 01:01:01')),
        array('key'=>'customer_id','value'=>array('key' =>'eq','value' => 3)),

    ),

);

I used this and it worked in SOAP API v2:

$params = array('complex_filter'=>
    array(
        array('key'=>'created_at','value'=>array('key' =>'from','value' => '2013-05-03 01:01:01')),
        array('key'=>'customer_id','value'=>array('key' =>'eq','value' => 3)),

    ),

);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文