2

I'm writing a module to change a user's shopping cart order ID based on a stored value from their profile, which cannot be edited from the users.

In the hook call to commerce_cart_order_id I tried the following code, but it doesn't change the order ID. Printing $orderidentifier with krumo() shows 1; if I change return $orderidentifier; with return 1; my cart changes just as I'd expect it to.

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

Can anyone tell me what I'm missing?

  • if return 1; works then it simply means $user_full->field_currentcartorder['und'][0]['value'] is empty (or there's other code involved that we can't see). I guess there's an outside change casting to an int would make a difference, but I think it's unlikely – Clive Oct 23 '14 at 14:07
  • if I print it with krumo() it says it's equal to 1 – mcgyvrfan121 Oct 23 '14 at 14:08
  • 2
    Then your argument is with PHP :) Variable assignment is understandably a cornerstone of the language - standard PHP can't do anything to change $orderidentifier between two sequential lines of code. Definitely not in the way your code describes anyway – Clive Oct 23 '14 at 14:09
  • when printed with krumo and getting 1 I would expect the next line returning the same variable to return 1 as well however it seems to be null on the return which of course makes no sense as I just had a value in the previous line and did nothing to change it – mcgyvrfan121 Oct 23 '14 at 14:16
  • also I tried to echoing and printing it and got no results however printing or echoing <br /> tags causes breaks to appear at the top of the page – mcgyvrfan121 Oct 23 '14 at 14:21
1

fixed it I had to add an $orderidentifier = intval($orderidentifier); to convert it to an integer so the hook I was calling could understand it

  • Indeed: if (!empty($order_id) && is_int($order_id)) { is in commerce_cart_order_id(). So it wants to enforce an integer. In a codebase and language that have severe type-safety problems. Interesting approach – Clive Oct 23 '14 at 14:42

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.