I'm watching a demo of Commerce Stock 2.x right now, and even though the stock for items is in whole numbers (e.g. 0 or 5), the stock module shows them in various parts of the user interface and messages as decimals (e.g. 0.00 and 5.00). A simple round() on these will remove the hanging decimals, as it looks awkward to say the maximum of any item that can be purchased is "5.00".

Again, I'm just watching a demo so I don't know the precise file type or various places where the interface needs to be updated, but the good thing to do will be to determine the maximum number of decimal values available to the field and round to that. So, if the field has a precision of 2 (i.e. 2 maximum decimal places), you can round like so:

  // Outputs 2.
  print round(2.00, 2);

But it would still work for actual instances of decimal values:

  // Outputs 4.66.
  print round(4.66, 2);

Does this make sense?

(At the same time, and since it's an area you need to round I won't open a separate issue, the site messages displayed pertaining to out of stock items should be made complete sentences, such as "The maximum quantity of Product One that may be purchased is 1." with the period at the end. Maybe that can be fixed in the same patch?)

CommentFileSizeAuthor
#9 updated_default_rules.patch2.65 KBguy_schneerson

Comments

guy_schneerson’s picture

thanks @rszrama, good to know people are actually giving V-2 a go. I know i got to do more work on the module before its good for live use, one of those is the messages. The reason i left this to last is that the messages are configurable using rule actions so its easy to configure by users.
ill try and look at this soon

guy_schneerson’s picture

rockylhc’s picture

Where can I put the round() function in the module?

guy_schneerson’s picture

the msg is set by rules and unfortunately i don't think rules has is a round() action. ill look at this soon and maybe add a round action if needed.

rszrama’s picture

It may take a second token / definition in hook_entity_property_info() for the stock field (if this is indeed a field atm).

rockylhc’s picture

So what's the quick fix to show the round figure for the stock amount? Thanks in advance.

guy_schneerson’s picture

rzrama - stock is a field but the value used by the messages is calculated (stock - in cart quantity),
rockylhc - i don't think we i a quick fix (you may be able to use php code inside the rules to do the rounding).

I will try and look at this next (probably over the weekend).

guy_schneerson’s picture

Just added token support http://drupal.org/project/issues/commerce_stock
so you can now set a rule msg like:

The maximum Quantity for Drupal T-Shirt Black Small that can be ordered is 10.
You already ordered 4, so you should add 6 or less.

using the following text:

The maximum Quantity for [commerce-product:title] that can be ordered is [commerce-product:commerce-stock-int].

You already ordered [commerce-product:user-quantity-ordered], so you should add [commerce-product:commerce-stock-user] or less.

I need to update the rules default rules with messages that use those tokens. and i think those need fixing anyway so they work with the latest version of rules

will keep this issue open until i do

guy_schneerson’s picture

StatusFileSize
new2.65 KB

patch with updated rules includes:
+ installs correctly with latest version of rules
+ displaying stock quantities as an int using tokens

guy_schneerson’s picture

Status: Active » Reviewed & tested by the community

committed: http://drupalcode.org/project/commerce_stock.git/commit/e4fe35f

please test and let me know if this works for you.

guy_schneerson’s picture

Status: Reviewed & tested by the community » Needs review
guy_schneerson’s picture

Status: Needs review » Fixed

i think all is good so setting to fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.