Answers.Body: <p>Removed the var_dump() from setting the variable as follows, and it works perfectly:</p>
  
  <pre><code>craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function($event)
  {
      $lineItem = $event-&gt;params['lineItem'];
      $globalPrices = craft()-&gt;globals-&gt;getSetByHandle('defaultPrices');
      $itemPrice = $globalPrices-&gt;fontStylePrice;
      $lineItem-&gt;price = $itemPrice;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:24:38.703Z
Answers.Text: Well yeah sorry I thought when you answered brad you meant that was just a typo above. Vardump returns a string... Must be a wierd se
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:25:52.377Z
Answers.Text: ..se post to recommend assigning var dump to a var?  Well there are uses for that but... In any case I was right...you were assigning a string to it...type error!
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:26:13.363Z
Answers.Text: Yeah, I missed the point of his question, I was thinking of the variable name :P
Answers.UserDisplayName: Adam Ladrach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:22:16.280Z
Answers.LastActivityDate: 2016-08-22T13:22:16.280Z
Answers.UserDisplayName: Adam Ladrach
Answers.Body: <p>Just a wild guess really, but it feels like this might be a type issue - is the price you're getting back from the global a float?  Or is it a string maybe?</p>
  
  <p><code>lineItem-&gt;price = floatval($itemPrice);</code></p>
  
  <p>...might be what you need?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T12:47:54.133Z
Answers.Text: Still getting a $0 value :/ I'm not sure what's going on. I did set the field type as a number.
Answers.UserDisplayName: Adam Ladrach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:12:35.253Z
Answers.Text: But what type of value does var_dump say it is?  Probably not it, but worth a check..
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:20:57.423Z
Answers.Text: Err in an event handler you probably can't. This is what phpstorm / xdebug are great for! But basically it had to be either you're not getting the value from the global ok, or there's some problem assigning to the price because of what you do get back.
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T13:22:38.920Z
Answers.Text: I removed the var_dump from where I set the variable and it works! Probably a silly thing to do, but I just did what the SE post said :P
Answers.UserDisplayName: Adam Ladrach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-22T00:55:55.317Z
Answers.LastActivityDate: 2016-08-22T00:55:55.317Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I'm trying to set the price of the item being added to the cart by a global variable, which is a number field. Here's what I have:</p>
  
  <pre><code>craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function($event)
  {
      $lineItem = $event-&gt;params['lineItem'];
      $globalPrices = craft()-&gt;globals-&gt;getSetByHandle('defaultPrices');
      $itemPrice = var_dump($globalPrices-&gt;fontStylePrice);
      $lineItem-&gt;price = $itemPrice;
  </code></pre>
  
  <p>This just results in a $0 price being set, and not the value from the Global Variable. But again, <code>$lineItem-&gt;price = 25</code> works fine. Any suggestions?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T00:42:36.663Z
Comments.Text: Are you testing with `var_dump($globalPrices->fontStylePrice);` in place or is that just a typo in your code example?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T12:43:19.803Z
Comments.Text: Yeah, I swapped some of the tags out for placeholders, just didn't get them all apparently.
Comments.UserDisplayName: Adam Ladrach
Tags: <plugin-craftcommerce>
Title: Using Global Variable as Price for Variant
ThreadText: # Using Global Variable as Price for Variant
  
  (Asked by: username_0 on 2016-08-21)
  
  I'm trying to set the price of the item being added to the cart by a global variable, which is a number field. Here's what I have:
  
  ```
  craft()->on('commerce_lineItems.onPopulateLineItem', function($event)
  {
      $lineItem = $event->params['lineItem'];
      $globalPrices = craft()->globals->getSetByHandle('defaultPrices');
      $itemPrice = var_dump($globalPrices->fontStylePrice);
      $lineItem->price = $itemPrice;
  
  ```
  
  This just results in a $0 price being set, and not the value from the Global Variable. But again, `$lineItem->price = 25` works fine. Any suggestions?
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: Are you testing with `var_dump($globalPrices->fontStylePrice);` in place or is that just a typo in your code example?  
  > **username_0**: Yeah, I swapped some of the tags out for placeholders, just didn't get them all apparently.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-08-22. Score: 1
  
  Removed the var\_dump() from setting the variable as follows, and it works perfectly:
  
  ```
  craft()->on('commerce_lineItems.onPopulateLineItem', function($event)
  {
      $lineItem = $event->params['lineItem'];
      $globalPrices = craft()->globals->getSetByHandle('defaultPrices');
      $itemPrice = $globalPrices->fontStylePrice;
      $lineItem->price = $itemPrice;
  
  ```
  
  > **Comments:**
  > **username_2**: Well yeah sorry I thought when you answered username_1 you meant that was just a typo above. Vardump returns a string... Must be a wierd se  
  > **username_2**: ..se post to recommend assigning var dump to a var?  Well there are uses for that but... In any case I was right...you were assigning a string to it...type error!  
  > **username_0**: Yeah, I missed the point of his question, I was thinking of the variable name :P  
  
  ---
  
  ### Answer by username_2 on 2016-08-22. Score: 0
  
  Just a wild guess really, but it feels like this might be a type issue - is the price you're getting back from the global a float? Or is it a string maybe?
  
  `lineItem->price = floatval($itemPrice);`
  
  ...might be what you need?
  
  > **Comments:**
  > **username_0**: Still getting a $0 value :/ I'm not sure what's going on. I did set the field type as a number.  
  > **username_2**: But what type of value does var_dump say it is?  Probably not it, but worth a check..  
  > **username_2**: Err in an event handler you probably can't. This is what phpstorm / xdebug are great for! But basically it had to be either you're not getting the value from the global ok, or there's some problem assigning to the price because of what you do get back.  
  > **username_0**: I removed the var_dump from where I set the variable and it works! Probably a silly thing to do, but I just did what the SE post said :P  
  
  ---
  
  