使用 magento API V2 限制结果数量
您好,我已经在网站上搜索了我的问题,但没有找到简单的解决方案,我认为这个问题非常基本。
我正在使用 Api V2,所以也许现在有一个解决方案。在这里,这是我的代码:
$api_soap_url = 'http://localhost/magento/api/v2_soap?wsdl=1';
$client = new SoapClient($api_soap_url);
$session_id = $client->__soapCall('login',array($user, $pw));
$data = array($session_id);
$result = $client->__soapCall('customerCustomerList', $data);
这会返回所有结果,我需要限制结果数量,因此我尝试使用此处找到的过滤器和其他解决方案,但没有运气。
我唯一没有尝试过的是这个:
但是按日期过滤并不能解决我的问题,对于如此简单的需求,重写类是一个非常复杂的解决方案。
提前致谢
Hi I have searched the site for my question but haven't found an easy solution and I think the issue is so basic.
I'm using Api V2 so maybe there's a solution now. Here I go, this is my code:
$api_soap_url = 'http://localhost/magento/api/v2_soap?wsdl=1';
$client = new SoapClient($api_soap_url);
$session_id = $client->__soapCall('login',array($user, $pw));
$data = array($session_id);
$result = $client->__soapCall('customerCustomerList', $data);
This returns all results, I need to limit number of result so I have tried using filters and other solutions found here but no luck.
The only one I haven't tried is this one:
Control the number of results from a Magento API call
But filtering by date doesn't solve my problem and rewriting classes is a ver complex solution for such a simple need.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定过滤器可以限制结果数量,但您可以尝试以下操作:
I'm not sure the filter can limit number of result but you can try this:
我最终覆盖了app/code/core/Mage/Sales/Model/Order/Api.php,添加了一个名为“collection.limit”的“特殊魔法”字段。您的里程可能会有所不同;我对 Magento 安装和访问 Magento 安装的程序(在本例中是一组 C# 程序)都有严格的控制。
我的调用者只是使用“魔法字段”作为键/值对,如下所示(请再次测试,我是从 C# 调用的,所以这个 php 应该被认为是可疑的):
在我的 Magento 安装中(这部分经过测试,实时运行),我在本地命名空间中创建了一个 Sales/Model/Order/Api.php 并重写了 items 函数。在该函数的第 32 行左右,您将看到以下内容:
相反,我使用 strncmp 在这里“捕获”我自己的魔法限制器,并在 foreach 内使用 if-else:
我对此并没有过于兴奋,但是,我认为它非常安全并且有效。
I ended up overriding app/code/core/Mage/Sales/Model/Order/Api.php, adding a "special magic" field called "collection.limit". Your mileage may vary; I have tight controls on both the Magento installation and the programs (in this case, a set of C# programs) accessing the Magento installation.
My caller simply uses the "magic field" as a key/ value pair, something like this (please test, again, I was calling from C#, so this php should be considered suspect):
In my Magento installation (this part is tested, live and running), I created a Sales/Model/Order/Api.php in my local namespace and over-rode the items function. Around the 32nd or so line of that function, you'll see this:
Instead, I "catch" my own magic limiter with the strncmp here, with an if-else inside the foreach:
I'm not overly excited by this, but, I think it's pretty safe and it works.