Advertisement
Guest User

Untitled

a guest
Nov 19th, 2012
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. // For debugging, this function is called by hook_menu()
  2. function mymodule_test($product_id)
  3. {
  4.     global $user;
  5.     $user = user_load($user->uid);
  6.  
  7.     $order = commerce_cart_order_load($user->uid);
  8.     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  9.    
  10.     $product = commerce_product_load($product_id);
  11.    
  12.     $line_item = commerce_product_line_item_new(
  13.         $product,
  14.         1,
  15.         0,
  16.         array(
  17.         ),
  18.         'cover'
  19.     );
  20.    
  21.     $line_item_wrapper = entity_metadata_wrapper("commerce_line_item", $line_item);
  22.    
  23.     $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
  24.         $line_item_wrapper->commerce_unit_price->value(),
  25.         'base_price',
  26.         array(
  27.                 'amount' => 1234,
  28.                 'currency_code' => 'EUR',
  29.                 'data' => array(),
  30.         ),
  31.         TRUE
  32.     );
  33.    
  34.     $insert_line_item = commerce_cart_product_add($user->uid, $line_item_wrapper->value(), FALSE);
  35.    
  36.     return 'done';
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement