Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[CONTRIBUTION] Disable "Add to cart" button if stock 0 or price 0 and display Out Stock


nicko107

Recommended Posts

Hello

 

 

I upload this contribution that doing this:

 

FEATURES:

---------

 

1.- This contribution disable the button "Add to cart" or "Buy Now", for a product everywhere in the catalog,

 

when the stock of that product is 0, or the price of that product is 0,

 

and replace it by a button (without link) with the text: "Out Stock". (this contribution is multilanguage)

 

2.- Add the "Add to cart" / "Buy Now!" button for all places of catalog where appear a product but not have a Buy Now button: Module New products on month..., Whats new, Specials (column right) Specials (page with all specials)

 

and instructions to applied this modification to disable button Buy Now when quantity of this product are 0 or price are 0

 

 

DEMO:

-----

http://www.oscommerce-demo.com/demo01/

 

 

 

This contribution is based in "Display Out Of Stock Button" contribution created by Jean Gionet,

 

Added some corrections and multilanguage buttons, and intructions for applied for other files.

In this contribution add new feature that display the "Out Stock" button when price is 0.

Correct path of image buttons file

Added image buttons in english, spanish, german.

 

 

 

Change & Files affected by this modification:

--------------------------------------------

 

3/6 new buttons to upload

 

product_info.php <-- information page of product:

Disable the button when stock = 0 or price = 0.

And Display behind the product name: "In Stock" or "Out Stock" if that product havent stock.

Include instructions to add the contribution "Stock Display (Images or Text)"

http://www.oscommerce.com/community/contributions,968

with some modification for multilingual buttons.

This add 3 possibility: In Stock, limitate stock (can define a low stock) and Out of Stock.

include only for this file.

 

catalog/includes/modules/product_listing.php <-- list categories, subcategories, manuafacturers, search results

product_reviews.php <-- list reviews

product_reviews_info.php <-- review of product

product_reviews_write.php <-- write reviews page

catalog/product_new.php <-- List of New products (page)

 

 

 

The next files/pages no display "Add to cart" button,

this contribution include instructions to add a

"Add to cart" button to this files:

---------------------------------------------------

catalog/specials.php <-- List of Specials products (page)

catalog/includes/modules/new_products.php <-- Module "New products in month ...

catalog/includes/boxes/whats_new.php <-- Box in column left with one new product

catalog/includes/boxes/specials.php <-- Box in column right with one special

 

 

 

Include folder with files with modifications to upload to stores without modifications in files.

 

Include screenshots with examples.

Link to comment
Share on other sites

Download at:

 

http://www.oscommerce.com/community/contributions,4549

 

 

SCREENSHOTS:

------------------

 

For products with Stock = 0, or price = 0

disable the Add to cart button and display "x Out Stock" button without link, and behind product name display Out Stock:

 

 

productinfooutstocklo5.png

 

For product listing:

 

productlistingoutstockhw4.png

 

 

For review products:

 

reviewinfooutstocklp4.png

 

For new products page:

 

productsnewlistoutstockea2.png

 

 

 

And now Module of New Products on month... display the Buy Now! button:

 

newproductsmonthoutstockbn2.png

 

and the page of specials products:

 

specialpageoutstockfo3.png

 

 

and similar for the Whats New box for the column left

and Special box of column right

Link to comment
Share on other sites

Hello

 

I uploaded a version for stores thats installed the contribution:

 

"Individual boxes for products in central modules"

 

the "version for contributions individual boxes v1.1

 

 

 

This version include instructions to applied this contribution Disable Add to cart button is stock = 0 or price = 0 for products of modules:

 

New Products on month.. with individual boxes v1.1 installed

 

and

 

Specials products page with individual boxes v1.1 installed

Include files with modifications installed and screenshots

 

 

 

DEMO with both contributions:

  • individual boxes v1.1
  • Disablle Add to cart if stock = 0 or price = 0

http://www.oscommerce-demo.com/demo01/

 

The rest of file use instructions of first version of Disable Add to ...... contribution

Link to comment
Share on other sites

  • 2 months later...

Hi, nice contri!!! Keep up the good work

 

Is it possible that there's a bug in it?

 

Because in the product_listing, the button: "out of stock" is always showing up, even when a product is on stock.

 

The product_info works o.k products_new etc. are all working o.k.

 

Someone had the same problem?

 

Thnxz

Link to comment
Share on other sites

  • 2 weeks later...

same here ------ ???

 

And it doesn't seem to work on other pages as well

I keep som products online even if they are sold. If both the price and the stock =0 - then there's no problem. But if the stock is 0 and there's still a price - it shows ????

I'm not sure that's the idea??

 

I tried to make these changes to products_new.php

 

If (($products_new['products_quantity']<>0) and ($products_new['products_price']>0) or ($products_new['products_quantity']<0))

 

And it worked - but I can't get product_listing.php to work ??

 

I wonder where Nicko 107 is?

Or maybe others have solved this? Please, if you have, let us know

 

Helle :-)

Link to comment
Share on other sites

I've just tried this on the new products module... and it doesn't work at all. I get no changes at all , even if i set price to 0 and qty to 0

 

I made the changes in catalog/includes/modules/new_products.php

 

 

The item still shows a buy now now button. I have "Individual boxes for products in central modules" installed.

 

 

Nick ??? any help would be appreciated. I see it working on your test site so it must be possible

Link to comment
Share on other sites

Hi

 

yes , the product listing is working for me ok. but i can't work out the code for the front page modules. i know nicko has it working on his demo page , so i'm hoping he can post a section of the code here. the install instructions don't include the front page modules.

 

this probably won't help you HelleM, but in case it does , here is the code from my product_listing.php

 

I know nico does answer questions here on his contribs, he's very helpful.

 

<?php
 }

 $list_box_contents = array();

 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
  case 'PRODUCT_LIST_MODEL':
	$lc_text = TABLE_HEADING_MODEL;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_NAME':
	$lc_text = TABLE_HEADING_PRODUCTS;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_MANUFACTURER':
	$lc_text = TABLE_HEADING_MANUFACTURER;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_PRICE':
	$lc_text = TABLE_HEADING_PRICE;
	$lc_align = 'center';
	break;
  case 'PRODUCT_LIST_QUANTITY':
	// $lc_text = TABLE_HEADING_QUANTITY;  //this change hides the quantity heading title 
	$lc_text = ''; //this change hides the quantity heading title 
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_WEIGHT':
	$lc_text = TABLE_HEADING_WEIGHT;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_IMAGE':
	$lc_text = TABLE_HEADING_IMAGE;
	$lc_align = 'center';
	break;
  case 'PRODUCT_LIST_BUY_NOW':
	$lc_text = TABLE_HEADING_BUY_NOW;
	$lc_align = 'center';
	break;
}

if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
  $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
}

$list_box_contents[0][] = array('align' => $lc_align,
								'params' => 'class="productListing-heading"',
								'text' => ' ' . $lc_text . ' ');
 }

 if ($listing_split->number_of_rows > 0) {
$rows = 0;
$listing_query = tep_db_query($listing_split->sql_query);
while ($listing = tep_db_fetch_array($listing_query)) {
  $rows++;

  if (($rows/2) == floor($rows/2)) {
	$list_box_contents[] = array('params' => 'class="productListing-even"');
  } else {
	$list_box_contents[] = array('params' => 'class="productListing-odd"');
  }

  $cur_row = sizeof($list_box_contents) - 1;
  $has_description = false;

  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
	$lc_align = '';

	switch ($column_list[$col]) {
	  case 'PRODUCT_LIST_MODEL':
		$lc_align = '';
		$lc_text = ' ' . $listing['products_model'] . ' ';
		break;
	  case 'PRODUCT_LIST_NAME':
		$lc_align = '';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
		} else {
		  $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';
		}
		if (PRODUCT_LIST_DESCRIPTION && $listing['products_description'] && PRODUCT_LIST_DESCRIPTION_MAX_LENGTH)
		$lc_text .= '<br><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="productDesc">' . tep_flatten_product_description($listing['products_description'],  ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id']) . '">' . TEXT_MORE . '</a>') . '</td></tr></table>';
		break;
	  case 'PRODUCT_LIST_MANUFACTURER':
		$lc_align = '';
		$lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
		break;
	  case 'PRODUCT_LIST_PRICE':
		$lc_align = 'center';
		if (tep_not_null($listing['specials_new_products_price'])) {
		  $lc_text = ' <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
		} else {
		  $lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
		}
		break;
	  case 'PRODUCT_LIST_QUANTITY':
		$lc_align = 'right';
		// $lc_text = ' ' . $listing['products_quantity'] . ' '; // this hides stock quantity of product 
		$lc_text = ' '; // this hides stock quantity of product 
		break;
	  case 'PRODUCT_LIST_WEIGHT':
		$lc_align = 'right';
		$lc_text = ' ' . $listing['products_weight'] . ' ';
		break;
	  case 'PRODUCT_LIST_IMAGE':
		$lc_align = 'center';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
		} else {
		  $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> ';
		}
		break;
	  case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';
		If (($listing['products_quantity']<>0) and ($listing['products_price'] > 0)){
	   $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
		}else{	
	   $lc_text = tep_image_button('out_stock.gif', IMAGE_BUTTON_OUT_STOCK) . ' ';
	   }
		break;
	}

	$list_box_contents[$cur_row][] = array('align' => $lc_align,
										   'params' => 'class="productListing-data"',
										   'text'  => $lc_text);
  }
}

new productListingBox($list_box_contents);
 } else {
$list_box_contents = array();

$list_box_contents[0] = array('params' => 'class="productListing-odd"');
$list_box_contents[0][] = array('params' => 'class="productListing-data"',
							   'text' => TEXT_NO_PRODUCTS);

new productListingBox($list_box_contents);
 }

 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>

 

 

my only problem with product_listing is my "all products" page shows everything as out of stock , but i will look at that today

Link to comment
Share on other sites

hi again

Nope your code doesn't work. if I have 0 on stock - but there's a price - the product still has the "Put in Cart" button...

 

If I change the code from

If (($listing['products_quantity']<>0) and ($listing['products_price'] > 0))

 

to

 

If (($listing['products_quantity']<>0) OR ($listing['products_price'] > 0))

 

the button will be hidden if the price is et to 0 - but not the quantity is 0?

 

Helle :-)

Link to comment
Share on other sites

Did you change your admin settings correcty as below ?

 

"Set "Display Product Quantity" to a number different to 0

 

this display the quantity in stock of each product in product listing

and are needed for work the conditional.

 

Example: set to 4, and then change the 4 of "Display Buy Now column" to 5.

 

Admin >> Configuration >> Stock:

 

Set "Check stock level" to TRUE

Set "Allow checkout" to FALSE

 

 

and you made this change -

 

OPEN file:

catalog/includes/modules/product_listing.php

FIND:

$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';

Comment out or REPLACE with:

If (($listing['products_quantity']<>0) and ($listing['products_price'] > 0)){
$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
}else{	
$lc_text = tep_image_button('out_stock.gif', IMAGE_BUTTON_OUT_STOCK) . ' ';
}

 

 

 

 

What is the name of your "buy now buttons" ? is it button_buy_now.gif ? as listed in the code above ?

Link to comment
Share on other sites

Perfect - it works like a charm... and yes my button name is "button_buy_now.gif"

 

I can't get Star product and Featured to work either....

I set Featured not to show the "Buy now" button!

 

The "Control New Products module for 2.2-MS2" works fine for me though...

 

Helle :-)

Link to comment
Share on other sites

I need the code for thes front page modules also -

 

Star product

 

Featured (front page)

 

Specials on default

 

 

yes, i thought that removing the buy now buton would be a temp fix for now , otherwise i'll just end up baby sitting the all the front page products.

 

Nico has the front page out of stock buttons working on his demo page. I've tried loads of different code to try and get it working , but no joy.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
well that was easy . My all products page is now working. i just needed to add the "p.products_quantity" to the code.

 

another one down...3 to go :D

 

 

Hi Andy,

 

 

Where did you add this code?? To products_listing.php???

 

Do let me know. Has anybody got their products_listing.php working????

Converge

Link to comment
Share on other sites

Gimme the PHP files you using, maybe I can help...

Regards

Jack

 

This is the code for the buy now buttons

 

 

From featured products front page -

 

<td class="star-product">'. strip_tags($description['products_description']) . '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, "products_id=" . $featured_products["products_id"]). '">' . DESCR_READ_MORE . '</a><br><br><a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $featured_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_IN_CART) . '</a><br><br><span class="greetUser">' . $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) . ' </td>
<td background="images/infobox/right.gif" class="smallText"><img src="images/infobox/right.gif" width="14" height="149" /></td>

 

 

From Star Product -

 

<td><a href="' .  tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $star_products['products_id']) . '">' . tep_image_button('button_buy.gif', IMAGE_BUTTON_IN_CART) . '</a>' . tep_draw_separator('pixel_trans.gif', '10', '10') . '<a href="' .  tep_href_link(FILENAME_PRODUCT_INFO, "products_id=" . $star_products["products_id"]). '">' . tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/more_info.gif') . '</a></td>

 

 

From Default Specials -

 

<td class="star-product">'. strip_tags($description['products_description']) . '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, "products_id=" . $default_specials["products_id"]). '">' . DESCR_READ_MORE . '</a><br><br> <a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $default_specials['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_IN_CART) . '</a><br><br><s>'. $currencies->display_price($default_specials['products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</s><a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $default_specials['products_id']) . '">' . '</a> <span class="productSpecialPrice">' . $currencies->display_price($default_specials['specials_new_products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</span></td>

 

 

 

Would be great if you can help :thumbsup:

Link to comment
Share on other sites

  • 3 years later...

Hi!

 

I have tried to to this with my shop but i´ve got an templated store and my product listing is not the same,

 

the code below is what list the buy now button, the one in product_info i have managed to fix.

 

<div style="padding-top:7px;">'. preg_replace ($search, $replace, $show['desc']).'</div><div align="right" style=" padding-top:13px; padding-right:20px;" class="box_price">'.$product_contents[2].'    <a href="' . tep_href_link('product_info.php','products_id=' . $listing['products_id']) . '">' . tep_image_button('more_info.gif') . '</a>  <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a></div></td>

 

Please give me some pointers to apply this.

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...