Closed (works as designed)
Project:
Commerce Stock
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
29 Apr 2013 at 17:29 UTC
Updated:
17 Jul 2013 at 16:43 UTC
When adding the stock quantity value as a field in views, accessing $row->commerce_stock is often not the correct stock value. I'm not sure if it's cached or munged somewhere in the code. The only way I could get around it was loading the whole product in a PHP field, then accessing product->commerce_stock->value().
Comments
Comment #1
aidanlis commentedCancel that, $product->commerce_stock->value() is incorrect too. I'm now directly accessing the data from the database ... I'm guessing it's cached somewhere?
Comment #2
guy_schneerson commentedI don't see how this is a stock issue as the commerce_stock field is just another decimal field.
can you enplane how you are "adding the stock quantity value" and posibly provide your view export.
Comment #3
guy_schneerson commentedif you are only using commerce_stock and Drupal entity api functions you shouldn't have caching issues unless you are writing directly to the database somewhere
Comment #4
aidanlis commentedThere were a few layers on top of commerce_stock_simple so I've disabled those and things are making more sense. $product->commerce_stock->value() is correct, however $row->commerce_stock as accessed in a PHP field in a Drupal view is incorrect.
Comment #5
guy_schneerson commented@aidanlis any news did you manage to solve your issue?
Comment #6
aidanlis commentedI think $row->commerce_stock is simply the entity id and not the resolved stock number, suggesting there's something wrong with the code that sets up the value.
As a quick fix, I used a PHP field and $product->commerce_stock->value() to display the stock level.
Comment #7
guy_schneerson commentedI am not sure how you go about adding the stock field but I use the stock field in views on a regular bases (most of our site have a stock tab on the product page) and have no issue.
Also the commerce_stock module doesn't do any custom handling of the stock filed its all standard Entity API stuff so I don't think this is an issue with the module.
If you managed to get around your problem then I suggest we close this issue (we can always reopen if this comes up again) otherwise you will need to provide more information on how you are setting up your view.
Comment #8
aidanlis commentedIt's not the stock field itself, it's that views doesn't expose the right information to the other handlers ... unfortunately I'm not that familiar with the entity API to tell you why.
Here's an image demonstrating the problem: http://share.aidanlister.com/OqaK
Here's the view:
Comment #9
guy_schneerson commentedSorry haven't got views_php installed if you provide a more generic view will try and have a look.
I am setting this as a support request as I am not convinced this is a bug with the stock module, If we find it is we can set the state back to bug report.
Comment #10
trentl commentedI stumbled across this as I've been using views php with commerce stock trying to create a simple stock flag when inventory drops below 5. For instance, "Only 5 left, act now!" I found that the $row variable for views php returns the product nid.
You're better off using the "$data->" variable. I would say this is an issue with views php rather than commerce stock.
as a follow-up see: https://drupal.org/node/1140896
Comment #11
trentl commentedI solved how to access commerce_stock value using views PHP. Below is code that will return the stock count.
Comment #12
guy_schneerson commentedThanks @geeklygroup fo sharing,
I am going to close this issue as I don't see how this has anything to do with th commerce_stock.
If anyone thinks otherwise please reopen and explain.