Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Minimum Product Quantity with Admin v1.5
- # A little history on this contrib:
- - it is based heavily on "Min Order Quantity" By Dave Latham
- (http://www.oscommerce.com/community/contributions,2198)
- - improvement by Mark Rickert
- mjar81[a]gmail.com
- http://www.markrickert.net
- Contribution located at: http://www.oscommerce.com/community/contributions,2953
- This contrib improves on Dave Latham's version by allowing you to specify a minimum value for each product.
- There is an admin interface where you can turn on or off the features of this contrib.
- Product minimums are displayed on the product_info page right under the model number.
- - improvement by many contributors,
- like Gidgidonihah who released the version 1.4
- - (version 1.5) improvement by Piero Trono (tropic)
- (contact: http://php-multishop.com/contact.htm)
- In the version 1.5 I added the capability to specify the order in which to display the
- "MQP column" in the products listing page (index.php file).
- # Changes:
- 1.5
- the changes of this version are the steps 12-19
- ...
- 1.2
- Changed - minorder is not stored in the "products" table since there was virtually no need
- to have a different product minimum for each language... if you want this feature,
- use ver. 1.1.
- 1.1
- Added - Ability to manage each individual product's minimum level via admin catalog feature.
- Added - Country/Language specific data is retained when using admin interface.
- Added - Comments to differentiate my code from original code.
- # INSTALLATION
- ________________________________________________________________________________________________
- STEP 1:
- _____________________________________________________________________________________________________
- In ./catalog/shopping_cart.php around line 144
- after this:
- while (list($option, $value) = each($products[$i]['attributes'])) {
- $products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
- }
- }
- $products_name .= '</td>' .
- '</tr>' .
- '</table>';
- insert this:
- //Minimum quantity code
- if(MINIMUM_ORDERS == 'true'){
- $min_order_query = tep_db_query("select p.minorder as min_quant FROM " . TABLE_PRODUCTS . " p where p.products_id = '".$products[$i]['id']."'");
- while ($min_order = tep_db_fetch_array($min_order_query)) {
- if ($products[$i]['quantity'] < $min_order['min_quant'] ) {
- $products[$i]['min_quant']=$min_order['min_quant'];
- }
- }
- if ($products[$i]['quantity'] < $products[$i]['min_quant'] ) {
- $products[$i]['quantity']=$products[$i]['min_quant'];
- $cart->add_cart($products[$i]['id'],$products[$i]['quantity'],$products[$i]['attributes']);
- $cart_notice = sprintf(MINIMUM_ORDER_NOTICE, $products[$i]["name"], $products[$i]["min_quant"]);
- }
- }
- //End Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 2:
- _____________________________________________________________________________________________________
- In ./catalog/shopping_cart.php around line 174
- after this:
- <td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
- </tr>
- <?php
- }
- }
- insert this:
- //Minimum quantity code
- if ($cart_notice) {
- ?>
- <tr>
- <td class="stockWarning" align="center"><br><?php echo $cart_notice; ?></td>
- </tr>
- <?php
- }
- //End Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 3:
- _____________________________________________________________________________________________________
- in product_info.php
- find:
- $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
- add:
- p.minorder to the field list
- or just replace with this:
- //Minimum quantity code
- $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id, p.minorder from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
- _____________________________________________________________________________________________________
- STEP 4:
- _____________________________________________________________________________________________________
- in product_info.php
- find:
- if (tep_not_null($product_info['products_model'])) {
- $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
- } else {
- $products_name = $product_info['products_name'];
- }
- and insert after it:
- //Minimum quantity code
- if (tep_not_null($product_info['minorder']) && MINIMUM_ORDERS == 'true') {
- $products_name .= '<br><span class="smallText">Minimum order: ' . $product_info['minorder'] . '</span>';
- }
- //End: Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 5:
- _____________________________________________________________________________________________________
- Run this SQL query on your database:
- INSERT INTO `configuration` (`configuration_id` , `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function`)
- VALUES ('', 'Minimum Orders', 'MINIMUM_ORDERS', 'true', 'Whether or not to enforce minimum orders', '1', '19', NOW( ) , NOW( ) , NULL , NULL);
- _____________________________________________________________________________________________________
- STEP 6:
- _____________________________________________________________________________________________________
- Run this SQL query to modify your "products description" table:
- ALTER TABLE `products` ADD `minorder` INT( 4 ) DEFAULT '1' NOT NULL ;
- _____________________________________________________________________________________________________
- STEP 7:
- _____________________________________________________________________________________________________
- Populate the minorder field in your products_description table.
- *note* that the table automatically sets all minorder's to one (1).
- Or continue to be able to do it via Admin interface.
- _____________________________________________________________________________________________________
- STEP 8:
- _____________________________________________________________________________________________________
- You can turn this feature on and off in the admin panel under Configuration:My Store:Minimum Orders
- *****************************************************************************************************
- If you want, you can stop here, but continue if you want to be able to change the values via the
- admin page.
- *****************************************************************************************************
- _____________________________________________________________________________________________________
- STEP 9: Define languages for admin web interface
- _____________________________________________________________________________________________________
- insert into all language files ./admin/includes/languages/$language/categories.php
- //Minimum quantity code
- define('TEXT_PRODUCTS_MINIMUM','Minimum per order:');
- //End: Minimum quantity code
- (or correct translation)
- (use babelfish.altavista.com)
- _____________________________________________________________________________________________________
- STEP 10: (this part is pretty intense... follow c.a.r.e.f.u.l.l.y.)
- _____________________________________________________________________________________________________
- in ./admin/categories.php
- Find: (around line 220)
- 'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));
- and insert BEFORE it:
- 'minorder' => tep_db_prepare_input($HTTP_POST_VARS['minorder']),
- Find: (about line 375)
- 'manufacturers_id' => '');
- Insert BEFORE it:
- //Minimum quantity code
- 'minorder' => '',
- //End: Minimum quantity code
- Find: (about line 381)
- $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
- REPLACE WITH:
- //Minimum quantity code
- $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id, p.minorder from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
- //End Minimum quantity code
- Find: (about line 587)
- <tr>
- <td class="main"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
- <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_quantity', $pInfo->products_quantity); ?></td>
- </tr>
- Insert AFTER it:
- <tr>
- <td class="main"><?php echo TEXT_PRODUCTS_MINIMUM; ?></td>
- <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('minorder', $pInfo->minorder); ?></td>
- </tr>
- Find: (about line 612)
- $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
- REPLACE WITH:
- //Minimum quantity code
- $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id, p.minorder from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
- //End: Minimum quantity code
- Find: (about line 818)
- $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p2c.categories_id, from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by pd.products_name");
- REPLACE WITH:
- //Minimum quantity code
- $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p2c.categories_id, p.minorder from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by pd.products_name");
- //End: Minimum quantity code
- Find: (about line 820)
- $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by pd.products_name");
- REPLACE WITH:
- //Minimum quantity code
- $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.minorder from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by pd.products_name");
- //End Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 11:
- _____________________________________________________________________________________________________
- In includes/languages/english/shopping_cart.php before the ?> add
- define('MINIMUM_ORDER_NOTICE', "Minimum order amount for %s is %d. Your cart has been updated to reflect this.");
- _____________________________________________________________________________________________________
- STEP 12 (v.1.5):
- _____________________________________________________________________________________________________
- Run this SQL query on your database:
- INSERT INTO `configuration` (`configuration_id` , `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function`)
- VALUES ('', 'Minimum Product Quantity', 'PRODUCT_LIST_MINORDER', '6', 'Do you want to display the Minimum Product Quantity?', '8', '11', NOW( ) , NOW( ) , NULL , NULL);
- _____________________________________________________________________________________________________
- STEP 13:
- _____________________________________________________________________________________________________
- In ./catalog/index.php around line 133
- after this:
- 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
- add this:
- //Minimum quantity code
- 'PRODUCT_LIST_MINORDER' => PRODUCT_LIST_MINORDER,
- //End: Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 14:
- _____________________________________________________________________________________________________
- In ./catalog/index.php around line 164
- after this:
- case 'PRODUCT_LIST_QUANTITY':
- $select_column_list .= 'p.products_quantity, ';
- break;
- add this:
- //Minimum quantity code
- case 'PRODUCT_LIST_MINORDER':
- $select_column_list .= 'p.minorder, ';
- break;
- //End: Minimum quantity code
- _____________________________________________________________________________________________
- STEP 15:
- _____________________________________________________________________________________________________
- In ./catalog/index.php around line 223
- after this:
- case 'PRODUCT_LIST_QUANTITY':
- $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
- break;
- add this:
- //Minimum quantity code
- case 'PRODUCT_LIST_MINORDER':
- $listing_sql .= "p.minorder " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
- break;
- //End: Minimum quantity code
- ________________________________________________________________________________
- STEP 16:
- _____________________________________________________________________________________________________
- In ./catalog/includes/modules/product_listing.php around line 50
- after this:
- case 'PRODUCT_LIST_QUANTITY':
- $lc_text = TABLE_HEADING_QUANTITY;
- $lc_align = 'right';
- break;
- add this:
- //Minimum quantity code
- case 'PRODUCT_LIST_MINORDER':
- $lc_text = TABLE_HEADING_MINORDER;
- $lc_align = 'right';
- break;
- //End Minimum quantity code
- ________________________________________________________________________________
- STEP 17:
- _____________________________________________________________________________________________________
- In ./catalog/includes/modules/product_listing.php around line 125
- after this:
- case 'PRODUCT_LIST_QUANTITY':
- $lc_align = 'right';
- $lc_text = ' ' . $listing['products_quantity'] . ' ';
- break;
- add this:
- //Minimum quantity code
- case 'PRODUCT_LIST_MINORDER':
- $lc_align = 'right';
- $lc_text = ' ' . $listing['minorder'] . ' ';
- break;
- //End Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 18:
- _____________________________________________________________________________________________________
- In ./catalog/includes/languages/$language/index.php
- before the ?> add
- //Minimum quantity code
- define('TABLE_HEADING_MINORDER', 'Minimum order q.ty');
- //End Minimum quantity code
- _____________________________________________________________________________________________________
- STEP 19:
- _____________________________________________________________________________________________________
- You can turn On/Off or change the order in which to display the MPQ column in the index.php file,
- through the admin panel under the path:
- Configuration: Product Listing: Minimum Product Quantity
- The values allowed are:
- 0: hide the MPQ column
- x: display the column in the x position
- _____________________________________________________________________________________________________
- THAT'S IT!
- _____________________________________________________________________________________________________
- We hope you like it!
- Thanks for all the great support of this community and this awesome program!
- Thanks to all the previous (an future) contributors,
- Piero Trono
- (http://php-multishop.com)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement