Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Greyed out "in cart" button if out of stock


sf7804

Recommended Posts

Just wondering if there was a "better" way to do this. I've edited this in product_info.php, but it's rather crude.

 

<?php  

if (tep_get_products_stock($products_id) > 0) { ?>  

	 <input type="hidden" name="products_id" value="<?php echo $product_info_values['products_id']; ?>"><?php echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

<?php  }

else {

?>

<em><font color="#999999">Cannot add to cart</font></em><br>

<?php echo tep_image_submit('button_in_cart_grey.gif', 'Cannot add to cart - out of stock')?>

<?php } ?>

 

It works great though ;)

Link to comment
Share on other sites

Untested:

 

<?php

switch (tep_get_products_stock($products_id)) {

   case 0:

   echo '<em><font color="#999999">Cannot add to cart</font></em><br>';

   echo tep_image_submit('button_in_cart_grey.gif', 'Cannot add to cart - out of stock');

   break;

   default:

   echo '<input type="hidden" name="products_id" value=' . $product_info_values['products_id'] . '">';

   echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);

}

?>

Link to comment
Share on other sites

  • 1 month later...

Look for the part towards the bottom that has the button_in_cart.gif

Looks like this

<td align="right" class="main"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>

 

replace the part starting at <?php with the top code.

The second code does not work

Link to comment
Share on other sites

The complete fix.

 

Replace the following in product_info.php:

 

<input type="hidden" name="products_id" value="<?php echo $product_info_values['products_id']; ?>"><?php echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

 

with the following:

 

<?php 

if (tep_get_products_stock($products_id) > 0) { ?> 

<input type="hidden" name="products_id" value="<?php echo $product_info_values['products_id']; ?>"><?php echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> 

<?php } 

else { 

?> 

<em><font color="#999999">Cannot add to cart at this time</font></em><br> 

<?php 

//Comment out the line below...the grey image is still clickable if you do not

//echo tep_image_submit('button_in_cart_grey.gif', 'Cannot add to cart - out of stock')?> 

<?php } ?>

 

The greyed image will still be clickable unless you comment out the line

echo tep_image_submit('button_in_cart_grey.gif', 'Cannot add to cart - out of stock')?>

 

Sarah...Thanks for the code!!

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

After adding this code I get this strange behaviour

from INCART BUTTON

 

When the product quantity is 0

the button is hidden (in product_info.php)

 

But when product quantity is not 0

I get SHOPPING CART Empty message

http://affiliatesexcel.com

 

This happens wherever the info page is called from

 

Is anyone getting this ERROR ?

Link to comment
Share on other sites

Reading the various posts on the

SHOPPING CART EMPTY error it appears that

the most probable cause is a loss of the SID

 

At least it seems to be the cause in this case

 

Some how introducing the IF ELSE routine by

 

if (tep_get_products_stock($products_id) > 0)

 

before

<input type="hidden" name="products_id" value="<?php echo $product_info_values['products_id']; ?>"><?php echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

 

seem to break the SID

 

Can anyone please suggest a remedy ?

 

I found this is a very valuable FEATURE to add to the

cart as it prevents out of STOCK items and allow

you to INTEGRATE EBay AUCTIONS and other

memberships where you don't SELL through the cart.

 

( I have seen a big thread on integrating E BAY )

 

You can see how I am trying to do this on

http://affiliatesexcel.com

Menu TOP AUCTIONS

Link to comment
Share on other sites

  • 4 weeks later...

Also do the same for ../includes/modules/product_listing.php so that the button is greyed out when the products are listed, ie., (about line 147)

case 'PRODUCT_LIST_BUY_NOW':

$lc_align = 'center';

if (tep_get_products_stock($listing_values['products_id'])> 0)

{

$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . tep_image_submit('button_in_cart_small.gif',

TEXT_BUY . $listing_values['products_name'] . TEXT_NOW) . '</a> ';

}

else

{

$lc_text = tep_image_button('button_in_cart_small_faded.gif').' ';

}

break;

 

Regards,

Mark.

Link to comment
Share on other sites

Hello Mark

 

after adding the above code in product_listing.php

I get this error message

 

Parse error: parse error in /home/affili43/affili43-www/catalog/includes/modules/product_listing.php on line 178

 

wich is

} else {

 

in the code

 

 /* 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', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a> ';

           break;

       } */



        case 'PRODUCT_LIST_BUY_NOW': 

        $lc_align = 'center'; 

        if (tep_get_products_stock($listing_values['products_id'])> 0) 

        { 

        $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . tep_image_submit('button_in_cart_small.gif', 

        TEXT_BUY . $listing_values['products_name'] . TEXT_NOW) . '</a> '; 

        } 

        else 

        { 

        $lc_text = tep_image_button('button_in_cart_small_faded.gif').' '; 

        } 

        break; 







       $list_box_contents[$cur_row][] = array('align' => $lc_align,

                                              'params' => 'class="productListing-data"',

                                              'text'  => $lc_text);

     }

   }



   new tableBox($list_box_contents, true);



   echo '    </td>' . "n" .

        '  </tr>' . "n";

 } else {

 

I still get theCART EMPTY Error after modifying the codes in

i the product_info.php and product_listing .php

Link to comment
Share on other sites

I have sort of managed to integrate our

E Bay auctions in the cart. See

http://affiliatesexcel.com

 

Graying out the INCART button will be

a grate feature.

 

If any of the experts of osC could help with the

issues (ABOVE POSTINGS)with getting it workig properly it will be

a great step towards integrating AUCTIONS

or external linksin to osc

Link to comment
Share on other sites

  • 2 weeks later...

Also need to do the same treatment for .. /includes/modules/products_new.php (about line 35).

 

<td align="right" valign="middle" class="main"><?php

 

if (tep_get_products_stock($products_new_array[$i]['id'])> 0)

{

echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action'))

. 'action=buy_now&products_id=' . $products_new_array[$i]['id'], 'NONSSL') . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';

}

else

{

echo tep_image_button('button_in_cart_faded.gif', IMAGE_BUTTON_IN_CART);

}

 

?></td>

 

Regards,

Mark.

Link to comment
Share on other sites

Hi Mark

 

Many thanks for the additional correction in the

product_new.php

 

Now I get the Greyed out Buton

button_in_cart_small_faded.gif

in product_ listing.php (default page)

whether the quantity is 0 or more

 

and "OUT of stock" comment when the quantity is 0

in th Product_info.php

 

I still get the Shopping cart empty error

in shopping cart.php when you click

in cart button for a product where quantity is not 0.

 

If you are there and want to test I have left the

site with changed files (Please let me know

as the site is liVe)

Link to comment
Share on other sites

Hi "Valley",

 

I'm not sure what your problem is but I suspect the problems are eleswhere ie., shopping_cart.php, and not the above scripts. I'm having no problems and there is nothing in the scripts to create problems. Sorry I can't offer more help.

 

Good luck.

 

Mark.

Link to comment
Share on other sites

Hi Mark

 

Many thaks , it is a pity I can't get this to work

 

Thre are TWO roblems

 

In Product Listing BUY NOW button dsappear

even when th product quantity is more than 0

 

When you click on IN CART button you get

a message " YOURCART IS EMPTY "

 

ONly when the mods are implemented

Otherwise everything is fine

 

I don't kow why this happens only to my

cart as no one else seem to have these problems.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

I'm looking for sortof the same feature, but I would like the button greyed out when a product is not yet available. (when date expected > current date)

 

anybody know what to change for that?

 

thanks a lot for any info!

 

DicE

_____.:::.________###__________|/______

:(o o): . (o o) (o o)

ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

Link to comment
Share on other sites

Hi all.

 

is there nobody else doing that?

I mean, I would like to have the greyed out button, but not when a produkt is out of stock, just when it's not yet available because it's brand new and everybody is waiting for it etc :-) that should be so hard for all you die hard coders out there !!! :P

 

thanks!!!

 

DicE

_____.:::.________###__________|/______

:(o o): . (o o) (o o)

ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...