Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Sold out button only on main page product listings?

Sold out button only on main page product listings?

Views: 1,141

Results 1 to 2 of 2
2 Jun 2011, 7:27 AM
#1
jt3c avatar

jt3c

New Zenner

Join Date:
Jul 2007
Location:
Eugene, OR
Posts:
16
Plugin Contributions:
0

Sold out button only on main page product listings?

I'm using v1.39h on my local test server and am not savvy with php coding.

I have the what's new product listing/gallery on the main page. The products are unique handcrafted dolls, so there will only be one of each.

My problem is that I want to leave the image of an item on the main page for awhile even after it has sold, with a 'sold out' button showing beneath it. I found some code that when added to the new_products.php will show the 'buy now' button if the item hasn't sold yet (qty=1) and the 'sold out' button when its purchased(qty=0).

I found the code in a reply to another thread:

'Sold out' button instead of price on main page

You can show a buy now button for all your items in the new product box. And when the product is not available, it shows the sold out button. Is this what you mean?

The code for to add the buy now button (for the new products page) is:

In other pages (specials, featured), rename $new_products accordingly.

Code:

$buy_now_link = zen_get_buy_now_button($new_products->fields['products_id'],'<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT) .'</a>');

Put it in /includes/modules/new_products.php

Have a look at the example below:

In my code lines 67 - 85

Code:

while (!$new_products->EOF) {
$products_price = zen_get_products_display_price($new_products->fields['products_id']);
$buy_now_link = zen_get_buy_now_button($new_products->fields['products_id'],'<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT) .'</a>');
if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev($new_products->fields['master_categories_id']);

$list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a><br />' . '<span class="advertisedPrice">' . $products_price . '</span><br/>' . $buy_now_link,
'link' => '' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']),

'image' => '' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT),
'title' => '' . $new_products->fields['products_name'],
'price' => '' . $products_price);

$col ++;
if ($col > (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS - 1)) {
  $col = 0;
  $row ++;
}
$new_products->MoveNextRandom();

}

What I'd like is to display just the 'sold out' once the item is sold, but not 'buy now' when its still available. Seems like a fairly simple 'if/then' type situation, but I can't seem to figure it out.

Can anyone help me modify the code I found, or direct me to code that will do what I want? It's the last polish I'd like to add before I upload and go live.

Hope this makes sense.

Thanks for any advice.

JT

2 Jun 2011, 3:14 PM
#2
jt3c avatar

jt3c

New Zenner

Join Date:
Jul 2007
Location:
Eugene, OR
Posts:
16
Plugin Contributions:
0

Re: Sold out button only on main page product listings?

A picture may help? Here's a screen shot of how it is right now with both buttons showing (sorry the image is small and fuzzy. I'm not sure how to paste an image as I've seen in other posts):

Attachment #9329

So, anyone have an idea for code that will only show the 'sold' button when the item has been purchased, but not the buy now when its available.

If the buy now is activated on the main page it puts the item right into the cart, skipping over the items detailed product info which I don't want happening. But I don't want them to have to go there if it is already sold thinking it is available, only if they consciously choose to click through and look at the details and larger additional images for that item. They may want to do this to get ideas for a customized doll, thus my desire to leave sold dolls in the gallery for awhile.

Thanks again for any help!

JT