1

I want to create custom products for every single one of my customers, and to add a thumbnail and custom order data from a JSAPP.

my scenario

Seen on #2 My JS application must get the unique id from the user. regardless if they are logged in or not (i dont know how which is the exact data or variable in the db i should send, and how do i send it?)

in #3 i must recieve custom information generated on the jsapp, i can send this as a Json , XML or URLstring from the jsapp to drupal commerce; im unsure how could i somehow, inject this information or update a variation of my product. or maybe there's a more easy way to do this.

Does anyone have some pointers on how to address this communication problem?

0
  1. Once your step one runs, you've actually created a unique order with a unique line item that references a product.

  2. The ID in #2 should probably just be your line-item id.

I would consider creating a rule on the event "After adding a product to cart" and a custom action (this is an answer where I provided the code to make a custom action) that takes a line item id (something the rule will easily have access to) and sends that to the three.js app.

  1. You really just want to add the custom data to the line item (which is unique to each line item on the order). In fact, using Customizable Products you can easily create a bundle specifically for adding as many fields as you would need to track your data (and display/hide it in views or display modes).

To do this, I would create a menu item that somehow recieves the full json object. Perhaps this blog article will help? Regardless, once you have your data, you will want to update the line item with your data and the best way to do this is with entity meta data wrappers if you are using fields to store the data.

<?php

$line_item_id = 1;
$line_item = commerce_line_item_load($line_item_id);
$line_item_wrapper = entity_metadata("commerce_line_item",$line_item);
dpm($line_item_wrapper->getPropertyInfo());

// ... mess with fields

$line_item_wrapper->save();

?>
  1. If you are using the fields on a line item to store your data, the cart will already be up-to-date because it simply references all the line items.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.