简体   繁体   中英

Magento - How to set minimum amount of products per order for a category?

Is it possible to set the minimum number of products required for a category per order in Magento. A client sells wildlife paintings, one of the shop categories is 'cards', it isn't very cost effective to ship less than 6 of these at a time.

How would I force a minimum of 6 products from the cards category?

Thanks, Dan

B00MER's suggestion is probably the easiest path if, from a business perspective, you can require users to buy the cards in certain quantities. The downside will be that they will be required to order multiples of the same card.

If you need to allow multiple different cards and still enforce limits, consider using a minimum order amount for the entire cart. This will cover cases of other products where shipping small quantities is not profitable.

If that doesn't work, consider using table rate shipping and using that as a handling fee for unprofitable orders. Or a handling fee for all orders.

If that doesn't work, AFAIK, you'll need to do some custom code checks as you describe. How would this work with products that are in several subcategories and so forth? Definitely doable, but the semantics may be odd.

Hope that helps!

Thanks, Joe

As an alternative suggestion consider creating a cart price rule that, while not preventing smaller quantities, can offer encouragements to potential customers.

For example a rule might have the conditions:

  • Product attribute combination (If an item is FOUND etc...)
  • Quantity in cart equals or is greater than 6
  • Attribute set is whichever set you use exclusively for cards

and then offer free shipping on those cards.

Presumably the cost of shipping a card is negligible when an order also contains something much bigger, like a canvas painting.
Set the minimum weight of your chosen shipping method to something like 1 Lb and the weight of each card to 0.18 (between one fifth and one sixth). That way a customer has to buy at least 5 others or something heavy at the same time.

I don't know about Categories but if you want to add a minimum quantity allowed for a single product page there is a round about way of doing it.

Using Magento create the product page as you normally would. Once created go to the page and view the source code. Grab all of the code and dump it into a editor (ie notepad++). From there scroll down through the code until about line 560-580 depending on your layout. You should find the javascript function:

 productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }

    }.bind(productAddToCartForm);

From here you would edit it to look like something similar to this:

productAddToCartForm.submit = function(button, url) {
    var LJSM1 = parseFloat(document.getElementById('bundle-option-1-qty-input').value);
    var L2 = parseFloat(document.getElementById('bundle-option-2-qty-input').value);
    var L3 = parseFloat(document.getElementById('bundle-option-3-qty-input').value);
    var L4 = parseFloat(document.getElementById('bundle-option-4-qty-input').value);
    var L5 = parseFloat(document.getElementById('bundle-option-7-qty-input').value);
    var L6 = parseFloat(document.getElementById('bundle-option-6-qty-input').value);
        if (this.validator.validate()) {
        if((L1+L2+L3+L4+L5+L6) <= 15){
        alert("Sorry you are below the minimum order. Please increase your order to 16 or more to continue.");
        }
        else{
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }
        }
    }.bind(productAddToCartForm);

In my case I added a simple if/else statement and called the options within the page and assigned them to a variable which I then summed.

After you have modified this code you can then save it to a .html file with the same name as the original page's URL and then upload it to the root of your magento directory. This acts as a sort of mask to the original page and so when browsing to the product you will be directed to this page instead of the original Magento page. The shopping cart, options, and java script will still work and everything will act normally. The only downsides are that whatever the page looked like when you grabbed the code is what it will look like to everyone else. So I recommend deleting the code for your shopping cart, product compare, and anything else that would have unique data so that there isn't any confusion. On top of that if you make any changes to the original Magento page or to your themes you will have to run through the process again really quick to update the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM