Jump to content



Photo

Prices Are Not Getting Correct - Cart


  • Please log in to reply
17 replies to this topic

#1 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 4 April 2017 - 4:10 AM

If my price of the product is less than thousand then the prices are correct after update or any calculation.

 

For example - if I am increasing or decreasing the quantity.

 

But if the price of the product is above thousand than it is giving the wrong answers.

 

And in practical scenario the cost or price of the product can be any digit.

 

thanks in advance.

 


  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 5 April 2017 - 11:36 AM

I think you'll need to change the column definition for the price. What is it currently?


  • 0

#3 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 8 April 2017 - 7:20 AM

The column definition for the price currently is INT UNSIGNED NOT NULL which is 4,294,967,295 and my current prices are below this numeral.

 

For example: (1) When I increased the price of the Kona::Half Pound - decaf - ground from $5.00 to $50.00 (added one 0). It is showing the correct result. $50.00 x 21 (qty) = $1,050.00.

 

(2) When I increased the price of Kona::1 lb. - caf - whole from $7.50 to $750.00. It is giving the correct answer. $750.00 x 2 = $1,500.00. BUT

 

(3) When I increased the price of Kona::1 lb. - caf - ground from $8.00 to $8,000.00. It is not giving the accurate answer.

 

(4) When the price of Kona::1 lb. - decaf - ground is increased from $8.50 to 8,500.00 and the quantity is increased from 1 to 2. It is showing $16.00 instead of $17,000.00.


  • 0

#4 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 8 April 2017 - 7:23 AM


  • 0

#5 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 8 April 2017 - 8:10 AM

Below is the screen shot of the cart

 


  • 0

#6 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 8 April 2017 - 8:12 AM

Sorry I tried to paste the screen shot but it is not showing anything.


  • 0

#7 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 10 April 2017 - 10:05 PM

Okay, um...nothing obvious coming to mind. Could you confirm that you're seeing this on the page for viewing the cart's contents (i.e., cart.php)? And are you using stored procedures? 


  • 0

#8 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 16 April 2017 - 5:22 AM

Yes, this page is localhost/cart.php and I am using stored procedures.

 

 

I have not changed anything from downloaded codes other than prices.


  • 0

#9 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 19 April 2017 - 4:08 PM

Hmmm...okay. I still don't have an obvious answer here. What I would do to debug this is first run the stored procedure directly to confirm whether the problem is on the database side or the PHP -> HTML side. If the stored procedure is also turning out wrong results, I'd run a subset of the stored procedure's query to see if that's working. 

 

Sorry I don't have an obvious "this is the problem" answer for you but I haven't seen this before and don't know of the clear problem.


  • 0

#10 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 20 May 2017 - 1:27 AM

And also with the above particulars when I am moving these items to wish list it is showing errors.


  • 0

#11 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 30 May 2017 - 4:44 PM

I was wondering where things stood! Thanks for the message. What were the results when you did what I recommended above?


  • 0

#12 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 31 May 2017 - 3:02 PM

I have run the stored procedure.

 

Call select_products('coffee', 3);

 

 
 
 
 
 
 
 
description image sku name stock price sale_price   A real treat! Kona coffee, fresh from the lush mou... kona.jpg C4 1 lb. - caf - ground - $8,000.00 50 800000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C6 1 lb. - caf - whole - $750.00 50 75000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C5 1 lb. - decaf - ground - $8,500.00 20 850000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C7 1 lb. - decaf - whole - $8.00 20 800 700 A real treat! Kona coffee, fresh from the lush mou... kona.jpg C8 2 lbs. - caf - whole - $15.00 30 1500 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C9 2 lbs. - decaf - whole - $15.50 15 1550 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C1 2 oz. Sample - caf - ground - $2.00 20 200 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C10 5 lbs. - caf - whole - $32.50 5 3250 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C2 Half Pound - caf - ground - $4.50 30 450 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C3 Half Pound - decaf - ground - $50.00 200 5000 NULL

 

It is showing the correct prices.

 

But I don't know how to debug this problem correctly. It would be highly appreciated if you solve it.

 

 
 
 
 
 
 
 
description image sku
 
 
 
 
 
 
 
description image sku name stock price sale_price   A real treat! Kona coffee, fresh from the lush mou... kona.jpg C4 1 lb. - caf - ground - $8,000.00 50 800000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C6 1 lb. - caf - whole - $750.00 50 75000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C5 1 lb. - decaf - ground - $8,500.00 20 850000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C7 1 lb. - decaf - whole - $8.00 20 800 700 A real treat! Kona coffee, fresh from the lush mou... kona.jpg C8 2 lbs. - caf - whole - $15.00 30 1500 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C9 2 lbs. - decaf - whole - $15.50 15 1550 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C1 2 oz. Sample - caf - ground - $2.00 20 200 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C10 5 lbs. - caf - whole - $32.50 5 3250 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C2 Half Pound - caf - ground - $4.50 30 450 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C3 Half Pound - decaf - ground - $50.00 200 5000 NULL name stock price salghghgghhge_price   A real treat! Kona coffee, fresh from the lush mou... kona.jpg C4 1 lb. - caf - ground - $8,000.00 50 800000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C6 1 lb. - caf - whole - $750.00 50 75000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C5 1 lb. - decaf - ground - $8,500.00 20 850000 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C7 1 lb. - decaf - whole - $8.00 20 800 700 A real treat! Kona coffee, fresh from the lush mou... kona.jpg C8 2 lbs. - caf - whole - $15.00 30 1500 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C9 2 lbs. - decaf - whole - $15.50 15 1550 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C1 2 oz. Sample - caf - ground - $2.00 20 200 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C10 5 lbs. - caf - whole - $32.50 5 3250 NULL A real treat! Kona coffee, fresh from the lush mou... kona.jpg C2 Half Pound - caf - ground - $4.50 30 450 NULL A real treat! Kona coffee, fresh from the             
  • 0

#13 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 1 June 2017 - 9:44 AM

As I said before, I don't have an obvious "this is the problem" answer for you as I haven't seen this before and don't know of the clear problem. So unfortunately I can't solve this on my own as I've never seen it before and can't replicate it. However, we should be able to work together to solve it!

 

So it's very useful to know that the stored procedure is pulling out the right prices. But that's the procedure for the products and you said earlier the issue is on the carts page. You should run the get_shopping_cart_contents procedure to see if it confirms the right prices.

 

Also, double-check to make sure you don't have applicable sale prices which would be overwriting the values in the products tables.


  • 0

#14 daddytiger

daddytiger

    Newbie

  • Members
  • Pip
  • 13 posts

Posted 7 June 2017 - 2:46 AM

Solution in earlier post I believe: http://larryullman.c...iger#entry20448

 

highlights of my 'workaround':

 

Hi all,
 
I had the same problem. It seems 2 problems:
 
Fisrt, qty can get truncated to 127 or 255 in the database. Had to change the type to mediumint(8) to reliably enter semi-reasonable quantities into MYSQL. Couldn't find a mismatch between collation, character sets, it all seemed consistent at UTF8-general, but maybe I missed something there. Had to change to mediumint(8) in the database tables AND stored procedures (qty parameter definition).
 
This first problem affects both the cart and the wishlist, have to fix both places.
 
Second problem, calculating the subtotal fails when in thousands because the number format function returns a string with the comma.
 
try:
echo gettype($price);
echo '<br>' . 'price is ' .  $price;
 
The inherent typecasting to INT apparently is truncating to just the thousands digit. Found this fix online, just insert in cart.php (and wishlist.php) after the get_just_price function but before the subtotal calculation:
 
    $price = htmlentities($price); //important part
    $price = str_replace(array('&amp;#36; ', ','), '', $price); //remove $ and comma

  • 0

#15 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 9 June 2017 - 1:50 PM

When I run this query:

 

CALL get_shopping_cart_contents('8fffa77c5b12ea1aa09922e1053aa52a');

 

sku   quantity    category     name                                         price     stock sale_price
C3         21        Kona          Half Pound - decaf - ground       5000    200   NULL
C6         2          Kona          1 lb. - caf - whole                      75000    50     NULL
C4         1          Kona          1 lb. - caf - ground                  800000    50     NULL
C5         2          Kona          1 lb. - decaf - ground              850000    20     NULL
 
I think the prices are correct.
 
And there is not any sale item in the cart right now.
 
And thanks to daddytiger so much I will surely look into the codes. But can you provide me the step by step details because I am still in a learning phase.

  • 0

#16 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 9 June 2017 - 4:53 PM

Ah, so this is progress! It looks like the get_shopping_cart_contents() is returning the right values. So the problem seems to be in either the PHP or the HTML. In looking at cart.html, the price is shown using:

 

$price = get_just_price($row['price'], $row['sale_price']);


// Calculate the subtotal:
$subtotal = $price * $row['quantity'];


// Print out a table row:
echo '<tr><td>' . $row['category'] . '::' . $row['name'] . '</td>
<td align="center"><input type="text" name="quantity[' . $row['sku'] . ']" value="' . $row['quantity'] . '" size="2" class="small" /></td>
<td align="right">$' . $price . '</td>
<td align="right">$' . number_format($subtotal, 2) . '</td>

number_format() on its own is not going to be the problem:

echo number_format(850000*2);
1,700,000

This makes me look at the get_just_price() function:

 

function get_just_price($regular, $sales) {


// Return the sale price, when appropriate:
if ((0 < $sales) && ($sales < $regular)) {
return number_format($sales/100, 2);
} else {
return number_format($regular/100, 2);
}


} // End of get_just_price() function.
And I'm fairly sure I've found the problem: it returns the price run through number_format(), and that number is going to be run through number_format() again in the script. Update the function so that it only returns $sales/100 or $regular/100 and see if that fixes the problem.

  • 0

#17 vikky

vikky

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 17 June 2017 - 3:11 PM

Thank you very much for the solution and the time you took to debug this problem.

 

Steps taken:

 

  1. Open product_functions.inc.php under includes directory.

  2. This is my modified get_just_price() function.

function get_just_price($regular, $sales) {

 
// Return the sale price, when appropriate:
if ((0 < $sales) && ($sales < $regular)) {
return $sales/100;
} else {
return $regular/100;
}
 
}

 

Now its showing the correct prices.

 

Second problem which daddytiger has mentioned.

 

Steps taken:

 

  1. Increased the quantity of the specific_coffees to 300 in the phpmyadmin.

  2. Clicked add to cart in the http://localhost/browse/coffee/Kona/3.

  3. Increased the quantity in the cart.php from 1 to 277 but it is showing only 127.

So there is a problem.

 

Looking in the SQL table structure:

 

carts - `quantity` TINYINT(3) UNSIGNED NOT NULL.

 

non_coffee_products - `stock` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0'.

 

order_contents - `quantity` TINYINT(3) UNSIGNED NOT NULL.

 

specific_coffees - `stock` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0'.

 

wish_lists - `quantity` TINYINT(3) UNSIGNED NOT NULL.

 

It seems there is a mismatch between `quantity` and `stock`.

 

I am not very sure about the stored procedures.

 

Your opinions are very important.


  • 0

#18 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4766 posts
  • LocationState College, PA (USA)

Posted 27 July 2017 - 11:27 AM

Well, I would argue that it's probably a mistake if someone is trying to buy more than 127 of an item. At the very least, in a real ecommerce site, they should contact the business for bulk discount on pricing and shipping. Still, having the user enter, say, a quantity of 500 and having that turn into 127 would appear to be a bug (to the user). If it were me, I'd add a check in PHP saying there's the limit on the quantity should a value greater than 127 be entered. 

 

Alternatively you could change the database and procedures to support a large quantity but I think that'd qualify as engineering support for an impractical situation. But however you want to handle it, of course!


  • 0