SOAP API magento 1.9中的ASC和DESC条件
我已经重写了Magento Core(M1.9)的Api模型,并想测试它是如何工作的。它也会返回may记录,我想在测试中设置Sql“order BY Desc | Asc”和“LIMIT”等条件。但是我不知道我应该把提到的条件放在哪里。 以下是我的测试代码:SOAP API magento 1.9中的ASC和DESC条件,magento,soap,Magento,Soap,我已经重写了Magento Core(M1.9)的Api模型,并想测试它是如何工作的。它也会返回may记录,我想在测试中设置Sql“order BY Desc | Asc”和“LIMIT”等条件。但是我不知道我应该把提到的条件放在哪里。 以下是我的测试代码: $username = 'testapi'; $apikey= 'password'; $client = new Zend_XMLRPC_Client('https://www.magentohost.com/index.php/api
$username = 'testapi';
$apikey= 'password';
$client = new Zend_XMLRPC_Client('https://www.magentohost.com/index.php/api/xmlrpc');
$session = $client->call('login', array($username, $apikey));
$filters = array(
array(
'category_id' => 163,
'internal_rating' => 6
//array('product_id'=>'Order by ASC')
));
try {
$message = $client->call('call', array($session, 'catalog_product.list', $filters));
var_dump($message);
} catch (Exception $fault) {
echo $fault->getMessage();
}
如有任何建议,我将不胜感激。请尝试测试以下代码:
$filters = array(
array(
'category_id' => 163,
'internal_rating' => 6,
'order' => 'product_id',
'dir' => 'asc',
'limit' => 100
));
我还没有亲自测试过。我从链接中获取了过滤器参数的格式
也许它也适用于您的情况。您必须重写该类并重写items函数 class=Mage\u目录\u模型\u产品\u Api 功能=项目
public function items($filters = null, $store = null, $extra = [])
{
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter($this->_getStoreId($store))
->addAttributeToSelect('name');
if(isset($extra["cur_page"])) {
$collection->setCurPage($extra["cur_page"]);
}
if(isset($extra["page_size"])) {
$collection->setPageSize($extra["page_size"]);
}
if(isset($extra["order"])) {
$collection->setOrder($extra["order"]["field"], $extra["order"]["type"]);
}
那你可以打电话过来
$filters = [];
$extra = ["cur_page"=>1,"page_size"=>"3","order"=>["field"=>"name", "type"=>"desc"]];
$result= $proxy->call($sessionId, 'catalog_product.list',[$filters,null,$extra]);
我尝试通过GET方法将参数limit、dir、order转换为url请求,如下所示:
$client = new
Zend_XMLRPC_Client('https://www.magentohost.com/index.php/api/xmlrpc?
limit=1&dir=desc&order=created_at');
$session = $client->call('login', array($username, $apikey));
$filters = array(
array(
'category_id' => 174
));
在重写类Mage_Catalog_Model_Product_Api方法项中
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter($this->_getStoreId($store))
->addAttributeToSelect('name')
->addAttributeToSelect('content_downloaded')
;
if (isset($_GET['order']) && isset($_GET['dir'])){
$order = htmlspecialchars(strip_tags($_GET['order']));
$dir = (strtoupper($_GET['dir']) == 'DESC' ) ? 'DESC' : 'ASC';
$collection->setOrder($order, $dir);
}
if (isset($_GET['limit'])){
$limit = intval($_GET['limit']);
$collection->getSelect()->limit($limit);
}
它给出了googd测试。这是哈基姆建议的类似解决方案。谢谢你,阿列克斯。我以前尝试过这种方法,但没有成功。谢谢哈基姆的回答,我没有尝试过你的解决方案,但我认为它会起作用。我解决了我的问题,正如我在回答中所描述的,这和你给出的方法是一样的。知道你对我的看法很有趣。