0

magento から製品リストを取得する際に問題が発生しています。ajax を使用して aa 値を送信し、その値を magento soap 呼び出しのフィルター値として使用していますが、機能していません。製品の詳細を取得できませんでした。

しかし、同じ webservice.php ファイルで値を変数にハードコーディングすると、動作します..

私がしてしまった過ちは何ですか...

ここに私の ajax.php & webservice.php ファイルがあります

ajax.php

// ajax script  
<script>
//item_code is text box , user enter some value to it. 
$('#item_code').live("keyup",function(){

    item_code = $('#item_code').val();

    $.ajax({
        url:"webservice.php",
        type:"POST",
        dataType: "json",
        data : '&item_code= ' + item_code,
        cache:false,
        success: 
        function (data) {

            if (data.successfully_inserted == "passed")
            {

                alert('ok');

            }
            else
            {

                alert('error');
            }
        }
      });
 });

</script>



webservice.php

<?php

//$item_code = 'abc' ;   // This works , I can get the correct result.
$item_code = $_POST['item_code'];  // when I assign $item_code to post data value it does not work. I echo it, data was posted correctly. 

$client = new SoapClient('http://myhost/index.php/api/soap/?wsdl');
$session = $client->login('test', 'test1234');


$filters = array(
 'item_code' => array('where'=>$item_code)
);

/* $filters = array(
 'item_code' => array('like'=>''.$item_code.'%')
); */


$products = $client->call($session, 'catalog_product.list', array($filters) );

print_r($products);

echo '{"successfully_inserted": "passed"}';
4

2 に答える 2

2

を使用して応答をデバッグできますか?

$client->__getLastResponse()

トレースを有効にする、サンプル コード

$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "応答:\n" . $client->__getLastResponse() . "\n";

于 2013-09-17T10:19:55.077 に答える
1

データをjson形式で送信しているため、最初にデコードする必要があります

$item_arr = json_decode($this->_getParam('item_code')); 

または、単純なhtmlタイプを使用してデータを投稿できます

また、コントローラーで ajax 関数を呼び出すときにポスト値をデバッグします。

これがあなたを助けることを願っています。

于 2013-09-17T10:29:08.140 に答える