Post by rleighton » Sat Aug 22, 2009 5:38 am

I'm very new to OpenCart. About an hour. I'm a web developer and am thinking about using it for clients. I like the simplicity and I love the "add-to-cart" visual and that I stay on the same page. But, when I go to the cart, I'm able to order fractions of items and OpenCart happily calculates the extended price. That looks stupid and it doesn't give me a confident feeling about this software. And, it isn't just the demo store. I've gone to live OpenCart storefronts and ordered 1.7 computer monitors. I did NOT continue to Checkout and hopefully this issue is caught at that point.

Newbie

Posts

Joined
Sat Aug 22, 2009 4:29 am

Post by SuperJuice » Sat Aug 22, 2009 8:25 am

Have confirmed this on 1.3.2.

Added 1.7 of a 2.00 item to my cart, showed cart total of 3.40.

Completed checkout procedure and admin panel shows only 1 item with a value of 3.40.

It won't work for fractions less than 1, ie. 0.7.

To reproduce:
1. Add item to your cart
2. Click 'Basket'
3. Modify quantity of item to fraction, eg 1.7 and click 'Update'
4. Complete checkout as normal

Granted this isn't desirable and appears to have been overlooked, but I think you will find when working on OpenCart that as a rule the code is extremely well written, easy to follow and easy to extend... but you're more than welcome to spend some time working on with osCommerce if you don't believe me ;)

Active Member

Posts

Joined
Thu Aug 13, 2009 12:06 pm

Post by Daniel » Sat Aug 22, 2009 8:36 am

I thought I stoped this from happenign.

I used (int) on the qty.

Try this code:

Code: Select all

  	public function add($product_id, $qty = 1, $options = array()) {
    	if (!$options) {
      		$key = $product_id;
    	} else {
      		$key = $product_id . ':' . implode('.', $options);
    	}
    	
		if (((int)$qty) && ((int)$qty > 0)) {
    		if (!isset($this->session->data['cart'][$key])) {
      			$this->session->data['cart'][$key] = (int)$qty;
    		} else {
      			$this->session->data['cart'][$key] += (int)$qty;
    		}
		}
  	}

  	public function update($key, $qty) {
    	if (((int)$qty) && ((int)$qty > 0)) {
      		$this->session->data['cart'][$key] = (int)$qty;
    	} else {
	  		$this->remove($key);
		}
  	}

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by rleighton » Sat Aug 22, 2009 8:58 am

Thanks, guys. You have an impressive community, here.

Daniel, I'll try that code. Thanks.

Newbie

Posts

Joined
Sat Aug 22, 2009 4:29 am

Post by dimitris68 » Sat Aug 22, 2009 4:46 pm

any clue on which file should be edited ??

Newbie

Posts

Joined
Sat Aug 22, 2009 4:45 pm

Post by Qphoria » Sat Aug 22, 2009 8:10 pm

In 1.3.2: system/helper/cart.php
In earlier versions: system/library/cart.php

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by wal_j » Sat Aug 22, 2009 11:25 pm

Daniel wrote:I thought I stoped this from happenign.

I used (int) on the qty.
The Code worked for me on 1.3.2.

I had a thought though, If somebody enters that they require "1.3" items, 1 obviousely is not enough for them so should the code be rounding up to increase sales? ;D

1.3 = 2
instead of
1.3 = 1

Alex

New member

Posts

Joined
Tue May 12, 2009 11:51 pm

Post by Qphoria » Sun Aug 23, 2009 1:00 am

Then use
ceil($qty)
instead of
(int)$qty

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 12 guests