1

I would like to configure my Magento store (Version: Magento 2.4.5) to have a Minimum Quantity of 1 and a Default Quantity of 5 for the products. Could you please provide me with instructions or guidance on how to make these specific changes?

I have tried: Store > Catalog > Inventory > Product Stock Options > Minimum Qty Allowed in Shopping Cart but this Set both Minimum Quantity and Default Quantity to 1

enter image description here

2 Answers 2

3

There is no native way to set a different Minimum Quantity and Default Quantity.

Here is how Magento determines which is the "Default Quantity" :

\Magento\Catalog\Block\Product\View::getProductDefaultQty

    public function getProductDefaultQty($product = null)
    {
        if (!$product) {
            $product = $this->getProduct();
        }

        $qty = $this->getMinimalQty($product);
        $config = $product->getPreconfiguredValues();
        $configQty = $config->getQty();
        if ($configQty > $qty) {
            $qty = $configQty;
        }

        return $qty;
    }

You can see Magento will either get the Minimal Qty ($this->getMinimalQty($product)), or from a "preconfigured value" ($product->getPreconfiguredValues()).

This preconfigured value is generaly only defined when you have a buyRequest parameter, meaning you are editing a product (from cart, whishlist, ...).

Solution

A solution would be to create an "after" plugin on the following method : \Magento\Catalog\Model\Product::getPreconfiguredValues.

In this plugin, you can verify if $preConfiguredValues->getQty() has been set, and if not, you can define it with your custom Default Quantity.

1

You can do this in the product level by editing the product and going under the Advanced Inventory option and un-tik the Minimum Qty Allowed in Shopping Cart and filling in the minimum value. enter image description here

2
  • 1
    This solution is similar to what OP tried. I think what OP wants is to be able to define a Minimum Qty to 1, but showing a different value by default on the product page : Products page shows a qty of 5, but customer can lower the value down to 1.
    – Cladiuss
    Jul 4, 2023 at 7:35
  • @Cladiuss is right, this is what I want. Jul 4, 2023 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.