Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

What is wrong with my code?


Cathi

Recommended Posts

Posted

I want sold products to show until I delete them. I am trying to alter product_listing.php so that if there is stock available, the Buy Now button appears, and if not, a Sold button appears. No matter what different things I try, only the Sold button appears on all the products. I wish everything was sold, LOL! :P

 

Here is the code so far, modeled after some code I found in a contribution, Soldout (but displayed) v0.2, which works just fine on the products_info.php and product_reviews.php pages.

 

case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';

$products_sold_out = '';
$stock_left = tep_get_products_stock($products_id) - $products_quantity;
$products_sold_out = stock_left;
if ($stock_left > 0) {
$lc_text = tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/button_buy_now.gif', 'Buy Now', IMAGE_BUTTON_BUY_NOW);
} else { 
$lc_text = tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/button_sold_out.gif', 'Sold Out', IMAGE_BUTTON_SOLD_OUT);
 }

		break;
	}

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

 

I hope someone can help. I am definitely not a php guru. :blink:

 

Cathi

Posted
case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';

$products_sold_out = '';
$stock_left = tep_get_products_stock($products_id) - $products_quantity;
$products_sold_out = stock_left;
if ($stock_left > 0) {
$lc_text = tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/button_buy_now.gif', 'Buy Now', IMAGE_BUTTON_BUY_NOW);
} else { 
$lc_text = tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/button_sold_out.gif', 'Sold Out', IMAGE_BUTTON_SOLD_OUT);
 }

		break;
	}

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

 

Not a PHP guru either, but I have the following in my product_info.php:

 

<br>
<font face="Arial" color="red" size="2"><?php if(($product_info['products_quantity']) < 1) echo $lc_text = '' . 'Contact us for avaiabilty or to pre-order' . ''; ?></font>
<p>
<p>
<?php

if(($product_info['products_quantity']) > 0)

echo TEXT_ENTER_QUANTITY . ":" . tep_draw_input_field('cart_quantity', $pf->adjustQty(1), 'size="6"'); 

if(($product_info['products_quantity']) > 0)

echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

 

It shows the 'buy it now' button etc if the stock quantity is 1 or more but shows 'Contact us for availability or to pre-order' if it's 0 or less.

Posted

Thanks Sean. I have it working on my product_info.php, but I wanted to do the same thing on product_listing.php.

 

Does anyone know if that's possible?

 

This is where I am now, and all the buttons say Buy Now, even for the sold item. Am I putting the IF statement in the wrong place, or am I just writing it completely wrong?

 

 case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';
		$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>?';

		break;
	}

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


	   if(($product_info['products_quantity']) > 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(DIR_WS_LANGUAGES . $language . '/images/buttons/button_sold_out.gif', 'Sold Out', IMAGE_BUTTON_SOLD_OUT);
 }

 

Cathi

Posted

I did see a few out of stock contributions. This particular one uses the quantity column, which I don't use because there is ever only one of each item. The code I'm trying to fit in there is from the one contribution that I did add to my store.

 

I just thought I might want to show a couple of the sold products (now I have no idea why I thought this was a good idea :huh: ), but I didn't want people to try and buy them.

 

Hopefully they'll just be smart enough to see the bright red note splashed across the product picture, lol. Or maybe it's a stupid idea and I'll just scrap it.

 

Thanks!

 

Cathi

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...