Post by nowhinjing » Sat Dec 08, 2007 12:31 am

Hopefully this will be useful for somebody ....

DESCRIPTION :

This HOW TO contains a complete guide to adding the facility to implement MINIMUM ORDER QUANTITY per Product on your OpenCart Site.

Since my version of OpenCart has now moved considerably away from the standard, I have included all the changes to be made as text within this file. It means that you will need to do some manual editing rather than just copying in replacement files, but it will be easier for those of us with heavily customised setups.

Differences have been identified using WinMERGE, and the appropriate parts of the code have been cut from the working version and then pasted into this document. This hopefully means that the scope for mistakes has been much reduced (?)

If you have not yet discovered WinSCP - this may well be a good opportunity !

BACKUP:

Ensure that you make back-up copies of the files you are about to change, it is very easy to make mistakes while editing !
The files to backup are :
  \admin\controller\product.php
  \admin\language\english\controller\product.php
  \admin\template\default\content\product.tpl
  \catalog\controller\cart.php
  \catalog\controller\product.php
  \catalog\language\english\controller\cart.php
  \catalog\language\english\controller\product.php
  \catalog\template\default\content\cart.tpl
  \catalog\template\default\content\product.tpl
  \library\cart\cart.php


INSTALL:

1) Create a new column in your product table by running this SQL script

Code: Select all

  ALTER TABLE `product` ADD `min_order` int(4) NOT NULL default '1' AFTER `weight_class_id`;
2) Edit \admin\controller\product.php

In function insert() : change

Code: Select all

    if ( ( $request->isPost()) && ( $this->validateForm())) {
      $sql = "insert into product set quantity = '?', date_available = '?', model = '?', manufacturer_id = '?', image_id = '?', shipping = '?', price = '?', sort_order = '?', weight = '?', weight_class_id = '?', status = '?', tax_class_id = '?', date_added = now()";
      $database->query($database->parse($sql, $request->get('quantity', 'post'), date('Y-m-d', strtotime($request->get('date_available_year', 'post') . '/' . $request->get('date_available_month', 'post') . '/' . $request->get('date_available_day', 'post'))), $request->get('model', 'post'), $request->get('manufacturer_id', 'post'), $request->get('image_id', 'post'), $request->get('shipping', 'post'), $request->get('price', 'post'), $request->get('sort_order', 'post'), $request->get('weight', 'post'), $request->get('weight_class_id', 'post'), $request->get('status', 'post'), $request->get('tax_class_id', 'post')));
      $insert_id = $database->getLastId();
to

Code: Select all

    if ( ( $request->isPost()) && ( $this->validateForm())) {
      $sql = "insert into product set quantity = '?', date_available = '?', model = '?', manufacturer_id = '?', image_id = '?', shipping = '?', price = '?', sort_order = '?', weight = '?', weight_class_id = '?', status = '?', tax_class_id = '?', min_order = '?', date_added = now()";
      $database->query($database->parse($sql, $request->get('quantity', 'post'), date('Y-m-d', strtotime($request->get('date_available_year', 'post') . '/' . $request->get('date_available_month', 'post') . '/' . $request->get('date_available_day', 'post'))), $request->get('model', 'post'), $request->get('manufacturer_id', 'post'), $request->get('image_id', 'post'), $request->get('shipping', 'post'), $request->get('price', 'post'), $request->get('sort_order', 'post'), $request->get('weight', 'post'), $request->get('weight_class_id', 'post'), $request->get('status', 'post'), $request->get('tax_class_id', 'post'), $request->get('min_order', 'post')));
      $insert_id = $database->getLastId();
In function update() : change

Code: Select all

    if ( ( $request->isPost()) && ( $this->validateForm())) {
      $sql = "update product set quantity = '?', date_available = '?', model = '?', manufacturer_id = '?', image_id = '?', shipping = '?', price = '?', sort_order = '?', weight = '?', weight_class_id = '?', status = '?', tax_class_id = '?', date_modified = now() where product_id = '?'";
      $database->query($database->parse($sql, $request->get('quantity', 'post'), date('Y-m-d', strtotime($request->get('date_available_year', 'post') . '/' . $request->get('date_available_month', 'post') . '/' . $request->get('date_available_day', 'post'))), $request->get('model', 'post'), $request->get('manufacturer_id', 'post'), $request->get('image_id', 'post'), $request->get('shipping', 'post'), $request->get('price', 'post'), $request->get('sort_order', 'post'), $request->get('weight', 'post'), $request->get('weight_class_id', 'post'), $request->get('status', 'post'), $request->get('tax_class_id', 'post'), $request->get('product_id')));
      $database->query("delete from product_description where product_id = '" . ( int ) $request->get('product_id') . "'");
to

Code: Select all

    if ( ( $request->isPost()) && ( $this->validateForm())) {
      $sql = "update product set quantity = '?', date_available = '?', model = '?', manufacturer_id = '?', image_id = '?', shipping = '?', price = '?', sort_order = '?', weight = '?', weight_class_id = '?', status = '?', tax_class_id = '?', min_order = '?', date_modified = now() where product_id = '?'";
      $database->query($database->parse($sql, $request->get('quantity', 'post'), date('Y-m-d', strtotime($request->get('date_available_year', 'post') . '/' . $request->get('date_available_month', 'post') . '/' . $request->get('date_available_day', 'post'))), $request->get('model', 'post'), $request->get('manufacturer_id', 'post'), $request->get('image_id', 'post'), $request->get('shipping', 'post'), $request->get('price', 'post'), $request->get('sort_order', 'post'), $request->get('weight', 'post'), $request->get('weight_class_id', 'post'), $request->get('status', 'post'), $request->get('tax_class_id', 'post'), $request->get('min_order', 'post'), $request->get('product_id')));
      $database->query("delete from product_description where product_id = '" . ( int ) $request->get('product_id') . "'");
In function getForm() : INSERT

Code: Select all

  $view->set('entry_min_order', $language->get('entry_min_order'));
after

Code: Select all

  $view->set('entry_discount', $language->get('entry_discount'));
In function getForm() : INSERT

Code: Select all

    if ( $request->has('min_order', 'post')) {
      $view->set('min_order', $request->get('min_order', 'post'));
    }
    else {
      $view->set('min_order', @ $product_info['min_order']);
    }
after

Code: Select all

    if ( $request->has('sort_order', 'post')) {
      $view->set('sort_order', $request->get('sort_order', 'post'));
    }
    else {
      $view->set('sort_order', @ $product_info['sort_order']);
    }
3) Edit \admin\language\english\controller\product.php

INSERT

Code: Select all

  $_['entry_min_order']      = 'Minimum Order Quantity:';
after

Code: Select all

  $_['entry_weight']         = 'Weight:';
4) Edit \admin\template\default\content\product.tpl

INSERT

Code: Select all

           <tr>
              <td><?php echo $entry_min_order; ?></td>
              <td><input name="min_order" value="<?php echo $min_order; ?>" size="2" /></td>
           </tr>
after

Code: Select all

           <tr>
              <td><?php echo $entry_quantity; ?></td>
              <td><input name="quantity" value="<?php echo $quantity; ?>" size="2" /></td>
           </tr>
                               
5) Edit \catalog\controller\cart.php

In function index() : INSERT

Code: Select all

      $view->set('column_min_order', $language->get('column_min_order'));
after

Code: Select all

      $view->set('column_min_order', $language->get('column_min_order'));
INSERT

Code: Select all

      $min_error = '0';
after

Code: Select all

      $product_data = array( );
change

Code: Select all

        $product_data[] = array( 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $image->resize($result['image'], 50, 50), 'option' => $option_data, 'quantity' => $result['quantity'], 'stock' => $result['stock'], 'price' => $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $config->get('config_tax'))), 'discount' => ( $result['discount'] ? $currency->format($tax->calculate($result['price'] - $result['discount'], $result['tax_class_id'], $config->get('config_tax'))) : null ), 'total' => $currency->format($tax->calculate($result['total'], $result['tax_class_id'], $config->get('config_tax'))), 'href' => $url->href('product', false, array( 'product_id' => $result['product_id'] )));
to

Code: Select all

        $line_min_error = '0';
        if ($result['quantity'] < $result['min_order']) {
          $result['quantity'] = $result['min_order'];
          $min_error = '1';
          $line_min_error = '1';
        }
        $product_data[] = array( 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $image->resize($result['image'], 50, 50), 'option' => $option_data, 'quantity' => $result['quantity'], 'min_order' => $result['min_order'], 'min_error' => $line_min_error, 'stock' => $result['stock'], 'price' => $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $config->get('config_tax'))), 'discount' => ( $result['discount'] ? $currency->format($tax->calculate($result['price'] - $result['discount'], $result['tax_class_id'], $config->get('config_tax'))) : null ), 'total' => $currency->format($tax->calculate($result['total'], $result['tax_class_id'], $config->get('config_tax'))), 'href' => $url->href('product', false, array( 'product_id' => $result['product_id'] )));
        if ($min_error == '1') {
          $view->set('error', $language->get('error_min_order'));
        }
6) Edit \catalog\controller\product.php

In function index() : change

Code: Select all

      $cart->add($request->get('product_id', 'post'), '1', $request->get('option', 'post'));
to

Code: Select all

      $cart->add($request->get('product_id', 'post'), $request->get('quantity', 'post'), $request->get('option', 'post'));
INSERT

Code: Select all

      $view->set('text_min_order', $language->get('text_min_order'));
      $view->set('min_order', $product_info['min_order']);
after

Code: Select all

      $view->set('price', $currency->format($tax->calculate($product_info['price'], $product_info['tax_class_id'], $config->get('config_tax'))));
7) Edit \catalog\language\english\controller\cart.php

INSERT

Code: Select all

  $_['column_min_order'] = 'Min.';
after

Code: Select all

  $_['column_quantity']  = 'Quantity';
INSERT

Code: Select all

  $_['error_min_order']  = 'Products marked with ### have had their Quantity reset to the Minimum Order Quantity!';
after

Code: Select all

  $_['error_stock']      = 'Products marked with *** are not available in the desired quantity or not in stock!';
8.) Edit \catalog\language\english\controller\product.php

INSERT

Code: Select all

  $_['text_min_order'] = 'Minimum Order Quantity for this product is: ';
after

Code: Select all

  $_['text_error']     = 'Product not found!';
9) Edit \catalog\template\default\content\cart.tpl

INSERT

Code: Select all

  <th class="f"><?php echo $column_min_order; ?></th>
after

Code: Select all

  <th class="f"><?php echo $column_quantity; ?></th>
INSERT

Code: Select all

  <?php if ($product['min_error'] == '1') { ?>
    <span>###</span>
  <?php } ?>
after

Code: Select all

        <td class="j"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
INSERT

Code: Select all

        <td class="l"><?php echo $product['min_order']; ?></td>
after

Code: Select all

        <td class="l"><input type="text" name="quantity[<?php echo $product['key']; ?>]" value="<?php echo $product['quantity']; ?>" size="3" /></td>
10) Edit \catalog\template\default\content\product.tpl

INSERT

Code: Select all

  <?php if ($min_order > '1') { ?>
    <p><b><?php echo $text_min_order; ?><?php echo $min_order; ?></b></p>
  <?php } ?>
after

Code: Select all

    <?php echo $description; ?>
INSERT

Code: Select all

  <input type="hidden" name="quantity" value="<?php echo $min_order; ?>" />
after

Code: Select all

  <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
11) Edit \library\cart\cart.php

In function __construct
change

Code: Select all

        $this->products[$key] = array( 'key' => $key, 'product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'shipping' => $product['shipping'], 'image' => $product['filename'], 'option' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'stock' => ( $quantity <= $product['quantity'] ), 'price' => ( $product['price'] + $option_price ), 'discount' => $discount, 'total' => ( ( $product['price'] + $option_price ) - $discount ) * $quantity, 'tax_class_id' => $product['tax_class_id'], 'weight' => $product['weight'], 'weight_class_id' => $product['weight_class_id'] );
to

Code: Select all

        $this->products[$key] = array( 'key' => $key, 'product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'shipping' => $product['shipping'], 'image' => $product['filename'], 'option' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'min_order' => $product['min_order'], 'stock' => ( $quantity <= $product['quantity'] ), 'price' => ( $product['price'] + $option_price ), 'discount' => $discount, 'total' => ( ( $product['price'] + $option_price ) - $discount ) * $quantity, 'tax_class_id' => $product['tax_class_id'], 'weight' => $product['weight'], 'weight_class_id' => $product['weight_class_id'] );
In function add() : change

Code: Select all

  function add($product_id, $qty = '1', $options = array( )) {
to

Code: Select all

  function add($product_id, $qty, $options = array( )) {
In function add() : change

Code: Select all

      $this->data[$key] += $qty;
to

Code: Select all

      $this->data[$key] += 1;
Start up your OpenCart Admin session :

In Catalog -> Product
> Select the Product you wish to update
> Set the Minimum Order Quantity to the value you require
repeat as necessary.

and thats all there is to it !

and finally ...........

GOOD LUCK !
Last edited by Qphoria on Thu Oct 02, 2008 10:12 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Nov 15, 2007 10:35 pm

Post by jocroft » Fri May 02, 2008 2:42 am

Thanks for this, not what I wanted but it showed me where to change the 'products marked with ***' is!!

I know you think you understood what I said, but what you heard was not what I meant


New member

Posts

Joined
Thu Mar 13, 2008 9:03 pm
Location - England

Post by mmcmsp » Tue Aug 12, 2008 3:25 pm

Just did it. When I went to admin I got the message bellow. Please help me!!! lol

library/cart/cart.php on line 211

And when I went to the store...

Warning: Cannot modify header information - headers already sent by (output started at /home/brindesa/public_html/brindes/catalog/language/english/english.php:106) in /home/brindesa/public_html/brindes/library/cart/currency.php on line 43

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/brindesa/public_html/brindes/library/cart/cart.php on line 211

Newbie

Posts

Joined
Sun Apr 20, 2008 1:11 pm

Post by Qphoria » Tue Aug 12, 2008 11:20 pm

First error usually happens if there are extra spaces at the end of the file you just modified
Second error means you have an error in your code. Like a missing ; or something.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by kellen » Fri Aug 15, 2008 7:48 am

What about a generic store-wide minimum order setting?

Newbie

Posts

Joined
Wed Aug 13, 2008 8:28 am

Post by mmcmsp » Tue Aug 19, 2008 1:07 pm

I've done it all again from a backup I had and I still have problems:

unexpected T_STRING in index.php?controller=product&product_id=5
unexpected T_ELSE in catalog/controller/cart.php


At Admin:

Notice: Use of undefined constant php - assumed 'php' in /admin/language/english/controller/product.php on line 1
Notice: Use of undefined constant php - assumed 'php' in /admin/language/english/controller/product.php on line 1

Fatal error: Call to undefined function set() in /admin/controller/product.php on line 1

Newbie

Posts

Joined
Sun Apr 20, 2008 1:11 pm

Post by bruce » Tue Aug 19, 2008 4:37 pm

All symptoms point to corruption in the language file you mentioned.

It should begin at the top with

Code: Select all

<?php
// Heading
$_['heading_title']        = 'Products';
$_['heading_description']  = 'You can edit your products here.';
chances are the first characters in the file are not <? as they should be

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Qphoria » Wed Sep 10, 2008 7:56 am

I've gone ahead and packaged this contrib as a zip file and uploaded it to the contribs area. All credit was given to nowhinjing for the original code.

DOWNLOAD

-EDIT-
Seems I've inadvertently included my Total Cart Weight contrib as well. So now when you view the cart, it tells you the total cart weight. Bonus :)
Last edited by Qphoria on Wed Sep 10, 2008 8:07 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Sep 17, 2008 2:43 am

Found a big bug in the code. If the customer changes the qty to be less than the min order qty on the cart page, they see the message that says "products marked with ### were auto-updated to the min order qty". But it only updates the display. If the customer doesn't click "update" and just clicks "Checkout" it will leave the changed qty in his cart.

I have a work around that checks the value at the cart post level, but then it breaks that nice little message since it forces a cart->update.  I will look into a proper fix.
Last edited by Qphoria on Wed Sep 17, 2008 11:06 pm, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Sep 24, 2008 8:37 am

Fixed and uploaded:
DOWNLOAD

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Fri Oct 10, 2008 12:45 am

UPDATE v0.4

- Updated to work with the new Option Weight & Stock v0.6 contrib.
- Fixed the sql error on cart page (it was left over code from the another contrib)

Download
Last edited by Qphoria on Sat Oct 11, 2008 2:03 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Sat Oct 11, 2008 2:02 am

UPDATE v0.5

- Fixed: Added the proper bug fix for getWeight() which fixes the comma problem and allows use of zone based shipping. Also changed the Total Cart Display weight to use a new method that doesn't rely on getting the unit back from getWeight.

Download

NOTE:THIS WILL BE THE LAST VERSION FOR OPENCART 0.7.8!

THERE WILL BE NO MORE VERSIONS OF THIS CONTRIB AS IT IS NOW PART OF THE CORE CODE.
PLEASE MAKE ANY FUNCTIONAL REQUESTS IN FUTURE VERSIONS DIRECTLY ON THE BUG TRACKER SITE. THANKS!

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 1 guest