Changing the default quantity on a Magento product page

Changing the default quantity on a Magento product page

By Luke on

For anyone that has used the Magento ecommerce platform, you will know that it is a fantastic system to use for your online shop. As well as being a very comprehensive system, it also has added SEO benefits and much more. However, from a developers perspective, there have been a few complaints, and this is mainly due to the combination of the fact that it very complex, and there is still currently a lack of supporting materials. For example, one of the main questions I hear from developers using the system for the first time, is “how do you add products to the homepage of a Magento site“? That’s quite a fundamental issue…


Setting the default quantity of a Magento Product

Another question I hear a lot is “can you set the default quantity of a product in Magento”? When trying to purchase items, Magento insists that you, first of all, enter an integer in the quantity box. This isn’t a massive issue, but it creates another barrier / additional step for a customer trying to buy one of your products. Well, after a bit of digging I have found a solution! The source of this solution is Sam Davies of who provides a quick and easy solution by inserting the default quantity as your minimal quantity (as defined in your site configuration), so the user only has to click once. The solution he provides is a little out of date in terms of the Magento directory structure (his original post was November 2008), and his code isn’t formatted correctly due to HTML issues, so we have provided an update:

First locate the file addtocart.phtml, which can be found in the following directory (replace “yourdesign” with the name of the template design you have created for your shop):


Open the file in your normal web / text editor and you find this code (around line 35):

<input name=”qty” type=”text” id=”qty” maxlength=”12″ value=”<?php echo $this->getMinimalQty($_product) ?>” /></span>

Now replace it with this code:

<input name=”qty” type=”text” id=”qty” maxlength=”12″ value=”<?php echo $this->getMinimalQty($_product)== null?1:$this->getMinimalQty($_product) ?>” /></span>

Upload the updated file via your normal FTP software and voila! You should now have a minimal amount in the quantity box, and one less obstacle for your customers!

About Luke

Luke is the owner of Falkon Digital Ltd, the head honcho. He likes strong coffee & fried chicken but not at the same time.

Related Posts
Comments (7)
  1. simon

    Sorry, there was a copy&paste problem with one of the “” signs after “12″. Fixed. Fixed lenght problem with css.

    Thanks a million for this code!!!

  2. SEO Creative

    Glad we could help! After seeing your comment I had to double check the code to make sure it had been entered correctly but it must just have been a copy & paste issue as you said

  3. aaron

    Just an update on this using the latest version of magento. In the addtocart.phtml file in the line-
    <input type="text" name="qty" id="qty" maxlength="12" value="getProductDefaultQty() * 1 ?>”

    I changed the “* 1″ to a “+1″ to get this-

    <input type="text" name="qty" id="qty" maxlength="12" value="getProductDefaultQty() + 1 ?>”

    and it did the trick for me! Thanks!

  4. Terrafield

    I changed the above code for Magento into:
    <input name="qty" type="text" id="qty" maxlength="12" value="getMinimalQty($_product)== null)?1:$this->getMinimalQty($_product) ?>” title=”__(‘Qty’) ?>” class=”input-text qty” />

    The main change are the brackets around the “true” statement.ยด, without it is not working under php5

  5. Stefan

    Been playing with it for a while now, but i want it just the other way around. Everything is on 1 and i want it to change to 0.

    I think something went wrong at the import of all the products. so all my simple products in a grouped product have a default qty of 1.

    Any idea if i can change this in the code.