[TomatoCart] Show variants special products in specials page of glass gray template

In this article, I am going to show you how you can show variant special products in a ‘specials’ page within the Glass Gray template.

Snip20150322_8As you can see, the specials menu will display in the top menus. Your customer could find the special variants products after clicking the variants products button in the specials page.

Now, please apply following changes for your store:

Step 1. Backup all of store files for safety.

Step 2. Find templates > glass_gray > content > products > specials.php to replace all of content with:

<?php
/*
  $Id: specials.php $
  TomatoCart Open Source Shopping Cart Solutions
  http://www.tomatocart.com

  Copyright (c) 2009 Wuxi Elootec Technology Co., Ltd;  Copyright (c) 2007 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/
	
	$products_type = 'genearl';
	
	if (isset($_GET['specials']) && isset($_GET['v']) && $_GET['v'] == 1){
		$products_type = 'variants';
		$variants_result = osC_Specials::getVariantsSpecials();
		$variants_specials = $variants_result['products'];
		$Qspecials = $variants_result['listing'];
	}else {
		$products_type = 'general';
		$Qspecials = osC_Specials::getListing();
	}
?>

<h1><?php echo $osC_Template->getPageTitle(); ?></h1>

<div class="btn-group">
	<?php if ($products_type == 'general') { ?>
	<a class="btn btn-default" href="<?php echo osc_href_link(FILENAME_PRODUCTS, 'specials'); ?>"><?php echo $osC_Language->get('general_products'); ?></a>
	<a class="btn btn-black" href="<?php echo osc_href_link(FILENAME_PRODUCTS, 'specials&v=1'); ?>"><?php echo $osC_Language->get('variants_products'); ?></a>
	<?php }else { ?>
	<a class="btn btn-black" href="<?php echo osc_href_link(FILENAME_PRODUCTS, 'specials'); ?>">General products</a>
	<a class="btn btn-default" href="<?php echo osc_href_link(FILENAME_PRODUCTS, 'specials&v=1'); ?>">Variants Products</a>
	<?php }?>
</div>

<div class="moduleBox">
	<div class="content">
  <?php if ($products_type == 'general' && $Qspecials->numberOfRows() > 0) { ?>
      <?php
        $i = 0;
        while ($Qspecials->next()) {
          if(($i % 3 == 0) && ($i != 0))
            echo '<div style="clear:both"></div>';
      
            echo '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
                   '<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $Qspecials->value('products_name')) . '</span>' . 
                   osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $osC_Image->show($Qspecials->value('image'), $Qspecials->value('products_name')), 'id="img_ac_specials_'. $Qspecials->value('products_id') . '"') . 
                   '<span style="display:block; padding: 3px; text-align: center"><s>' . $osC_Currencies->displayPrice($Qspecials->value('products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($Qspecials->value('specials_new_products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</span>';
                   
                   if ($Qspecials->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                   	echo '<div class="qtyBlock"><input type="text" id="qty_' . $Qspecials->valueInt('products_id') . '" value="1" size="1" class="qtyField" /></div>';
                   }
                   
                   echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id') . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_specials_' . $Qspecials->value('products_id') . '"'));
            echo '</div>';
      
          $i++;
        }
      ?>
  <?php } ?>
  
  <?php 
  	if ($products_type == 'variants') {
				$count_variants_specials = count($variants_specials);
				
        if ($count_variants_specials > 0) {
        	for ($i=0; $i < $count_variants_specials; $i++) {
						$variants_special = $variants_specials[$i];
						
						if(($i % 3 == 0) && ($i != 0)) {
							echo '<div style="clear:both"></div>';
						}
						
						echo '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
								'<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $variants_special['products_id']), $variants_special['products_name']) . '</span>' .
								osc_link_object(osc_href_link(FILENAME_PRODUCTS, $variants_special['products_id']), $osC_Image->show($variants_special['image'], $variants_special['products_name']), 'id="img_ac_specials_'. $variants_special['products_id'] . '"') .
								'<span style="display:block; padding: 3px; text-align: center"><s>' . $osC_Currencies->displayPrice($variants_special['products_price'], $variants_special['products_tax_class_id']) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($variants_special['variants_specials_price'], $variants_special['products_tax_class_id']) . '</span>';
						 
						if ($variants_special['products_type'] == PRODUCT_TYPE_SIMPLE) {
							echo '<div class="qtyBlock"><input type="text" id="qty_' . $variants_special['products_id'] . '" value="1" size="1" class="qtyField" /></div>';
						}
						 
						echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $variants_special['products_id'] . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_specials_' . $variants_special['products_id'] . '"'));
						echo '</div>';
						
        	}
        }
		} 
	?>
		<div style="clear:both"></div>
	</div>
	
	<div class="listingPageLinks">
      <span style="float: right;"><?php echo $Qspecials->getBatchPageLinks('page', 'specials'); ?></span>
    
      <?php echo $Qspecials->getBatchTotalPages($osC_Language->get('result_set_number_of_products')); ?>
	</div>
</div>

Step 3. Find includes > classes > specials.php to add following method into it:

/**
     * Get the variants specials
     *
     * @access public
     * @return array
     */
    function getVariantsSpecials() {
      global $osC_Language, $osC_Database;
			
      $Qspecials = $osC_Database->query('select vs.*, pv.products_price, pv.products_images_id, p.products_id, p.products_type, pd.products_name, p.products_tax_class_id, i.image from :table_variants_specials vs inner join :table_products_variants pv on vs.products_variants_id = pv.products_variants_id inner join :table_original_products p on pv.products_id = p.products_id inner join :table_products_description pd on (p.products_id = pd.products_id and pd.language_id = :language_id) left join :table_products_images i on (pv.products_images_id = i.id)');
      $Qspecials->bindTable(':table_variants_specials', TABLE_VARIANTS_SPECIALS);
      $Qspecials->bindTable(':table_original_products', TABLE_PRODUCTS);
      $Qspecials->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
      $Qspecials->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
      $Qspecials->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
      $Qspecials->bindInt(':language_id', $osC_Language->getID());
      $Qspecials->setBatchLimit((isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1), MAX_DISPLAY_SPECIAL_PRODUCTS);
      $Qspecials->execute();
      
      $result = array('listing' => $Qspecials);
      if ($Qspecials->numberOfRows() > 0) {
        while($Qspecials->next()) {
          $special_product = array('specials_id' => $Qspecials->valueInt('variants_specials_id'),
                                   'products_id' => $Qspecials->valueInt('products_id'),
          												 'products_type' => $Qspecials->valueInt('products_type'),
          												 'image' =>  $Qspecials->value('image'),
          												 'products_tax_class_id' => $Qspecials->valueInt('products_tax_class_id'),
                                   'products_price' => $Qspecials->value('products_price'),
                                   'variants_specials_price' => $Qspecials->value('variants_specials_price'));
          
          //attach the group and value for the products name
          $special_product['products_name'] = $Qspecials->value('products_name');
          $Qvariants = $osC_Database->query('select pvg.products_variants_groups_name, pvv.products_variants_values_name from :table_products_variants_entries pve inner join :table_products_variants_groups pvg on (pve.products_variants_groups_id = pvg.products_variants_groups_id and pvg.language_id = :group_language_id) inner join :table_products_variants_values pvv on (pve.products_variants_values_id = pvv.products_variants_values_id and pvv.language_id = :value_language_id) where pve.products_variants_id = :products_variants_id');
          $Qvariants->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
          $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
          $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
          $Qvariants->bindInt(':group_language_id', $osC_Language->getID());
          $Qvariants->bindInt(':value_language_id', $osC_Language->getID());
          $Qvariants->bindInt(':products_variants_id',  $Qspecials->valueInt('products_variants_id'));
          $Qvariants->execute();
          
          if ($Qvariants->numberOfRows() > 0) {
            while($Qvariants->next()) {
              $special_product['products_name'] .= '(<strong>' . $Qvariants->value('products_variants_groups_name') . ':' . $Qvariants->value('products_variants_values_name') . '</strong>)';
            }
          }
          
          $result['products'][] = $special_product;
        }
      }
      
      return $result;
    }

Step 4. Find templates > glass_gray > all.min.css and stylesheet.css to add following code into it:

.btn {
  display: inline-block;
  margin-right: 2px;
  margin-bottom: 5px;
  font-weight: normal;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  background-image: none;
  border: 1px solid transparent;
  white-space: nowrap;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1.42857143;
  border-radius: 3px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.btn:focus,
.btn:active:focus,
.btn.active:focus {
  outline: thin dotted;
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
}
.btn:hover,
.btn:focus {
  text-decoration: none;
}
.btn:active,
.btn.active {
  outline: 0;
  background-image: none;
  -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
}
.btn.btn-black {
  color: #ffffff;
  background: #666666;
}
.btn.btn-default {
  background: #f9f9f9;
  color: #666666 !important;
  border: 1px solid #aaaaaa;
  cursor: default; 
}

Step 5. Find templates > glass_gray > index.php and then search following code snippet:

'<li ' . ($osC_Template->getGroup() == 'products' && $osC_Template->getModule() == 'new' ? 'class="navVisited"' : null) . '><span class="navLeftHook"> </span>' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, 'new'), $osC_Language->get('new_products')) . '<span class="navHoverDownHook"> </span><span class="navRightHook"> </span></li>';

Replace it with:

'<li ' . ($osC_Template->getGroup() == 'products' && $osC_Template->getModule() == 'new' ? 'class="navVisited"' : null) . '><span class="navLeftHook"> </span>' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, 'new'), $osC_Language->get('new_products')) . '<span class="navHoverDownHook"> </span><span class="navRightHook"> </span></li>' .
'<li ' . ($osC_Template->getGroup() == 'products' && $osC_Template->getModule() == 'specials' ? 'class="navVisited"' : null) . '><span class="navLeftHook"> </span>' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, 'specials'), $osC_Language->get('specials')) . '<span class="navHoverDownHook"> </span><span class="navRightHook"> </span></li>';

Step 6. Go to admin panel > Start menu > Definitions > Languages to add following language definitions into general group.

Snip20150322_10

Snip20150322_11Snip20150322_12

Step 7. Go to admin panel > start menu > Catalog > Specials to create variants specials.

Snip20150322_1Snip20150322_2Now, when your customer click the Specials menu in your store front, he will see following specials page:

Snip20150322_7Snip20150322_8Snip20150322_9

And thats it!

Looking for quality TomatoCart hosting? Check out Arvixe Web Solutions.

Tags: , , , , , | Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

6 Comments on [TomatoCart] Show variants special products in specials page of glass gray template

  1. sajad1441 says:

    Hi Jack
    Education is taking full
    Please complete file code set

  2. nazari says:

    Hi Jack
    Education for admin panel …!!!!???????

    • Alex says:

      Hello,
      To configure this in the admin area please see step 7 of the article.

      If you’re experiencing any issues, please feel free to elaborate on the issues you’re experiencing (if possible, any error messages) so we can investigate.
      -Alex.

  3. zand says:

    Hi Jack
    Education is not complete
    Please complete code for admin panel

    • Alex says:

      Hello,
      Once you have followed the article, you would need to visit: admin panel > start menu > Catalog > Specials to create variants specials.

      Are you having any issues accessing this page or adding specials/variants?
      -Alex.

  4. sajad1441 says:

    Hi Jack
    This training will help them to solve a problem that I need
    The first problem is that the products of a single type of product and other products are not added to cart added

    Please help me to solve this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *