Jump to content

Product quantity field filled with minimum quantity possible?


Leo Clark

Recommended Posts

Please try this:

In content.product.php (Foundation), find:

{if $PRODUCT.available lte 0}
<div class="small-12 columns">
  <input type="submit" value="{$LANG.common.unavailable}" class="button small disabled expand marg-top" disabled>
</div>
{else}
<div class="medium-2 columns show-for-medium-up">
  <input type="text" name="quantity" value="1" class="quantity required text-center">
  <input type="hidden" name="add" value="{$PRODUCT.product_id}">
</div>
<div  class="small-12 medium-10 columns">
  <button type="submit" value="{$LANG.catalogue.add_to_basket}" class="button postfix">{$LANG.catalogue.add_to_basket}</button>
</div>
{/if}

This statement:
<input type="text" name="quantity" value="1" class="quantity required text-center">

Change to:
<input type="number" name="quantity" value="{if !$PRODUCT.minimum_quantity}1{else}{$PRODUCT.minimum_quantity}{/if}" min="{if !$PRODUCT.minimum_quantity}1{else}{$PRODUCT.minimum_quantity}{/if}" class="quantity required text-center">

This uses an HTML5 form element type of "number" (not available in IE9 and earlier). So, if the product's minimum quantity is not set or defaulted to zero, then use '1'. Otherwise, preload the number element with the minimum quantity and do not allow the spinner to let the number go below that (or '1').

I have not make extensive tests. It could be that the form validations may have a problem because this form element is no longer a textbox. But manually entering, for example, '-3', I get a red validation error. I do not know where it comes from, however.

And this only covers the View Product page. More work would need to be done wherever else there is the opportunity to add the product to the shopping basket or change the quantity - during checkout, for example.

The minimum quantity parameter of a product is relatively new. I have not yet discovered what happens if minimum quantity is higher than available stock.

Link to comment
Share on other sites

One way around skin code changes is to copy the stock Foundation code over to a newly named skin folder (mine). Change YOUR skin version's config.xml file so that the CDATA lines look something like this:

<name><![CDATA[mine]]></name>
	<display><![CDATA[My Name]]></display>
	<version>1.0</version>

Upgrades will not touch your renamed version. Using file difference software like BeyondCompare makes it easy to see if there are any skin code changes in an upgrade. Only those few changes would then need to be incorporated into your skin.

Link to comment
Share on other sites

Thanks @Dirty Butter. I will mess around and see what I will do.
It worked @bsmither ! It has a little scroll button which is nice, the message looks funny and cropped but at least is closer to what matters, the field itself (Screenshot attached).
I believe I have to do the same thing to categories view and latest products.

Screen Shot 2016-01-11 at 9.23.13 PM.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...