2017-11-10 5 views
2

Magento Core (M1.9)의 Api 모델을 다시 쓰면서 어떻게 동작하는지 테스트하고 싶습니다. 그것은 또한 레코드를 반환 할 수 있으며 SQL "Order Desc | Asc"및 "LIMIT"와 같은 조건을 내 테스트에서 설정하려고합니다. 그러나 나는 언급 된 조건을 어디에 두어야하는지 모른다. 다음은 테스트에 대한 내 코드입니다 :SOAP API magento의 ASC 및 DESC 조건 1.9

나는 어떤 조언을 이해할 수있을 것이다
$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(); 
} 

답변

0

, 아래의 코드를 테스트 해보세요 :

$filters = array(
    array(
     'category_id'  => 163, 
     'internal_rating' => 6, 
     'order'   => 'product_id', 
     'dir'    => 'asc', 
     'limit'   => 100  
)); 

나 자신에 의해 그것을 테스트하지 않았습니다를 . 링크에서 필터 매개 변수의 형식을 취했습니다 http://devdocs.magento.com/guides/m1x/api/rest/get_filters.html 어쩌면 귀하의 경우에도 작동합니다.

+0

감사합니다. Aleks. 나는 전에 이런 식으로 시도했지만 실패했다. –

0

당신은 항목

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]); 
+0

HAKIM에게 감사의 답변을 전합니다. 해결책을 찾지 못했지만 효과가있을 것이라고 생각합니다. 나는 내 대답에 묘사 한대로 내 문제를 해결하고 당신이 준 것처럼 그것을 similarar 방식으로했습니다. 내 것에 대한 당신의 의견을 아는 것은 흥미 롭습니다. –

0

하여 호출 할 수 있습니다 =이 클래스를 다시 작성해야하고 항목 클래스 = Mage_Catalog_Model_Product_Api 기능을 기능을 오버라이드 (override) dir, GET 메소드로 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 
)); 

그리고 rewrited 클래스 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); 
    } 

10 그리고 그것은 googd tests.It 준은 하킴이 제안 유사한 솔루션입니다.