Product quantity input method

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301819

Hi,

I may be wrong but i think in the older hikashop version we could have different quantity input method in different areas. Now it seems it is handled by one settings in product options->Quantity input method. We would like to keep our selection there "show left and right" and have select box in cart view show? Maybe i miss some settings please?

Thanks

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301833

Hi,

No there is and was never such options. It might have been a bug you found before where the display of the quantity input wasn't consistent throughout the different views.
Now however, with some easy view overrides you can achieve that.
For example, if you want to force to always have a select in the cart view of the checkout, you can change the line:

if($product->product_quantity_layout == 'show_select' || (empty($product->product_quantity_layout) && $this->config->get('product_quantity_display', 'show_default_div') == 'show_select')) {
to
if(true){
int he show_block_cart view file via the menu Display>Views menu.

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301847

Hi,

Thanks for replay Nicolas. Indeed that bug was used by us :)
Now, is there a way to change quantity selection to chosen select box in cart->show view? I have located code which is responsible for layout but i have no idea how this can be changed here:

<?php
	if(!empty($this->manage)) {
		if($this->cart->cart_type == 'wishlist') {
			$this->row->product_min_per_order = 1;
			$this->row->product_max_per_order = 0;
		}
		echo $this->loadHkLayout('quantity', array(
			'quantity_fieldname' => 'data[products]['.$product->cart_product_id.'][quantity]',
            'onchange_script' => 'window.cartMgr.checkQuantity(this);',
			'extra_data' => 'data-hk-product-name="'.$this->escape($product->product_name).'"',
		));
	} else {
?>
				<div class="hikashop_product_quantity_div hikashop_product_quantity_input_div_none">
					<span><?php echo $product->cart_product_quantity; ?></span>
				</div>
<?php
	}
?>

Thanks

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301848

I also found that in product page if variant has quantity 2, you can't select more than 2 and it's great feature...
However in cart->show view "data-hk-qty-max" doesnt work as it works on product page and it's always set to "0". So i assume there is a bug unless it's done on purpose or something... Attaching screenshots



Attachments:
Last edit: 6 years 3 months ago by kyratn.

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301850

Hi,

1. I think you can force it by adding such code:

'quantityLayout' => 'show_select',
after the line:
'extra_data' => 'data-hk-product-name="'.$this->escape($product->product_name).'"',
2. You can see in the code that you posted that the min and max quantities are forced to 1 and 0 when the cart is a wishlist on the cart/show.php view file:
		if($this->cart->cart_type == 'wishlist') {
			$this->row->product_min_per_order = 1;
			$this->row->product_max_per_order = 0;
		}
That's because it's a wishlist. You can wish to purchase 10 items of a product even if the current stock of the product is only 2. So we purposely disable the max on the quantity field for wishlists. I guess that's what you're looking at. So in that case, it's not a bug, it's a feature :p

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301889

Hi,

1. Thanks

2. Well you right about wishlist but what if it is cart? What's the point to allow select/change to more quantity than possible stock? I think it should behave as on product page if cart is cart and not wishlist?

Regards

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301890

Hi,

2. That's the case. If you look at the code the "if($this->cart->cart_type == 'wishlist') {" only force the min/max if it's a wishlist. This isn't the case for carts and thus it works like on the product page for carts.

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301897

Hi,

Hmm, i had to add this in else statement for it to work:

$this->row->product_max_per_order = $product->product_quantity;

I also tried with protostart template just now and it doesn't work without my modification, you may want to try by your self Nicolas :)

Thanks

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

  • Posts: 26215
  • Thank you received: 4032
  • MODERATOR
6 years 3 months ago #301914

Hello,

Unfortunately, the max product per order is not the product quantity.
So I do not understand the nature of your patch proposal ; specially when there is no limit when displaying a wishlist, as Nicolas explained previously.

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: 1119
  • Thank you received: 114
6 years 3 months ago #301946

Hi,

It's not about wishlist. It's about cart... As Nicolas said:

"If you look at the code the "if($this->cart->cart_type == 'wishlist') {" only force the min/max if it's a wishlist. This isn't the case for carts and thus it works like on the product page for carts."

However input in cart doesn'r work like in product page. If you have product stock of 2, you still can increase input numbers with plus sign to more than 2, however on product page if stock is 2, you won't be able to increase it... As i said you may take a look into it.

1. Create product with variant and quantity of 2.
2. Create menu Hikashop->cart display.
3. Add that product to cart and go to that menu.
4. Try to increase quantity by pressing plus sign, and you will be able to increase as much as you want...If you do save it will throw error for sure but that's not the question here.... If you do same on product page, you won't be able to increase quantity to more than 2 by pressing plus sign...

Anyway i may be wrong, you should know better what you guys doing with your component....

Thanks

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301965

Hi,

Well, it's more than up until now the information you provided to reproduce the problem was not precise enough and we didn't had the problem on our end in the various tests we made.
I was actually able to reproduce the issue today and apparently, this only happens in carts where you have products where you directly assign the quantity to the variants themselves. If the product has no variant or that the quantity is set at the product level this issue doesn't happen.
So thank you for your feedback, it's alwasy great to fix issues, even small ones like this one, but it would be great if you could provide more precise information next time when you report one. That will reduce the back and forth between us and it will make everyone happier :)
So I've made a patch on our end by changing the code:

if($this->row->product_quantity > 0)
		$max_quantity = min($max_quantity, $this->row->product_quantity);
to:
if($this->row->product_quantity > 0) {
		if($max_quantity == 0)
			$max_quantity = $this->row->product_quantity;
		else
			$max_quantity = min($max_quantity, $this->row->product_quantity);
	}
in the file components/com_hikashop/views/layouts/tmpl/quantity.php
It now works fine on my tests with that patch (note that if you have an override of layouts/quantity.php you need to do that change in the view override.

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301967

Hi,

Thanks Nicolas for taking your time to look into this and sorry for not giving precise enough instructions to reproduce the issue.
After Jerome replay i understood that we were talking about different things :)

Thanks again

The following user(s) said Thank You: nicolas

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301975

Hi,

Seems i have another issue. In the product->cart view i have changed some code to force input selection to be select box:

$this->row =& $product;
		$this->quantityLayout = $this->cartHelper->getProductQuantityLayout($this->row);
		if(!in_array($this->quantityLayout, array('show_simple','show_select','show_select_price','show_none')))
			[b]$this->quantityLayout = 'show_select';[/b]
		echo $this->loadHkLayout('quantity', array(
			'quantity_fieldname' => 'item['.$product->cart_product_id.'][cart_product_quantity]',
			'onchange_script' => 'window.hikashop.checkQuantity(this); if(this.value == '.(int)$product->cart_product_quantity.'){ return; } if(this.form.onsubmit && !this.form.onsubmit()) return; this.form.submit();',
		));

And it works fine but after i choose different quantity, the ajax refresh is triggered and the chosen library is not initialized, those page needs to be refreshed for chosen to be reinitialized again.

Thanks
Thanks

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301980

Hi,

Try adding the line:

if(typeof(jQuery) != "undefined" && jQuery().chosen) { jQuery(elem).find(".chosen").chosen(); }
after the line:
elem.innerHTML = text;
That should hopefully do the trick.
Let us know how it goes.

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #301987

Hi,

I would be more then happy to do it if you could tell me where? :)

I used some search and only could find it in hikashop.js file on line 302, added after and it didn't work...

The only what helped was adding this directly in the view but i don't think it's the right way to do it.

window.hikashop.ready( function() {
      jQuery(".no-chzn").chosen({disable_search: true});
  });

Thanks

Last edit: 6 years 3 months ago by kyratn.

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 3 months ago #301995

Hi,

Yes, in was in hikashop.js
Then try that line instead:
if(typeof(jQuery) != "undefined" && jQuery().chosen) { jQuery(elem).find("select").chosen(); }
Note that, we will probably add that line instead:
if(typeof(jQuery) != "undefined" && jQuery().chosen) { jQuery(elem).find("select").not('.no-chzn').chosen(); }
so that dropdowns with the no-chzn class are not chosenified when the ajax is refreshing some elements.
However, I actually don't see why the dropdown would have chosen applied to it in the first place on your website since it has the class no-chzn which is a class used to tell chosen to not chosenify that dropdown.

In any case, your solution is fine too.

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

  • Posts: 1119
  • Thank you received: 114
6 years 3 months ago #302020

Hi,

Well, it is applied on page load but gone after ajax refresh.

I have been playing with it and found that probably quantity layout isn't applied after ajax refresh. Please take a look into my screenshots, first is before ajax with:

$this->quantityLayout = 'show_select';

in the product->cart view and second is after ajax refresh. You should see the difference.





So i think that's why layout is set to show_simple by default because it doesn't work with ajax refresh.

Thanks

Attachments:

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

  • Posts: 83512
  • Thank you received: 13511
  • MODERATOR
6 years 2 months ago #302061

Hi,

Then you should change your custom code.
For example, if you remove that line:

if(!in_array($this->quantityLayout, array('show_simple','show_select','show_select_price','show_none')))
it should always display the dropdown, no matter what.

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

Time to create page: 0.103 seconds
Powered by Kunena Forum