Non-Numeric Product Quantity Deletes Product From Cart

  • Posts: 31
  • Thank you received: 1
7 years 5 months ago #270607

-- HikaShop version -- : 3.1.0
-- Joomla version -- : 3.7.2
-- PHP version -- : 7.1.1

Not a serious bug I don't think, but in the off-case that a person accidentally types in non-numeric input (e.g. "asdf") in Checkout into the Product Quantity field, on clicking Refresh/Next, the product is removed from the cart. It works fine if the non-numeric characters are after the number (e.g. "12asdf"), just not if the quantity starts with non-numeric character.

Expected behavior is a message that says there's a typo in the Product Quantity field, not just deleting the product from the cart.

Additional test case, If you add a product from the Product/Category page and give a non-numeric quantity, it adds 1 to the cart.

Thanks.

Last edit: 7 years 5 months ago by nyanginator. Reason: Info on additional test case for quantity field on Product/Category page

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 5 months ago #270609

Hello,

Can you please edit the file "administrator/components/com_hikashop/helpers/checkout/cart.php" and replace

		$items = array();
		foreach($data['cart']['item'] as $k => $v) {
			$items[] = array(
				'id' => (int)$k,
				'qty' => (int)$v
			);
		}
By
		$items = array();
		foreach($data['cart']['item'] as $k => $v) {
			if((int)$v == 0 && !is_numeric($v))
				continue;
			$items[] = array(
				'id' => (int)$k,
				'qty' => (int)$v
			);
		}
		if(empty($items))
			return true;
It should allow to skip the items with non numeric value.
That patch is only for the checkout cart ; if the behavior is better, we will see to create the same kind of patch for the cart module and the cart edition.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 1
7 years 5 months ago #270705

Hi, would it be better to have an error message about an invalid quantity? The patch works, ignoring any quantity changes to a product when a non-numeric quantity is given, and proceeds to the next step of checkout. I'm just wondering if it makes more sense to force the user to confirm exactly what the quantity of each cart product is. I guess the customer would have to really not be paying attention to type letters in the quantity box and not realize it, but users can tend to surprise us, yeah? (e.g. if a user wanted to type 3 but instead typed 'e', then the checkout would proceed with just quantity 1 instead).

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 5 months ago #270787

Hi,

We'll actually add some javascript on the inputs in the next version so that if what is entered in the quantity field is invalid, the system automatically reverts to the initial quantity when the input looses the focus (when the customer clicks somewhere else that the input field). And thus, no submit will happen in such case until the customer click on the "next" or "finish" button.
That way, he should better see the issue and it will be nicer.
We don't want to add an alert message. It kinds of stops the flow of the customer and is often regarded as bad UX.

The following user(s) said Thank You: nyanginator

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 1
7 years 5 months ago #270796

Thanks, on that note, the behavior of changing the quantity (a valid numeric one) and clicking Next results in the cart page being reloaded with no message, so it actually looks like clicking Next did nothing. If adding a message such as "Cart updated" disrupts the flow of the customer, would it be better to just go to the next step of checkout instead with the new quantity?

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 5 months ago #270798

Hello,

I'm sorry but I'm not following you.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 1
7 years 5 months ago #270841

Sure, let me try to clarify:

  1. Add product to cart
  2. Change quantity and click Next button
  3. Instead of going to the next step of the checkout, it stays on the cart page with no message (and sure, the quantity has been updated)
  4. I have to click Next again in order to get to next step of checkout

So it takes two clicks of Next to get to the next step of checkout, and no message as to why the second click is necessary. At least for me personally, I found that odd. It's like the first time I clicked Next had no effect. Or at least the button should change from "Next" to "Update Cart".

In Magento, it actually just ignored the quantity change and went to the next step of checkout with the old quantity, but I didn't quite like that either. In my opinion, the expected behavior should be that it goes to the next page of the checkout with the new quantity.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 5 months ago #270876

Hi,

That's a good idea. We'll add some message in such case so that the customer better understand what happened.
Going to the next step is not something I like. Then the customer doesn't even know how much he has to pay because of the change he just made.
If you have a checkout in three steps with: cart shipping payment
Then, if you change the quantity of a product on the step and it goes to the next step, you select the shipping and then the payment and you don't even know how much you'll be billed (for example if you use authorize.net in AIM with the credit card form on the checkout). That's something we want to avoid as much as possible.
Now you might say that the checkout workflow of the merchant is not adapted in that case, and I agree, but we still want to handle that properly.

The following user(s) said Thank You: nyanginator

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 1
7 years 5 months ago #270912

Good point. I guess I didn't think of that because I was showing a Cart Status on the last page before payment. I like the idea of just showing a message. Thanks.

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum