Udaya Sri
Udaya Sri

Reputation: 2452

retrive product list with post data with magento soap

I'm having an issue with retrieving the product list from magento . I'm sending a a value using ajax , then I use that value as a filter value for magento soap call, but it 's not working, I couldn't get the product details .

but when I hard coded the value to variable in the same webservice.php file it works ..

What's the fault I have done ...

here is my ajax.php & webservice.php files

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"}';

Upvotes: 0

Views: 710

Answers (2)

liyakat
liyakat

Reputation: 11853

you are sending data in json format so you should have to decode it first like

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

or you can use simple html type to post your data

Also debug post value when you call ajax function in controller.

hope this will help you.

Upvotes: 1

gvm
gvm

Reputation: 1128

Can you debug the response using,

$client->__getLastResponse()

Enable trace, sample Code

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

Upvotes: 2

Related Questions