Jump to content
wfreebird

change order quantity to a decimal value

Recommended Posts

Hi guys,

I am working on a shop for selling fabrics where customers need to be able to order a quantity in a decimal value.
So the customer needs to be able to order for example 1,5 meters of a fabric.
Can anyone tell me where i can find the code to do so?
Change the database is no problem and i am good with php and html/css but i am new with prestashop and smarty.

I hope anyone can help me.

Thank you in advance.

Greetings Werner

Share this post


Link to post
Share on other sites

what if to use centimetres? Customers will order 150cm of fabric.

Share this post


Link to post
Share on other sites

Dear Otzy,

Unfortunately is changing it in to cm not an option because the prices in the shop have to be in metres.
But thank you for your suggestion.

Regards Werner

Share this post


Link to post
Share on other sites

Why don't you enter the prices in cm? You can just modify the tpl files to display the price in metres. You will have to modify product-list.tpl and product.tpl and anywhere else you display products.

Share this post


Link to post
Share on other sites

Hi Whitelighter,

Thank you for your reply.
This weak i tried your solution but i came upon an other problem. The shop does not sell only fabrics but also other stuff like studs and zippers witch need to be sell-ed in single pieces.
Also all the online shops that sell fabrics have the functionality to order a decimal value.

I hope there is somebody that can help me because i really need this.

Greetings Werner

Share this post


Link to post
Share on other sites

One more idea
add field `measured` int default 0 to table ps_product,
set it to 1 for fabrics and 0 for other goods,
in tpl files check this field (it will be automatically the property of object $product):

{if $product.measured>0}
 {assign var='productPrice' value=$product.price*100}
{else}
 {assign var='productPrice' value=$product.price}
{/if}



then change the price output from $product.price to $productPrice, for instance:

{displayWtPrice p=$productPrice}

Share this post


Link to post
Share on other sites

Hi guys!

I found the solution. I realized it on my website. It is very very simple.

First of all change INT to Decimal in database ps_product - quantity AND change intval to floatval near quantity or qty in the following files:

1. /order.php
2. /cart.php
3.classes/cart.php
4.classes/product.php
5.classes/order.php
6.themes/prestashop/product.tpl

  • Like 1

Share this post


Link to post
Share on other sites

Hi Fangor,

Thank you very much.
I will try this one and let you know if it works.

With kind regards,
Werner

Share this post


Link to post
Share on other sites

Hi Fangor,
it seems that your solution is about 1.3 only.
Have you any suggestions about 1.4
Thank you,
regards,
Panagiotis

Share this post


Link to post
Share on other sites

I have same problem...but I use 1.4.0. Anybody who solved the problem please share thу solution :-)

Share this post


Link to post
Share on other sites

Helo coloboque,

I have solved the problem in 1.4. I will give you the solution tomorrow because it is a lang story and i don't have the time now.
I wanted to post the solution much ealier but i didn't have the time for it.
So tomorrow i post it here.

With kind regards
Werner

Share this post


Link to post
Share on other sites

Hi,

So here is finally my answer, sorry promised Saturday but there was something between.

It's a lot of work in 1.4.
First I changed the database. I searched in all the tables with the fields quantity and changed the type to decimal(17,2).
The tables are:
- ps
- ps
- ps_discount
- ps_orders (total_products and total_products_wt)
- ps_order_detail (all the fields with quantity in the name)
- ps_order_return_detail
- ps_order_slip_detail
- ps_pack
- ps_product
- ps_product_attribute
- ps_product_sale
- ps_specific_price
- ps_stock_mvt

After this you go to your prestashop folder
Now you have to search for all the files where the quantity value is set.
Open the files one by one and search for "intval($row['cart_quantity'])" for example. Every line with the word "intval" before the word "quantity" or "qty".
Change the word "intval" to "floatval".
Then repeat all but now you search for the word "int" an change this to "float".
You need to do this for the files:
- prestashop/classes/Attribute.php
- prestashop/classes/Cart.php
- prestashop/classes/Customization.php
- prestashop/classes/Discount.php
- prestashop/classes/Order.php
- prestashop/classes/OrderDetail.php
- prestashop/classes/OrderHistory.php
- prestashop/classes/OrderReturn.php
- prestashop/classes/Product.php
- prestashop/classes/ProductSale.php
- prestashop/classes/QuantityDiscount.php
- prestashop/classes/StockMvt.php
- prestashop/controllers/CartController.php
- prestashop/controllers/OrderController.php
- prestashop/order.php
- prestashop/cart.php
- prestashop/themes/prestashop/product.tpl (or if you have a other theme prestashop/themes/themename/product.tpl

Please check yourself if the above files are all the files you need to change. Just open the other files as well and search.
I did it with dreamweaver and used "find and replace" type by Find "int" and by Replace "float".

I hope this was useful.
It's a lot of work but in the end it works for the users of your shop.
Good luck

With kind regards,
Werner

  • Like 1

Share this post


Link to post
Share on other sites

Hi. This is what I was looking for. Does it really works with the newest version of Prestashop?
Does it resolves the difference between a dot and a comma?

Share this post


Link to post
Share on other sites

Dear Stanik,

If you do it right it works with the new version of prestashop.
I did this with prestashop 1.4.0.17.
You can see the result at: www.lacouture.nl
It is a dutch site so all text is in dutch.

Unfurtunetly you can only use a dot and not a comma.

Hope this helps.

With kind regards,
Werner

Share this post


Link to post
Share on other sites

First, my thanks belongs to wfreebird for his instructions about edit Prestashop database and source codes - it very helped me.
I solved a problem with a dot and comma. You can add few lines to source code for an automatic changing comma for a dot.

1. edit javascript in path: \themes\prestashop\js\cart-summary.js

a) In function "function updateQty(val)" make some changes (there are only in begin of function):

function updateQty(val)
{
 val = changeToDot(val);
 var id = $(this.el).attr('name');
 var exp = new RegExp("^([0-9]*[.]?)?[0-9]+$");


 $('input[name='+ id +']').val(val);


 ////...next code was not changed...////

 if (exp.test(val) == true)
 {
   var hidden = $('input[name='+ id +'_hidden]').val();
   var input = $('input[name='+ id +']').val();
   var QtyToUp = parseFloat(input) - parseFloat(hidden);

   if (parseFloat(QtyToUp) > 0)
     upQuantity(id.replace('quantity_', ''),QtyToUp);
   else if(parseFloat(QtyToUp) < 0)
     downQuantity(id.replace('quantity_', ''),QtyToUp);
 }
 else
   $('input[name='+ id +']').val($('input[name='+ id +'_hidden]').val());
}




B) Add this function before function "function updateQty(val)":

function changeToDot(myFloatNumber){
for (var i=0;i        var currentChar = myFloatNumber.charAt(i);

       if (currentChar == ","){
           myFloatNumber = myFloatNumber.replace(/,/, '.');
           break;
       }
   }
   return myFloatNumber;
}




2. edit php file in path: \controllers\CartController.php

find and comment a row with:

$qty = (float)(abs(Tools::getValue('qty', 1)));


and place instead this row:

$qty = (float)(abs(str_replace(",",".",Tools::getValue('qty', 1))));




It´s all. I hope this helps you.

Share this post


Link to post
Share on other sites

Hi everybody,

 

 

Can anyone inform if this solution runs with recent versions like 1.45 or 1.47???

 

 

 

Regards,

 

 

Carlos

Share this post


Link to post
Share on other sites

I'm trying to do the same in the last version of prestashop and there is no way that works. I am configuring a fabric store, and the minimum quantity I need is 0,20 cm. I change all the .php archives and database but still not work.

 

Any advise?

Share this post


Link to post
Share on other sites

That`s the same I need, a store that sells fabrics and other products that must be sold in units. It seems that this solution doesn`t work with 1.45 and 1.47. We will try harder and if if we became to a solution I`ll let you know.

 

I believe that the only person that will solve this issue will be someone that knows very well Prestasop`s core in order to make the needed changes.

 

 

Any help????

 

 

Thanks!!!! :)

Share this post


Link to post
Share on other sites

Guys this is a basic and a must for one webshop CMS to have quantity in decimals

hope someone from presta will work on it

  • Like 1

Share this post


Link to post
Share on other sites

Hi guys,

 

Can we we ask a prestashop developer to make a module or to ad it in the next upgrade together?

I have coded a previous version to have the quantities in a decimal value but my problem now is that i can't upload to the new version and i want to update the outdated design of the site.

So if anyone know how to contact a developer i will be happy to contact him or her and ask.

 

With kind regards,

Werner Vrijvogel

Share this post


Link to post
Share on other sites

i've done all the canges (wfreebird gave) but...

 

When i Add product... let´s say with value 10.25 from product.php, with a minium_quantity of 10.25 (the same valu)

It seem likt that value is rounde (ceil...) to 10. So it´s not possible to add 10.25. But 11....

 

Maybe i forgot some changes. Plz Help....

Share this post


Link to post
Share on other sites

I've tried Wfreebird's solution, dident work out for me on 1.5.4.1. So currently working on a fix for newer versions.

Share this post


Link to post
Share on other sites

So the following attachment has my notes how I fixed a decimal product quantity order.

It says step by step what to do, It worked for me on Prestashop 1.5.4.1.

 

 

decimal_input_notes.txt

 

It might be done easier but these are my notes so why not share them

Goodluck

Edited by Bolinga (see edit history)

Share this post


Link to post
Share on other sites
So the following attachment has my notes how I fixed a decimal product quantity order. It says step by step what to do, It worked for me on Prestashop 1.5.4.1. decimal_input_notes.txt It might be done easier but these are my notes so why not share them Goodluck

 

Hi, I followed all the steps but there are some things I have not made correctly:

- Show units with decimals in the confirmation email that is sent to the client (order_conf)

- Subtract the stock in decimals

 

Did you get it to work?

 

PD: I'm working with 1.5.3.1

  • Like 1

Share this post


Link to post
Share on other sites

Hi, I followed all the steps but there are some things I have not made correctly:

- Show units with decimals in the confirmation email that is sent to the client (order_conf)

- Subtract the stock in decimals

 

Did you get it to work?

 

PD: I'm working with 1.5.3.1

 

Yeah, I've found out my notes arent complete yet. Some error's still in here. I am still working on it. Hope to post an update tomorrow. Sorry for not posting a complete solution.

  • Like 1

Share this post


Link to post
Share on other sites

Hello,

thanks for this solution , I have the same errors that diosimmy and cant put 0.55 or 0.etc on minium quantity, anyway im searching what we need to change for works correctly :D

 

Have an other fail:

 

/module/cashondelivery/validation

 

-> Cart cannot be loaded or an order has already been placed using this cart

 

:/ maybe i need change validations quantity files?

 

Thanks in advance

Edited by tabutnas (see edit history)

Share this post


Link to post
Share on other sites

Soo my own solution worked perfect for me locally. But no I've tried it on a host with a fresh prestashop install. And now my total price doesent caculate add a decimal quantity.

I've been searching for a fix for 2 days now.. Cant seem to get it working. I can fix the pdf + email bug but, not his one. So any help is welcome.

 

In this screenshot you see the wrong calculation.

post-566138-0-31976900-1369239295_thumb.png

 

I keep thinking it's a database that need's some adaption.... But cant find it!

Thank you in advance.

  • Like 1

Share this post


Link to post
Share on other sites

Yes, for me is the same.. but crash on /module/cashondelivery/validation have 500 internal server error at do this change. :(

Edit:

 

I managed to fix this bug, my problems now are;

  • Minimum quantity adapt to decimals
  • Some feilds (backend-front-end) don't show decimals

Edited by tabutnas (see edit history)

Share this post


Link to post
Share on other sites

well now works 100% fine to me, now i understand china philosophy XD

well this is my contribution;

i change some files... basically just search and change to float or modify functions 2 show correct quantities as decimal.

 

sql: equal than bolinga but add this changes

ps_product -> out_of_stock

ps_product_attribute -> minimal_quantity

just search and change tables what have "out_of_stock or minimal_quantity" and change to decimal 17,2 and "default minimum"

 

Some variables u need 2 search and change:

quantity

minimal_quantity

minimum_quantity

$qty

$nbTotalProducts

out_of_stock

 

 

that's all, thank bolinga :D

  • Like 2

Share this post


Link to post
Share on other sites

The ordering part works, customers can order a decimal quantity of products and the total price works fine! But in my backoffice & the invoice doesen't give a decimal quantity, although the price is correct. Help is needed..

Edited by Bolinga (see edit history)

Share this post


Link to post
Share on other sites

Bolinga, did you finally solve your problem?

 

Tabutnas, how exactly did you change the files? I don't understand exactly what "modify functions" is, or how do you make the search.

 

I don't have much idea of web programming, and I have tried to change my prestashop to decimals but it keeps displaying a wrong total price.

 

Do you have problems when adding new products to the catalog (error message: "Minimum quantity incorrect", I have to change it each time I edit a product, from 1.00 to 1).

 

Thank you!

Share this post


Link to post
Share on other sites

Bolinga, did you finally solve your problem?

 

Tabutnas, how exactly did you change the files? I don't understand exactly what "modify functions" is, or how do you make the search.

 

I don't have much idea of web programming, and I have tried to change my prestashop to decimals but it keeps displaying a wrong total price.

 

Do you have problems when adding new products to the catalog (error message: "Minimum quantity incorrect", I have to change it each time I edit a product, from 1.00 to 1).

 

Thank you!

My problem is fixed now :) had to change invoice and pdf controllers for admin and front.

 

If your total price is not calculated correctly, you missed a int at the controllers. Also make shure to change all the controllers for in the controllers/admin folder, since this is the place where you input the amount of products. Best thing might be open up all the controllers and search qty and change the int's to float and after that do the same for quant.

 

I'm sorry that I stopped making notes of all the changes that I made..

Goodluck though

Share this post


Link to post
Share on other sites

I've changed all these things...but in the cart summary the total isn't correct

 

nsfz.jpg

 

In the suggested changes I don't understand these:

 

-OwnName_cart -quantity

-quantity_per_user

-OwnName_cart_rule_product_group -quantity

-OwnName_customization -quantity

-OwnName_order_detail -quantity

-product_quantity_in_stock

-OwnName_order_return_detail -product_quantity

-OwnName_pack -quantity

-OwnName_product -minimal_quantity

-quantity

-OwnName_product_shop -minimal_quantity

-OwnName_stock_avaible -quantity

-OwnName_product_sale -quantity

-OwnName_cart_product -quantity

 

In the db there aren't table called "OwnName" (or with the ps site's name) :(

 

Thank you!!

Share this post


Link to post
Share on other sites

I've changed all these things...but in the cart summary the total isn't correct

 

nsfz.jpg

 

In the suggested changes I don't understand these:

 

-OwnName_cart -quantity

-quantity_per_user

-OwnName_cart_rule_product_group -quantity

-OwnName_customization -quantity

-OwnName_order_detail -quantity

-product_quantity_in_stock

-OwnName_order_return_detail -product_quantity

-OwnName_pack -quantity

-OwnName_product -minimal_quantity

-quantity

-OwnName_product_shop -minimal_quantity

-OwnName_stock_avaible -quantity

-OwnName_product_sale -quantity

-OwnName_cart_product -quantity

 

In the db there aren't table called "OwnName" (or with the ps site's name) :(

 

Thank you!!

 

At the installation of Prestashop you can chose a unique name for these tables. People refer them as "OwnName" since it's different for every installation.

Share this post


Link to post
Share on other sites

Yes, for me is the same.. but crash on /module/cashondelivery/validation have 500 internal server error at do this change. :(

Edit:

 

I managed to fix this bug, my problems now are;

  • Minimum quantity adapt to decimals
  • Some feilds (backend-front-end) don't show decimals

 

Hi Tabutnas, I am working on the same and have this problem now also. What did you do to correct this? Any more people that solved the complete decimal issue, having tips?

 

Also, the cart doesnt calculate correctly; it ignores the decimal figure, only uses the digit before the "." . I am using PS 1.5.4.1

Edited by AnitaR (see edit history)

Share this post


Link to post
Share on other sites

you can use to find column in database table with name quantity in it by this SQL statement

SELECT DISTINCT TABLE_NAME, column_name, column_type
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE  '%quantity%'
AND TABLE_SCHEMA =  'write your DB name here'
  • Like 2

Share this post


Link to post
Share on other sites

Hello,

 

I don't understand something

When you say "In the DATABASE change all these items to decimals(17,2)"; that means that we have to change "quantity" by "decimals (17,2)", or only "decimals", or only "(17,2)" ???

Thanks for your help

Share this post


Link to post
Share on other sites

it's necessary to change quantity field datatype from INT (integer) to float(17,2)

  • Like 1

Share this post


Link to post
Share on other sites