Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order creation via API fails in Magento

Tags:

api

magento

I am getting a rather strange error when trying to create a new order via the Magento API V1.0. Here is the basic workflow of my code:

  1. Create shopping cart using the cart.create method.
  2. Set a customer as 'guest' using the cart_customer.set method.
  3. Add products to cart using the cart_product.add method.
  4. Create the order using the cart.order method.

At this point, the cart.order method throws a SoapFault exception with the message "Call to a member function setFinalPrice() on a non-object". The same exception is thrown if I replace the cart.order method with other methods such as cart.info or cart_product.list.

Since the exception's message does not seem very descriptive, I was wondering if anybody else has ever bumped into this.

Thanks.

UPDATE: The problem is due to the fact that I am adding products to the cart using their SKUs when calling the cart_product.add method. The exception is no longer thrown when using product IDs instead of SKUs (I suspect this could be a bug). However, at this point the cart.order method returns false, so the order is still not created.

like image 938
Epicurus Avatar asked Oct 13 '11 15:10

Epicurus


1 Answers

Before you do cart.order method, you must assign the payment and shipping address to your cart.

it's standard procedure to create an order in magento.

the steps should be like this :

  • Create shopping cart using the cart.create method.
  • Set a customer as 'guest' using the cart_customer.set method.
  • Add products to cart using the cart_product.add method.

try to call cart_shipping.method and cart_payment.method before you call cart.order

  • Create the order using the cart.order method.
like image 55
Josua Marcel C Avatar answered Nov 09 '22 05:11

Josua Marcel C