Jump to content
Sign in to follow this  
GLWalker

Specials Module for osC Bootstrap build

Recommended Posts

Here's a super easy special module that follows the same layout as the new products module.  Im going to post the code here and let you put it together!

 

It is so similar to the new products module, some may swear I just copied it and just changes 3 things! Maybe I did, maybe I didn't, maybe I used copy and paste, maybe I typed it all out. You will NEVER know.

 

Step 1)

Navigate to your catalog/includes/modules/ directory. Create a new .php file and name it specials.php

 

Step 2) Open the new file and paste this inside:

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $special_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, products_price, if(s.status, s.specials_new_products_price, p.products_price) as products_special_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
  } else {
    $special_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, products_price, if(s.status, s.specials_new_products_price, p.products_price) as products_special_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
  }

  $num_special_products = tep_db_num_rows($special_products_query);

  if ($num_special_products > 0) {

    $special_prods_content = NULL;

    while ($special_products = tep_db_fetch_array($special_products_query)) {
      $special_prods_content .= '<div class="col-sm-6 col-md-4">';
      $special_prods_content .= '  <div class="thumbnail">';
      $special_prods_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $special_products['products_image'], $special_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
      $special_prods_content .= '    <div class="caption">';
      $special_prods_content .= '      <p class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_products['products_id']) . '">' . $special_products['products_name'] . '</a></p>';
      $special_prods_content .= '      <hr>';
      $special_prods_content .= '      <p class="text-center text-danger"><del class="text-muted">' . $currencies->display_price($special_products['products_price'], tep_get_tax_rate($special_products['products_tax_class_id'])) . '</del><br>' . $currencies->display_price($special_products['products_special_price'], tep_get_tax_rate($special_products['products_tax_class_id'])) . '</p>';
      $special_prods_content .= '      <div class="text-center">';
      $special_prods_content .= '        <div class="btn-group">';
      $special_prods_content .= '          <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'products_id=' . $special_products['products_id']) . '" class="btn btn-default" role="button">' . SMALL_IMAGE_BUTTON_VIEW . '</a>';
      $special_prods_content .= '          <a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $special_products['products_id']) . '" class="btn btn-success" role="button">' . SMALL_IMAGE_BUTTON_BUY . '</a>';
      $special_prods_content .= '        </div>';
      $special_prods_content .= '      </div>';
      $special_prods_content .= '    </div>';
      $special_prods_content .= '  </div>';
      $special_prods_content .= '</div>';
    }
?>

  <h3><?php echo sprintf(TABLE_HEADING_SPECIAL_PRODUCTS, strftime('%B')); ?></h3>

  <div class="row">
    <?php echo $special_prods_content; ?>
  </div>

<?php
  }
?>

Step 3)

Open catalog/index.php

Find in 2 areas:

<?php include(DIR_WS_MODULES . FILENAME_NEW_PRODUCTS); ?>

Depending what order you want to show the specials paste this in before or after the above:

<?php include(DIR_WS_MODULES . 'specials.php'); ?>

Step 4)

Open catalog/includes/languages/* / index.php

 

Add this line where ever you feel like:

define('TABLE_HEADING_SPECIAL_PRODUCTS', '%s Specials!');

Done!

 

Usage:

If you want to limit the products that show, inside includes/modules/specials.php change MAX_DISPLAY_NEW_PRODUCTS  to any number desired.

 

 


Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×