1

As I understand it commerce gets the users highest numbered order that is not yet completed (on the customers end) and uses that when a user adds an item to their cart or views their cart however I created a module that will allow a single user to create many carts (lets call these quotes) for their customers and i need a way for them to be able to go back and edit a previous quote or complete checkout on a previous quote right now i have a list of quotes in a view (any order that has not passed the checkout review page) and I want to add a column containing a link or button that will allow them to load that order number as the current cart I tried using a custom module function with a call to

commerce_cart_order_load(1);

(from a menu link) which is a previous order on my account however that appears to do nothing

Can anyone explain what I'm doing wrong/ what I need to do to make this work?

I would be perfectly happy doing this with views php if there is a function to set the users cart order that I'm missing, or by storing an OrderID hidden on the users profile

Thank You

0

After much playing and breaking I wrote some code in a custom module to save the current order to load to the users profile in a un-editable field

    function create_new_quote_menu() {
  $items = array();
  $items['create_new_quote'] = array(
    'title' => 'Start New Quote',
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'custom_callback',
    'access arguments' => array('access content'),
  );
  $items['quotes/%/Load'] = array(   // assuming you want to make this dynamic
    'title' => 'Quotes',
    'page callback' => 'create_new_quote_LoadQuote',
    'page arguments' => array(1),   // references %, i'm assuming this is all dynamic
    'access arguments' => array('access content'),  // don't do this, whatever permission you want goes here
    'type' => MENU_CALLBACK
  );
  return $items;
}

function custom_callback () {
  global $user;
  $currentOID;
  $user_full = user_load($user->uid);
  $currentOID = commerce_cart_order_new($user->uid);

  $updateUserParams = (array) $user_full;
    $updateUserParams['field_currentcartorder'][LANGUAGE_NONE][0]['value'] = intval($currentOID->order_id);

    unset($fullUser->pass);
    unset($updateUserParams['pass']);

    user_save($user_full, $updateUserParams);
drupal_set_message(t('You have Created a New Quote #'). $currentOID->order_id,'status');
drupal_goto('moulding');
}

function create_new_quote_LoadQuote($quote_to_load) {
  global $user;
  $user_full = user_load($user->uid);

  $updateUserParams = (array) $user_full;
    $updateUserParams['field_currentcartorder'][LANGUAGE_NONE][0]['value'] = intval($quote_to_load);

    unset($fullUser->pass);
    unset($updateUserParams['pass']);

user_save($user_full, $updateUserParams);
drupal_set_message(t('You Loaded Quote #'). $quote_to_load,'status');
drupal_goto('quotes');
}


function create_new_quote_commerce_cart_order_id($uid) {
  global $user;
  $user_full = user_load($user->uid);
  $orderidentifier = $user_full->field_currentcartorder['und'][0]['value'];
  $orderidentifier = intval($orderidentifier);
  return $orderidentifier;
}

excuse my uncommented code and poor module name but I got it working this this code set so I can now create and change orders from my view by pasing Quotes/[orderid]/Load via a link

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.