Services resource for Product types (from Drupal Commerce)

Events happening in the community are now at Drupal community events on www.drupal.org.
ziodave's picture

Dears,

As I need to programmatically create Products in Drupal 7.x and Drupal Commerce, I'm writing a small file based on the skeleton of resources/node_resource.inc.

Right now I'm just able to create products and receive the ID of the created product (which I'm looking to use as a reference for the node creation).

Is this of some interest for this group, should I share this small file - full with errors :-))

Thanks,
David

Comments

Please do! Could go towards

dabblela's picture

Please do! Could go towards the beginnings of a nice Commerce Services module.

Product type patch

ziodave's picture

Ok, find the patch file here, http://drupal.org/node/1272836#comment-4960778 (the patch file has been generated using the instructions at http://drupal.org/project/services/git-instructions).

The patch file includes the following changes:
[1] a new file resources/product_resource.inc that contains the actual code to create a product (it only supports 'create' at the time being),
[2] a patch to services.resource_build.inc, to include and load the resources/product_resource.inc definitions,
[3] a patch to resources/file_resource.inc to fix as issue with the file-related code as explained here, http://drupal.org/node/1090278 - not directly related to the product feature.

Once the patch has been applied, the product.create operation must be enabled in the Web Services configuration (standard procedure, as it applies to other resources/operations).

The operation works like the node.create operation, required attributes are:
[1] type (product type, e.g. 'product'),
[2] sku (must be unique, if not a SQL ERROR will arise),
[3] title (string),
[4] uid (numeric),
[5] amount (numeric, multiply by 100, e.g. 1.99 = 199),
[6] currency_code (string, e.g. "USD").

The call will return a product ID (in the pid attribute) that can be used to reference the product from a content node (I'm using it programmatically as well).

Till now I created about 400 products + 400 content nodes (plus 1-2 files each content node), and is working fine.

Services Commerce Module

FranciscoLuz's picture

Hi,

I started out a module called Services Commerce (it is still a sandbox project) which adds Drupal Commerce resources (Customer Profile, Order, Payment Transaction and Product) to Services.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: