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:';
Find:
Code: Select all
$this->data['text_wait'] = $this->language->get('text_wait');
Code: Select all
$this->data['text_minimum_qty'] = $this->language->get('text_minimum_qty');
Find:
Code: Select all
$this->data['model'] = $product_info['model'];
Code: Select all
$this->data['minimum_qty'] = $product_info['minimum_qty'];
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>
Code: Select all
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;">
<b><?php echo $text_minimum_qty; ?></b>
<?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">
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>
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>
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>
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>
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'] = '';
}
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');
Code: Select all
$this->data['entry_minimum_qty'] = $this->language->get('entry_minimum_qty');
Add:
Code: Select all
$_['entry_minimum_qty'] = 'Minimum Quantity:';
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()");
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 . "'");
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 . "'");