3
votes

The problem

I'm having trouble creating an order using the Magento SOAP api. I've got all the bare necessities in place (code snippet below) but everytime I try to create the order it fails with status code 1008 (See Magento Docs).

There is no fault message though, so I only know the order creation failed.

$cart_id                 = $magi->execute("cart.create");
$customerEntity          = $magi->execute("customer.info",5);
$customerEntity["mode"] = "customer";

$customerAddressEntity         = $magi->execute("customer_address.info",$customerEntity["default_billing"]);
$customerAddressEntity["mode"] = "billing";

$magi->execute("cart_customer.set", array($cart_id,$customerEntity));
$magi->execute("cart_customer.addresses", array($cart_id,array($customerAddressEntity)));

$productEntity = array("product_id" => 48,"qty" => 1);

$magi->execute("cart_product.add",array($cart_id,array($productEntity)));
$magi->execute("cart_payment.method",array($cart_id,array("method" => "banktransfer")));

$orderId = $magi->execute("cart.order", array($cart_id));

In the magento log the following messages are logged after this operation.


Undefined offset: 0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php

Undefined variable: websiteId/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php.
(this entry repeats itself 3 times after this one, each half a second apart).


I am at a loss here, it was in working condition a couple of weeks ago and not much has changed since then.

More information

The $magi variable holds an object that is an abstraction for using the Magento Soap api. It also catches and logs all errors, hence no try/catch blocks in this code.

  • Magento version: 1.7.0.0
  • Php version 5.4.6
  • Server OS: Ubuntu 11.10 (development server)
3

3 Answers

1
votes

I think your $productEntity is wrong.

$productEntity = array(
     array("product_id" => 48,"qty" => 1);
);

and it makes the cart is empty.

^^

1
votes

Undefined offset: 0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php

the error means there is an array that not have value for [ '0' ]

1
votes

The first error:

Undefined offset: 0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php

Is due to a bug in Api.php on this method:

protected function _preparePaymentData($data)
{
    if (!(is_array($data) && is_null($data[0]))) {
        return array();
    }

    return $data;
}

I was able to get rid of this problem replacing

if (!(is_array($data) && is_null($data[0])))

with

if (!(is_array($data) && !isset($data[0])))

During testing it works the same way and gets rid of the error.