Add Sold Out Button for the Out of Stock Products in TomatoCart’s Bootstrap Template

In this article, I will give you a solution to add sold out button for the out of stock products in bootstrap template. You will be satisfy with the following amazing changes in your bootstrap store.

Out of stock products in products listing page

soldout_listFigure 1. List style of product listing page

soldout_grid

Figure 2. Grid style of product listing page

Out of stock products in new products listing page

soldout_new_list

Out of stock products in specials products listing page

soldout_specials

Out of stock products in new products module

soldout_new_products_module

How to apply above changes for your store?

Step 1. Add a new configuration for your store.

– Go to your web host cpanel and find the phpmyadmin tool in it.

– Run the following sql in your phpmyadmin tool to add the new configuration for your store.

INSERT INTO toc_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Hide add to cart button for out of stock items', 'STOCK_HIDE_OUT_OF_STOCK', '0', 'When the product is out of stock, the add to cart button will not be shown in the store front.', '9', '7', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now());

Step 2. Add a sold out banner into your bootstrap template.

– Download the banner at https://www.dropbox.com/s/54qpltuuh3pjueg/soldout.png

— Put the banner into templates/bootstrap/images fold in your TomatoCart root directory.

Step 3. Adjust the product listing page.

— Go to templates/bootstrap/modules/products_listing.php.

— Find the following code:

 $buy_now_link = osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add');

— Replace it with:

 $sold_out = false;
                if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
                	if ($osC_Product->getQuantity() < 1) {
                		$sold_out = true;
                	}
                }

                $button_sold_out = '<button class="btn btn-small btn-inverse btn-sold-out" disabled="disabled"><i class="icon-shopping-cart icon-white "></i> ' . $osC_Language->get('button_sold_out') . '</button>';
                $buy_now_link = osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add');

— Find following code snippet:

<div class="left">
                    <?php 
                        echo $image_link;
                    ?> 
                    <h3>
                    	<?php echo osc_link_object($href, $Qlisting->value('products_name')); ?>
                    </h3>
                    <p class="description">
                        <?php echo strip_tags($osC_Product->getDescription()); ?>
                    </p>
                </div>

— Add following code before it:

<?php if ($sold_out): ?>
    <div class="soldout-banner"></div>
<?php endif;?>

— Find following code:

<?php 
                    	    if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
														//enable quantity input field
														if (defined('PRODUCT_LIST_QUANTITY_INPUT') && PRODUCT_LIST_QUANTITY_INPUT == 1) {
                    	?>
                    					<input type="text" id="qty_<?php echo $Qlisting->value('products_id'); ?>" value="1" size="1" class="qtyField" />
                    	<?php 
                    				}
                    	?>	
                        <a id="ac_productlisting_<?php echo $Qlisting->value('products_id'); ?>" class="btn btn-small btn-info ajaxAddToCart" href="<?php echo $buy_now_link; ?>">
                    	<?php 
                    	    } else {
                    	?>
                        <a class="btn btn-small btn-info" href="<?php echo $buy_now_link; ?>">
                    	<?php 
                    	    }
                    	?>
                        	<i class="icon-shopping-cart icon-white "></i> 
                        	<?php echo $osC_Language->get('button_buy_now'); ?>
                        </a><br />

— Replace it with:

<?php if ($sold_out === false): ?>
                    	<?php 
                    	    if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
								//enable quantity input field
								if (defined('PRODUCT_LIST_QUANTITY_INPUT') && PRODUCT_LIST_QUANTITY_INPUT == 1) {
                    	?>
									<input type="text" id="qty_<?php echo $Qlisting->value('products_id'); ?>" value="1" size="1" class="qtyField" />
                    	<?php 
								}
                    	?>	
						<a id="ac_productlisting_<?php echo $Qlisting->value('products_id'); ?>" class="btn btn-small btn-info ajaxAddToCart" href="<?php echo $buy_now_link; ?>">
                    	<?php 
                    	    } else {
                    	?>
                        <a class="btn btn-small btn-info" href="<?php echo $buy_now_link; ?>">
                    	<?php 
                    	    }
                    	?>
                        	<i class="icon-shopping-cart icon-white "></i> 
                        	<?php echo $osC_Language->get('button_buy_now'); ?>
                        </a><br />
                        <?php else: ?>
                        <?php echo $button_sold_out;?>
                        <?php endif;?>

Step 4. Override new products module.

— Go to templates/bootstrap/modules/content/new_products.php.

— Clear all of content of the file and copy following code into it:

<?php
/**
 * TomatoCart Open Source Shopping Cart Solution
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License v3 (2007)
 * as published by the Free Software Foundation.
 *
 * @package      TomatoCart
 * @author       TomatoCart Dev Team
 * @copyright    Copyright (c) 2009 - 2012, TomatoCart. All rights reserved.
 * @license      http://www.gnu.org/licenses/gpl.html
 * @link         http://tomatocart.com
 * @since        Version 1.1.8
 * @filesource
*/

    global $osC_Template, $osC_Language, $osC_Image;

    $osC_Language->load('products');

    require_once ('templates/' . $osC_Template->getCode() . '/models/products.php');

    $products = get_new_products();
?>

<?php 
    if (sizeof($products)) {
?>
    <!-- module new_products start //-->
    <div class="moduleBox module-new-products">
        <h6><?php echo $osC_Box->getTitle(); ?></h6>

        <ul class="products-list grid clearfix">
        <?php 
            foreach ($products as $product) {
                $osC_Product = new osC_Product($product['products_id']);

                $sold_out = false;
                if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
                	if ($osC_Product->getQuantity() < 1) {
                		$sold_out = true;
                	}
                }
        ?>
            <li class="clearfix">
            	<?php 
            		if ($sold_out == TRUE):
            	?>
            	<div class="soldout-banner"></div>
            	<?php 
            	    elseif ($product['is_specials'] === TRUE):
            	?>
            		<div class="specials-banner"></div>
            	<?php   
            	    elseif ($product['is_featured'] === TRUE):  
            	?>
            		<div class="featured-banner"></div>
            	<?php   
            	    endif;
            	?>
                <div class="left">
                    <?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $product['products_id']), $product['products_image'], 'id="img_ac_newproductsmodule_' . $product['products_id'] . '"'); ?> 
                    <h3><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $product['products_id']), $product['products_name']); ?></h3>
                    <p class="description"><?php echo strip_tags($osC_Product->getDescription()); ?></p>
                </div>
                <div class="right">
                    <span class="price"><?php echo $osC_Product->getPriceFormated(true); ?></span>
                    <div class="buttons hidden-phone">
                    	<?php if ($sold_out === false): ?>
                        <a id="ac_newproductsmodule_<?php echo $product['products_id']; ?>" class="btn btn-small btn-info ajaxAddToCart" href="<?php echo osc_href_link(FILENAME_PRODUCTS, $product['products_id'] . '&action=cart_add'); ?>">
                        	<i class="icon-shopping-cart icon-white "></i> 
                        	<?php echo $osC_Language->get('button_buy_now'); ?>
                        </a>
                        <?php else: ?>
                        <button class="btn btn-small btn-inverse btn-sold-out" disabled="disabled"><i class="icon-shopping-cart icon-white"></i> <?php echo $osC_Language->get('button_sold_out'); ?></button>
                        <?php endif; ?>
                        <br />
                        <?php echo osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $product['products_id'] . '&action=wishlist_add'), $osC_Language->get('add_to_wishlist'), 'class="wishlist"'); ?>
                        <?php
                          if ($osC_Template->isInstalled('compare_products', 'boxes')) {
                              echo  '<br />' . osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), osc_get_all_get_params() . '&cid=' . $product['products_id'] . '&' . '&action=compare_products_add'), $osC_Language->get('add_to_compare'), 'class="compare"');
                          }
                        ?>
                    </span>
                </div>
            </li>
        <?php 
            }
        ?>
        </ul>
    </div>

    <!-- module new_products end //-->
<?php 
    }
?>

That’s it. Please try it.

If you have any problem need to be solved, don’t hesitate to contact us via support@tomatocart.com. We provide free technical support service for Arvixe users. So, we strongly recommend you to buy Arvixe high performance virtual host to install TomatoCart store.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

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

Author Spotlight

Jack Yin

Jack Yin

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

Leave a Reply

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


6 − = 0

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>