Post by ssjal » Mon Feb 01, 2010 4:21 am

Hi,
i implemented Product-level min order qty in my shopping cart. i was using the opencart version 1.3.4
The following code modification helps in setting minimum ordered quantity for each individual product.

We have to make changes in 7 files.

+++++++++++++++++++++++++++++++++++++++++

Database changes:
Add field named "minimum_qty" in product table.

Field name : minimum_qty
Type :int(4)
Null: No
Default: 1
++++++++++++++++++++++++++++++++++++++++
Front End Changes:
1.) catalog\language\english\product\product.php
Add

Code: Select all

$_['text_minimum_qty']  = 'Minimum Quantity:';
2.) catalog\controller\product\product.php
Find:

Code: Select all

$this->data['text_wait'] = $this->language->get('text_wait');
Add following after the above code:

Code: Select all

$this->data['text_minimum_qty'] = $this->language->get('text_minimum_qty');
+++++++++++++++
Find:

Code: Select all

$this->data['model'] = $product_info['model'];
Add following after the above code:

Code: Select all

$this->data['minimum_qty'] = $product_info['minimum_qty'];
3.) catalog\view\theme\default\template\product\product.tpl
Find:

Code: Select all

<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="1" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
              <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
              <input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
            </form>
Replace with following code:

Code: Select all

<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;">
              <b><?php echo $text_minimum_qty; ?></b>&nbsp;&nbsp;
              <?php echo $minimum_qty; ?><br /><br />
              <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<? echo $minimum_qty;?>" />
                <a onclick="return send_onclick(frmName);$('#product').submit()" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
              <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
              <input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
            </form>
++++++++++++++++++
Find:

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product">
Replace with the following:

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product" name="frmName" onsubmit="send_onclick()">
+++++++++++++++++++
Adding javascript:
Find:

Code: Select all

    <script type="text/javascript"><!--
$.tabs('.tabs a'); 
//--></script>
Add following after the above code:

Code: Select all

<script type="text/javascript" language="JavaScript">
function send_onclick(frmName) {
var bolSubmit;
bolSubmit = true;
myvariable = <?php echo $minimum_qty; ?>;
if (frmName.quantity.value < myvariable) {
alert("Please Enter Minimum Quantity");
bolSubmit = false;
}
if (bolSubmit == true) {
frmName.submit(frmName);
}
}
//-->
</script>
ADMIN END CHANGES

4.) admin\view\template\catalog\product_form.tpl
Find:

Code: Select all

      <tr>
        <td><?php echo $entry_price; ?></td>
        <td><input type="text" name="price" value="<?php echo $price; ?>" /></td>
      </tr>
Add following after the above code:

Code: Select all

      <tr>
        <td><?php echo $entry_minimum_qty; ?></td>
        <td><input type="text" name="minimum_qty" value="<?php echo $minimum_qty; ?>" /></td>
      </tr>
5.) admin\controller\catalog\product.php
Find:

Code: Select all

		if (isset($this->request->post['sku'])) {
      		$this->data['sku'] = $this->request->post['sku'];
    	} elseif (isset($product_info)) {
			$this->data['sku'] = $product_info['sku'];
		} else {
      		$this->data['sku'] = '';
    	}
Add following after the above code:

Code: Select all

		if (isset($this->request->post['minimum_qty'])) {
      		$this->data['minimum_qty'] = $this->request->post['minimum_qty'];
    	} elseif (isset($product_info)) {
      		$this->data['minimum_qty'] = $product_info['minimum_qty'];
    	} else {
			$this->data['minimum_qty'] = 1;
		}
++++++++++++++++
Find:

Code: Select all

$this->data['entry_priority'] = $this->language->get('entry_priority');
Add following after the above code:

Code: Select all

$this->data['entry_minimum_qty'] = $this->language->get('entry_minimum_qty');
6.) admin\language\english\catalog\product.php
Add:

Code: Select all

$_['entry_minimum_qty'] = 'Minimum Quantity:';
7.) admin\model\catalog\product.php
Find:

Code: Select all

public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', measurement_class_id = '" . (int)$data['measurement_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', date_added = NOW()");
Replace with:

Code: Select all

public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', minimum_qty = '" . (int)$data['minimum_qty'] . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', measurement_class_id = '" . (int)$data['measurement_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', date_added = NOW()");
++++++++++++++++++

Find:

Code: Select all

public function editProduct($product_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', measurement_class_id = '" . (int)$data['measurement_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
Replace with:

Code: Select all

public function editProduct($product_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', minimum_qty = '" . (int)$data['minimum_qty'] . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', measurement_class_id = '" . (int)$data['measurement_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");

Attachments

minimum.jpg

minimum.jpg (14.07 KiB) Viewed 1999 times


New member

Posts

Joined
Thu Sep 17, 2009 4:45 pm

Post by Qphoria » Wed May 19, 2010 9:34 pm

This is a good start. But the cart page is really where it matters. You can force 25 here, but on the cart page you can change it again.

I will add min order qty to 1.4.8 that has a check at the cart level, preventing you from changing it before checking out

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dramony » Thu May 20, 2010 5:15 pm

great! looking forward for 1.4.8

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm
Who is online

Users browsing this forum: No registered users and 1 guest