gplsek / fitmoostore

fitmostore
GNU General Public License v2.0
0 stars 0 forks source link

Create Product via API #2

Closed gplsek closed 10 years ago

gplsek commented 10 years ago

Create product via API:

Receive json object from API call fitmoo->drupal

Product = Product Display (regular drupal node) Product Item (commerce product entity)

Product Display:

SudoCode

Create Node Object $node->type = 'tops' (shirts, jackets, and etc) $node->uid = logged in user UID

then add other fields

then add product items.

create product object via commerce: $product_type = 'shirt'; $product = commerce_product_new($product_type); $product->status = status; $product->uid = 'uid'; $productt->sku = 'sku'; $product->title = 'title'; $product->created = time(); $product->size = ...

then product save via commerce hook

get the ID, create the other 4 variations

then save ids on:

$node->product_items['und'] = IDs array.

then node_save($node)

let me know if this makes sense.

I will add some sample links.

gplsek commented 10 years ago

Created couple sample functions in the fitmoo_product module sites/all/modules/custom/fitmoo_product/fitmoo_product.module

you can see what the product and product_item obeject looks like by trying something like for event product: http://fitmoo.plsekwerks.com/fitmoo/product_node/2 then its product_item: http://fitmoo.plsekwerks.com/fitmoo/product/3 you can see the product here: http://fitmoo.plsekwerks.com/node/2

For more complicated products: Product that is a collection of items you can see http://fitmoo.plsekwerks.com/fitmoo/product_node/3 you can now see that it has multiple product_item references

the product is here: http://fitmoo.plsekwerks.com/node/3 if you change the Size in the drop down it loads different product_item there you can tell for example by selecting S vs XL the price changes as well.

you can see the product_item object here: http://fitmoo.plsekwerks.com/fitmoo/product/4 http://fitmoo.plsekwerks.com/fitmoo/product/5 and so on

there are functions in there that will help you create the products via the api.

We will need to set up the API to accept the json soehting like this:

product

jg77merten commented 10 years ago

POST http://fitmoostore.loc/tapi/user/logout X-CSRF-Token: g23gMtjDtBzptg4YNXFmnYL8u8Ada425a44141 -- response -- <?xml version="1.0" encoding="utf-8"?>

<result>1</result>

POST http://fitmoostore.loc/tapi/user/login Content-Type: application/x-www-form-urlencoded username=test1&password=test1 -- response -- Set-Cookie: SESSb22f1e1c07a26da425a441410bf4eb41=fMSznhcIJcpEslyhDxDuoxmwegqbBaerecjyIUbhhT4; expires=Thu, 13-Mar-2014 19:38:06 GMT; path=/; domain=.fitmoostore.loc; HttpOnly <?xml version="1.0" encoding="utf-8"?>

<result><sessid>fMSznhcIJcpEslyhDxDuoxmwegqbBaerecjyIUbhhT4</sessid><session_name>SESSb22f1e1c07a26da425a441410bf4eb41</session_name><user><uid>13</uid><name>test1</name><theme></theme><signature></signature><signature_format>filtered_html</signature_format><created>1392739073</created><access>0</access><login>1392739484</login><status>1</status><timezone>America/Los_Angeles</timezone><language></language><picture/><data></data><roles is_array="true"><item>authenticated user</item></roles><rdf_mapping><rdftype is_array="true"><item>sioc:UserAccount</item></rdftype><name><predicates is_array="true"><item>foaf:name</item></predicates></name><homepage><predicates is_array="true"><item>foaf:page</item></predicates><type>rel</type></homepage></rdf_mapping></user></result>

GET http://fitmoostore.loc/services/session/token Cookie: SESSb22f1e1c07a26da425a441410bf4eb41=fMSznhcIJcpEslyhDxDuoxmwegqbBaerecjyIUbhhT4 -- response --

oUI5DA7jYSUSCWFvRID85Gp0k0Jk9BHFlxCC0fpH_HI

GET http://fitmoostore.loc/tapi/user/13 Cookie: SESSb22f1e1c07a26da425a441410bf4eb41=fMSznhcIJcpEslyhDxDuoxmwegqbBaerecjyIUbhhT4 X-CSRF-Token: oUI5DA7jYSUSCWFvRID85Gp0k0Jk9BHFlxCC0fpH_HI -- response -- <?xml version="1.0" encoding="utf-8"?>

<result><uid>13</uid><name>test1</name><theme></theme><signature></signature><signature_format>filtered_html</signature_format><created>1392739073</created><access>1392739484</access><login>1392739484</login><status>1</status><timezone>America/Los_Angeles</timezone><language></language><picture/><data></data><roles is_array="true"><item>authenticated user</item></roles><rdf_mapping><rdftype is_array="true"><item>sioc:UserAccount</item></rdftype><name><predicates is_array="true"><item>foaf:name</item></predicates></name><homepage><predicates is_array="true"><item>foaf:page</item></predicates><type>rel</type></homepage></rdf_mapping></result>

POST http://fitmoostore.loc/tapi/cart X-CSRF-Token: oUI5DA7jYSUSCWFvRID85Gp0k0Jk9BHFlxCC0fpH_HI Cookie: SESSb22f1e1c07a26da425a441410bf4eb41=fMSznhcIJcpEslyhDxDuoxmwegqbBaerecjyIUbhhT4 Content-Type: application/x-www-form-urlencoded -- response -- <?xml version="1.0" encoding="utf-8"?>

<result><uid>13</uid><status>cart</status><type>commerce_order</type><order_id>2</order_id><order_number>2</order_number><revision_id>2</revision_id><mail>test1@mail.loc</mail><data/><created>1392741521</created><changed>1392741521</changed><hostname>127.0.0.1</hostname><log>Created as a shopping cart order.</log><revision_timestamp>1392741521</revision_timestamp><revision_hostname>127.0.0.1</revision_hostname><revision_uid>13</revision_uid><commerce_order_total><amount>0</amount><currency_code>USD</currency_code><data><components is_array="true"><item><name>base_price</name><price><amount>0</amount><currency_code>USD</currency_code><data/></price><included>1</included></item></components></data></commerce_order_total><commerce_order_total_formatted>$0.00</commerce_order_total_formatted><commerce_line_items/><commerce_customer_billing/><commerce_customer_shipping/><commerce_discounts/></result>

jg77merten commented 10 years ago

All done and works :)

2014-02-18 7:38 GMT+03:00 George Plsek notifications@github.com:

Created couple sample functions in the fitmoo_product module sites/all/modules/custom/fitmoo_product/fitmoo_product.module

you can see what the product and product_item obeject looks like by trying something like for event product: http://fitmoo.plsekwerks.com/fitmoo/product_node/2 then its product_item: http://fitmoo.plsekwerks.com/fitmoo/product/3 you can see the product here: http://fitmoo.plsekwerks.com/node/2

For more complicated products: Product that is a collection of items you can see http://fitmoo.plsekwerks.com/fitmoo/product_node/3 you can now see that it has multiple product_item references

the product is here: http://fitmoo.plsekwerks.com/node/3 if you change the Size in the drop down it loads different product_item there you can tell for example by selecting S vs XL the price changes as well.

you can see the product_item object here: http://fitmoo.plsekwerks.com/fitmoo/product/4 http://fitmoo.plsekwerks.com/fitmoo/product/5 and so on

there are functions in there that will help you create the products via the api.

We will need to set up the API to accept the json soehting like this:

product

  • product description
  • some field
  • product items
    • product item
    • title
    • price
    • quantity/stock
    • variation 1 (can be size)
    • variation 2 ....

Reply to this email directly or view it on GitHubhttps://github.com/gplsek/fitmoostore/issues/2#issuecomment-35352014 .

jg77merten commented 10 years ago

Now I upload, configurate and making API-calls manual.

2014-02-20 16:35 GMT+03:00 Max Klimchuk sabre@tut.by:

All done and works :)

2014-02-18 7:38 GMT+03:00 George Plsek notifications@github.com:

Created couple sample functions in the fitmoo_product module

sites/all/modules/custom/fitmoo_product/fitmoo_product.module

you can see what the product and product_item obeject looks like by trying something like for event product: http://fitmoo.plsekwerks.com/fitmoo/product_node/2 then its product_item: http://fitmoo.plsekwerks.com/fitmoo/product/3 you can see the product here: http://fitmoo.plsekwerks.com/node/2

For more complicated products: Product that is a collection of items you can see http://fitmoo.plsekwerks.com/fitmoo/product_node/3 you can now see that it has multiple product_item references

the product is here: http://fitmoo.plsekwerks.com/node/3 if you change the Size in the drop down it loads different product_item there you can tell for example by selecting S vs XL the price changes as well.

you can see the product_item object here: http://fitmoo.plsekwerks.com/fitmoo/product/4 http://fitmoo.plsekwerks.com/fitmoo/product/5 and so on

there are functions in there that will help you create the products via the api.

We will need to set up the API to accept the json soehting like this:

product

  • product description
  • some field
  • product items
    • product item
    • title
    • price
    • quantity/stock
    • variation 1 (can be size)
    • variation 2 ....

Reply to this email directly or view it on GitHubhttps://github.com/gplsek/fitmoostore/issues/2#issuecomment-35352014 .