Opencart Decimal quantity

Fractional quantity of goods. For Opencart 2.x and 3.x is supported. look upon DEMO. In this article you will receive full instructions. Do everything with us.

  1. We work with database tables. Table oc_cart . In this table, you need to change the data type of the field. quantity field to decimal(15,2)
    In the tables productproduct_option_valueproduct_discount and order_product change data type of fields quantity field to decimal(15,2)
  2. Editing files.
    – /system/library/cart.php replace here
    (int)$quantity field to $quantity

    – /admin/model/catalog/product.php
    here we make replacements
    (int)$data[‘quantity’]  field to  $data[‘quantity’]
    (int)$product_option_value[‘quantity’] field to $product_option_value[‘quantity’]
    (int)$product_discount[‘quantity’ field to $product_discount[‘quantity’]
    (int)$data[‘minimum’] field to $data[‘minimum’] 

    – /catalog/model/checkout/order.php here we make replacements
    (int)$product[‘quantity’] field to $product[‘quantity’]
    (int)$order_product[‘quantity’] field to $order_product[‘quantity’]  (4 times)

    – /catalog/controller/checkout/cart.php here we make replacements
    in the function public function add() we find the block
    if ($product_info) {
        if (isset($this->request->post[‘quantity’]) && ((int)$this->request->post[‘quantity’] >= $product_info[‘minimum’])) {
    $quantity = (int)$this->request->post[‘quantity’];
        } else {
    $quantity = $product_info[‘minimum’] ? $product_info[‘minimum’] : 1;

    and remove (int)
    if ($product_info) {
        if (isset($this->request->post[‘quantity’]) && ($this->request->post[‘quantity’] >= $product_info[‘minimum’])) {
    $quantity = $this->request->post[‘quantity’];
        } else {
    $quantity = $product_info[‘minimum’] ? $product_info[‘minimum’] : 1;

If you add a fractional quantity of one product (for example, 1.5), then in the header of the information block there will appear “In the basket 1.5 product (s)”. This misunderstanding needs to be corrected, namely: we need to display in the information block not the number of goods, but the number of lines of the selected product. Moreover, we have no right to add fractional goods with integers. To do this, you need to make corrections to the file. /system/library/cart.php, slightly modify the countProducts() function.

	public function countProducts() {
		$product_total = 0;
		$products = $this->getProducts();

		foreach ($products as $product) {
			$product_total += $product['quantity'];
			$product_total = $i;
		return $product_total;

Leave a Reply