Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add Specials to main page (index.php)


Dennisra

Recommended Posts

I would like to display the store specials on the center column of the  main page much like the new products are. Can anyone suggest a simply or the best add-on to accomplish this. I have looked but none of the add-ons seem to fit the bill. I may be missing something however.

Thank you for your help.

osCommerce Online Merchant v2.3.4 Responsive

PHP version: 5.6.31 (Zend: 2.6.0)

MySQL 5.6.37-log

Link to comment
Share on other sites

I found this. Tried for a couple hours but it does not work for me. Any tips that might help.

 

Posted September 2, 2014  by GLWalker
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.

 

Link to comment
Share on other sites

 @Dennisra   add this

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

after

<?php echo $oscTemplate->getContent('index'); ?>

and if you got error  like this 
 

1327 - Undeclared variable: MAX_DISPLAY_NEW_PRODUCTS

thats mean on the page you request, the variable MAX_DISPLAY_NEW_PRODUCTS is not defined. It should be present in the configuration table.

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
(9999, 'New Products Module', 'MAX_DISPLAY_NEW_PRODUCTS', '9', 'Maximum number of specials products to display in a category', 3, 5, NULL, '2017-09-30 07:18:08', NULL, NULL);

 

Screenshot from 2017-09-30 10-31-24.png

Edited by Omar_one

Get the latest Responsive osCommerce CE (community edition) here .

Link to comment
Share on other sites

You can't use 3 years old blog post exactly...codebase has changed so much since then...and the index page is now modular...so your specials thing needs to be a module.

Take the idea of that blog post, but not the code.

You need to make a module.  A module consists of (usually) three files;

the module itself
the modules template file
the modules language file

So, take the new products module as a base...and by trial and error learn some code from it. 

It's important that all shopowners know enough code to be dangerous...

/includes/modules/content/index/cm_i_new_products.php
/includes/modules/content/index/templates/new_products.php
/includes/languages/english/modules/content/index/cm_i_new_products.php

You need to copy each.  Rename each.  Open each, change each appropriately. 
Save, upload, install.  Forget.

Link to comment
Share on other sites

Excellent Omar_one. It works like a charm!!

One question: Should there be a file "specials.php in //includes/modules as I get this error on each category display page:

Warning: include(includes/modules/specials.php): failed to open stream: No such file or directory in /usr/local/www/index.php on line 214

Warning: include(): Failed opening 'includes/modules/specials.php' for inclusion (include_path='.:/usr/local/share/pear') in /usr/local/www/index.php on line 214

 

Thank you again!

Link to comment
Share on other sites

I just installed this (update) and it works great!!

I had to put the css code at the top of the file user.css to get it to work in Chrome but other than that no problem. Looks good in Firefox, IE and Chrome.

Nice addition. Thank you very much!!

Dennis

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...