decimal quantity

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
My customers ordered quantity can be (1.5,0.5,1.25,10.5,........) they can only buy Int Quantity
how i can handle  it
i'm using NopCommerce 2.7
11 years ago
up
11 years ago
Mahgoop wrote:
My customers ordered quantity can be (1.5,0.5,1.25,10.5,........) they can only buy Int Quantity
how i can handle  it
i'm using NopCommerce 2.7


Here are two ideas of how you could address it.

Option 1

   Edit the source code.  I have not done what you are talking about here but I would guess that you would need to change the order quantity variable from "int" to "double".  You might also need to manually change that field from int to double in your database as well.  I am not sure how or where all you would need to edit the code to get it to work.  Also you would want to make sure this did not mess up any of the shipping plugins etc.  Also, you would have to come up with some way to keep someone from entering something like 1.1635.

Option 2

Use product variants on your products to define the quantity amount.  This is the option I used on my store.  Depending on the products you are selling this might work out just fine.  

Here is an example:

Imagine you are selling corn flour in different size bags.  You could set up the products as follows

variant 1  -  1 pound bag

variant 2  -  2.5 pound bag

variant 3  -  4.5 pound bag

variant 4  -  10.25 pound bag

Someone could order a quantity of one of variant 2 or they could order two.  Thus, getting two 2.5 pound bags of corn flour.  

What kind of products are you selling?  If you could break them up this way or by using product attributes it might be an easy solution to the problem.
11 years ago
I’ve done option 1 and it seems to handle it all fine. Variants were not an option for me as it didn’t take the values out of stock and it looks silly. The fact the Quantity and StockQuantity are not decimal is beyond me. Apparently this will not be offered in version 3 either, such a shame as the cart is brilliant apart from that.

Anyway I started by changing StockQuantity in the database to decimal and worked through the models and controllers until a compile was happy, then the big job “Quantity” and in the end the numbers just all added up.

Quantity and StockQuantity should have been either a Double, Float or Decimal from the very beginning. I see no reason why the new versions shouldn’t have that option.

Cheers,

Mike.
10 years ago
Bojangles1 wrote:

Quantity and StockQuantity should have been either a Double, Float or Decimal from the very beginning. I see no reason why the new versions shouldn’t have that option.


Totally agree with this, just upgrading a site to v.3 myself and am having to go through and make all the code changes to set all quantity properties to decimal again. There are loads of scenarios where quantity may need to be decimal so it should be that by default really.
7 years ago
I wonder why it is still and in in version 3.7.  Have you all had a change to document the change to decimal? The Database seems easy  enough:

DECLARE @Table as nvarchar(max) , @Column as nvarchar(max)
DECLARE tablecursor Cursor for
  SELECT  Table_Name, Column_Name
  FROM [DATABASE].INFORMATION_SCHEMA.COLUMNS
  Where COLUMN_NAME in ('Quantity','StockQuantity')
OPEN tablecursor
FETCH NEXT FROM tablecursor INTO @Table, @Column
WHILE @@FETCH_STATUS = 0
BEGIN
  EXEC('alter table ['+ @Table +'] alter column ['+ @Column +'] Decimal(18,3) not null')
  FETCH NEXT FROM tablecursor INTO @Table, @Column
END
CLOSE tablecursor
DEALLOCATE tablecursor

But when I go to change the code I end up chasing my tail.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.