Welcome Guest, Not a member yet? Register   Sign In
Illegal offset type in isset or empty
#1

[eluser]nvanprooyen[/eluser]
I'm working on writing a API call to Magento using CodeIgniter and getting this illegal offset error. Here is an example from Magento's forum for the method I'm trying to use:

Code:
$proxy->call($sessionId, 'product_stock.update', array('Sku', array('qty'=>50, 'is_in_stock'=>1)));

And here is the CI equivalent to that:

Code:
function updateProductInventory($sku) {
        $apiSession = $this->apiConnect();
       // $this->xmlrpc->set_debug(TRUE);
        $this->xmlrpc->method('call');
        $request = array($apiSession, 'product_stock.update', array($sku , array('qty'=>20, 'is_in_stock'=>1)));
        var_dump($request);
        $this->xmlrpc->request($request);
         if (!$this->xmlrpc->send_request()) {
            echo $this->xmlrpc->display_error();
        } else {
            $response =  $data['response'] = $this->xmlrpc->display_response();
            var_dump($response);
        }

Not sure what the problem is, all the other methods I've written functions for so far work fine. The one difference with this one, is there are several arrays in $request. I'm guessing that's what is making it choke, but I'm not positive of that. Anyone have any ideas?
#2

[eluser]nvanprooyen[/eluser]
This is what the $request array var_dump looks like if it's helpful...

Code:
array
  0 => string '0443befb93cf3438a59b731825e600ab' (length=32)
  1 => string 'product_stock.update' (length=20)
  2 =>
    array
      0 => string 'SKU-00001' (length=9)
      1 =>
        array
          'qty' => int 20
          'is_in_stock' => int 1
#3

[eluser]louisl[/eluser]
I've not used magneto before but 'Illegal offset' usually means you're trying to access an array element that doesn't exist.

I think this

Code:
$proxy->call( $sessionId, 'product_stock.update', array('Sku', array('qty'=>50, 'is_in_stock'=>1)) );

Should translate to this

Code:
$this->xmlrpc->request( $apiSession, 'product_stock.update', array($sku, array('qty'=>50, 'is_in_stock'=>1)) );

Looks to me like you have a surrounding array on your $request variable that isn't needed.
#4

[eluser]nvanprooyen[/eluser]
Hi Louis,

Thanks for the response. Making that change is causing 2 new problems. First, CodeIgniter is having a problem w/ the foreach loop inside the XMLRPC library when it's formed that way. Here is that function:

Code:
function request($incoming)
    {
        if ( ! is_array($incoming))
        {
            // Send Error
        }

        $this->data = array();

        foreach ($incoming as $key => $value)
        {
            $this->data[$key] = $this->values_parsing($value);
        }
    }

Secondly, Magento is returning a session expired error. Guessing that's just because the session ID isn't being passed along correctly due to the error above. It seems like an array needs to be passed along to the request method for this to work correctly, but the multiple arrays are what is screwing w/ it.
#5

[eluser]nvanprooyen[/eluser]
Well, forming $request this way seemed to make the issue go away (basically dropped out the array around $sku):

Code:
$request = array($apiSession, 'product_stock.update', $sku , array('qty'=>20, 'is_in_stock'=>1));

The function isn't updating inventory like it should still, so I'm not sure I'm passing the request along to Magento the way it needs to be formed. I think the way I had it the first time is correct for Magento, but CI is having a problem w/ it for whatever reason. Maybe the request function in the XMLRPC library needs another foreach loop to deal w/ multiple arrays?
#6

[eluser]louisl[/eluser]
Just had a quick look at the docs, seems if you have mixed data you need to define it's type and the whole thing does apparently have to be an array.

From the docs (http://ellislab.com/codeigniter/user-gui...mlrpc.html)
"If you use data types other than strings, or if you have several different data types, you will place each parameter into its own array, with the data type in the second position:"

I think that means this:-

Code:
$request = array (
                   array($apiSession, 'string'),
                   array('product_stock.update', 'string'),
                   array($sku, 'int'),
                   array( array('qty'=>50, 'is_in_stock'=>1), 'array')
);

Sorry I don't have more time to look into this, hope this helps
#7

[eluser]nvanprooyen[/eluser]
Thank you. It gives me another place to look for answers. I tried doing it that way and now it's causing a bunch of problems in the functions where the CI library serializes the data. Will update here in case anyone else ever runs into a similar issue.
#8

[eluser]nvanprooyen[/eluser]
Does anyone know of a way to see the actual XML request, that the XML-RPC class constructs?




Theme © iAndrew 2016 - Forum software by © MyBB