Just filing this to say that I'm starting work on the order resource's retrieve and update methods (which are the ones I need right now).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

http://drupal.org/sandbox/drupalista-br/1283494 and https://github.com/sumitk/commerce_services both have some rough code for this so I'm starting with that and seeing what it does.

rszrama’s picture

Version: » 7.x-1.x-dev

Ok, but be warned, our Order code in Sumit's sandbox was based around this funky object to array conversion method we baked in for our clients at the time. ; )

I think we'll need to bake a better "combined resource" abstraction into this version. If you don't need the index, I'll be happy to add it on top of your code.

cvangysel’s picture

Status: Active » Needs review
FileSize
8.08 KB

Patch attached with support for index and retrieve operations.

joachim’s picture

I'm afraid this has completely dropped off my radar due to a variety of reasons -- sorry, I should have said here that I wasn't working on it any more. Glad to see someone else has picked this up! :)

Jerenus’s picture

This is my patch of order resource, includes index、retrieve、delete and update. It works fine for me.

Jerenus’s picture

Title: order resources: retrieve & update » Order resources: Index & Retrieve & Delete & Update & Create
FileSize
19.74 KB

This is my patch of order resource, includes index、retrieve、delete、update and create, hope can be checked.

Jerenus’s picture

FileSize
41.12 KB

This is an example of adding orders with postman.

T1ckL35’s picture

Hi, the patch in comment 6 is cool but it doesn't save updates to the product for things such as 'status' etc.
In resources/product.inc there is a line in the code like this:

$product->{$key} = $value;

which doesn't actually update the product.
I looked around for a product update function but not having only just started using drupal commerce and its related modules I couldn't find what was needed. I found the following method though and this seems to do the job.

$product->{$key} = $value;
commerce_product_save($product);

If there is another way that is better then please post up as I'd like to know :)

rszrama’s picture

Just pushed a patch that handles index, retrieve, update, and delete by abstracting the product resource callbacks into general API functions that the order resource can use. The new update code supports translation, field flattening, single vs. multi-value fields, etc. Will have to document it in a separate issue.

Leaving this open until create is done.

Commit: http://drupalcode.org/project/commerce_services.git/commitdiff/1e368dd

ben.bunk’s picture

Catching up here - Is there something wrong in the code for create in #6? Or another reason create wasn't included in the commit from #9?

pepsimxm’s picture

Hi everyone,

Just wondering if the orders index and retrieve are still in development, or if any of these patches have been included in the latest version of the module (30th Sept 2013)?

thanks

joachim’s picture

It's highly likely that these would all be provided OOTB by Services Entity module. See #1979988: Depend on Services Entity?.

torgosPizza’s picture

I'd like to know if Services Entity could handle a CREATE action on order (I thought you had to run CREATE against /cart?). Either way I'd love to know if CREATE is working yet, as it doesn't currently appear to be.

brighteridea’s picture

Issue summary: View changes

Every get an answer for this torgosPizza

sin’s picture

Here is my order create variant based on #6 and #9.

It creates order, line items and billing profile at once. Optionally allows to set order uid, status, override product price and set any billing profile fields.

Example request structure:

$data = array(
  'uid' => 1,
  'status' => 'pending',
  'products' => array(
    array('sku' => '000001', 'qty' => 2, 'price' => 123),
    array('sku' => '000002', 'qty' => 3, 'price' => 123),
  ),
  'commerce_customer_billing' => array(
    'commerce_customer_address' => array(
      'country' => 'RU',
      'name_line' => 'Синица Сергей Геннадьевич',
      'first_name' => '',
      'last_name' => '',
      'organisation_name' => '',
      'administrative_area' => '',
      'sub_administrative_area' => '',
      'locality' => '',
      'dependent_locality' => '',
      'postal_code' => '',
      'thoroughfare' => '',
      'premise' => '',
    ),
    'field_d7c_commerce_phone' => '2222222',
    'field_rucommerce_email' => 'myemail@example.ru',
  ),
);

cimo75’s picture

Seems like I am not able to get a proper json formatting for this ;

{
  'uid': 1,
  'status': 'cart',
  'products': [
    {
      'sku': '5449000000996-212',
      'qty': 2,
      'price': 1234
    }
  ]
}

throws a 400: : Invalid JSON error.
tx
Simone

sin’s picture

Hi, I've just tested minimal working example. The JSON was:

{"uid":1,"status":"pending","products":[{"sku":"14216577","qty":2,"price":123}]}

chevali’s picture

Hi, I am very new to this module, I added the patch from #15 thanks user sin.
I basically am working on a mobile app that is completely not connected to drupal yet i want to add orders from that app on my drupal site, after searching i stumbled upon this solution, my question is how do i use the patch to send data to the endpoint and add the order?

i was able to retrieve but now it's time to create it

torgosPizza’s picture

@chevali: That is functionality pretty much built into Services. Essentially you would take something like the JSON posted in the above comment to a Services endpoint that you have enabled for the CRUD methods of Commerce Orders. You'd need to include a session cookie and X-CSRF-Token as per usual.

Some good examples can be found on Tyler Frankenstein's site.

torgosPizza’s picture

Status: Needs review » Needs work

So far I like the patch in #15 a lot. It makes it much easier to create an order that we can then easily fulfill.

However the patch still Needs Work, IMO, because the order that's created does not honor the pricing set in the request (such as in the working example in #17). What happens is the line item itself has the correct price, but the total does not seem to be recalculated, so the order total itself is still the list price of the product as set in the product admin interface. (Unless I did something wrong or am missing a step?)

Aside from that I think this is a step in the right direction. The last thing we may need is the ability to send payment information along with the order, or in a separate API call. For a lot of our Rules, they are called when the event "An order is paid in full" gets fired. Generally speaking this event only gets triggered when a payment comes in for an order and a transaction for the full order balance is created. I can work to add this feature, unless it's already somewhere I have missed. (EDIT: #2054163: Payments and targeted actions for payments has a "rushed" patch that I will attempt to clean up.)

torgosPizza’s picture

[Removed comment because the issue was PEBKAC. Drupal Commerce Services reuse the site permissions system, so per the documentation I created a new API user (and an API User role) and assigned those CRUD permissions to them. That should take care of that.]

torgosPizza’s picture

One additional issue I have found is that custom fields on an order cannot be updated with the latest patch. I thought that a simple fix would be to add a call to commerce_services_set_field_values() but once I add that, I begin getting an error "Unknown field type 'products'" which is probably due to some of the non-entity-structure-following magic happening in the method proposed here for adding products to the order payload. So we may need to accommodate custom fields just in this code block for creating/updating orders, OR we implement something like #1979988: Depend on Services Entity? and standardize a lot of this.

sin’s picture

@torgosPizza

Custom billing profile fields are processed by commerce_services_update_entity() in my patch. I think we need to use commerce_services_update_entity() too to handle order custom fields.

No order total recalculation yet. How to do that properly?