Opencart 4 · 5 min read · Updated

Sell in Packs for OpenCart 4: Quantity Steps (Packs of 6, Cases of 12) and a Maximum per Order (Free Extension)

Only allow whole packs and set a maximum per order: the product page rounds to packs, cards add one pack, and checkout stays closed until quantities are valid.

Opencart 4 sell in packs

Some products only make sense in multiples: wine by the case of 6, screws by the box of 100, T-shirts for a team in tens. Others need a ceiling: a limited release, a heavily discounted item, or anything resellers like to buy out. OpenCart 4 has a Minimum Quantity field on each product, but nothing for “multiples of 6” and nothing for “no more than 24 per order”.

This free extension adds both. Pick a product, set the pack size and an optional maximum, and OpenCart only lets customers order whole packs up to that limit, from the product page all the way to checkout.

Download Sell in Packs for OpenCart 4 (free, tested on OpenCart 4.1.0.4)

OpenCart 4 product page for iPod Classic, the quantity box starting at 6 with the note Sold in packs of 6. Maximum 24 per order. under Add to Cart
The quantity starts at one pack, with the pack size and the limit right under it.

What it does

  • Pack sizes per product. Packs of 6 means 6, 12, 18… can be ordered, and nothing in between.
  • A maximum per order per product, with or without a pack size.
  • On the product page, the quantity box starts at one pack, a note shows the pack size and limit, and anything the customer types is rounded up to a whole pack (8 becomes 12) and capped at the maximum.
  • On product cards (category, search, Latest, Featured and other modules), the Add to Cart button adds one pack instead of one item.
  • In the cart, any product in the wrong quantity gets a clear message with the nearest valid quantities, and the Checkout button is disabled until it’s fixed.
  • Checkout is closed to anyone who goes straight to the checkout URL with an invalid cart: they’re sent back to the cart.
  • Options count together. A pack of 6 can be 3 red and 3 blue.

Install it

  1. Download sellinpacks.ocmod.zip.
  2. Go to Extensions → Installer, upload it, and click the green +.
  3. Go to Extensions → Extensions → Modules and install Sell in Packs.
  4. Click Edit, add your products, turn Status on and save.

Set up your products

Sell in Packs settings in OpenCart 4: a product search box with Sold in multiples of and Maximum per order fields and an Add button, then a table with iPod Classic in multiples of 6 with a maximum of 24, and MacBook in multiples of 1 with a maximum of 2
Two rules: the iPod in packs of 6 (up to 24), and the MacBook limited to 2 per order.

Start typing a product name, pick it from the list, fill in the two numbers and click Add. Every rule stays editable in the table below, and the red button removes it.

FieldWhat it means
Sold in multiples ofThe pack size. 6 allows 6, 12, 18… Use 1 for any quantity (useful when you only want a maximum).
Maximum per orderThe most one order can have, counting all of the product’s options together. 0 means no maximum.

The maximum has to be a whole number of packs. If you enter 20 for packs of 6, the settings page won’t save and tells you why: “A maximum of 20 can’t be reached in packs of 6. Use a multiple of the pack size.” Pick 18 or 24 instead.

Products without a rule aren’t affected, and switching Status off turns all rules off at once without deleting them.

With OpenCart’s Minimum Quantity

The product’s own Minimum Quantity (Catalog → Products → Data) still applies. The extension starts the quantity box at the smallest whole number of packs that meets it: a product with a minimum of 10 in packs of 6 starts at 12.

What customers see

On the product page, the box starts at one pack. If a customer types 8, it becomes 12 as soon as they leave the box or click Add to Cart. If they type 40 with a maximum of 24, it becomes 24. The same happens on a phone:

The quantity box with 6 and Add to Cart on a phone, with the note Sold in packs of 6. Maximum 24 per order.
On a 390 px phone.

The cart is where customers can still change quantities freely. If a quantity isn’t allowed, they see exactly what to change, and the Checkout button stays greyed out until they do:

OpenCart 4 shopping cart with a warning: Please adjust these quantities to continue. MacBook: you have 3, and the maximum per order is 2. iPod Classic is sold in packs of 6. You have 8: choose 6 or 12. The Checkout button is disabled.
Two problems in one cart: too many MacBooks, and 8 iPods where only packs of 6 are sold.

Once both are fixed (2 MacBooks and 12 iPods in our test), the warning disappears and Checkout works again.

How it’s built

Sell in Packs changes no core files. It uses four OpenCart 4 events:

EventWhat it does
catalog/view/product/product/afterSets the starting quantity, adds the note and the rounding script
catalog/view/product/thumb/afterMakes product card buttons add one pack
catalog/view/checkout/cart_list/afterAdds the warning and disables the Checkout button
catalog/controller/checkout/checkout/beforeSends an invalid cart back to the cart page

The cart check adds up every line of the same product first, so different options of one product share the pack and the limit:

foreach ($this->cart->getProducts() as $product) {
    $id = (int)$product['product_id'];

    $totals[$id]['quantity'] = ($totals[$id]['quantity'] ?? 0) + (int)$product['quantity'];
}

// later, for each product with a rule:
if ($rule['max'] && $quantity > $rule['max']) {
    // "you have 3, and the maximum per order is 2"
} elseif ($quantity % $rule['step']) {
    // "sold in packs of 6. You have 8: choose 6 or 12"
}

Why warn in the cart instead of refusing the add to cart? OpenCart’s cart page lets customers type any number, and refusing the change outright would leave them guessing. A message that says “choose 6 or 12” is quicker to act on, and the checkout check makes sure no invalid order gets through either way.

New to events? OpenCart 4 events by example explains how they work.

Testing

TestResult
Save a maximum of 20 for packs of 6Refused: “A maximum of 20 can’t be reached in packs of 6…”
Product page, iPod Classic (packs of 6, max 24)Quantity starts at 6, note shown; typing 8 gives 12, typing 40 gives 24
Add to Cart on the category page cardAdds 6
Cart with 3 MacBooks (max 2) and 8 iPodsBoth problems listed, Checkout button disabled
Opening the checkout URL with that cartRedirected to the cart
Fixed to 2 MacBooks and 12 iPodsNo warning, checkout opens
Canon EOS 5D in packs of 2: 1 Red“Sold in packs of 2. You have 1: choose 2.”
1 Red + 1 Blue (two cart lines)No warning: the two colours make one pack

Troubleshooting

ProblemCause and fix
No note on the product pageCheck Status is on and the product has a rule. A theme that changes the quantity box’s HTML can stop the extension from finding it: compare with the default theme.
Checkout button is greyed outA product in the cart is in the wrong quantity. The message above the cart says which one.
Customers want to mix products in one pack (any 6 wines)Packs are per product. For a mixed case, create a “Mixed case of 6” product with options for the choices.

Related: minimum order amount for OpenCart 4, B2B wholesale pricing for customers who buy by the case, and product options in OpenCart 4.

Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *