X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Strange Out Of Stock Behavior on Products page (https://forum.x-cart.com/showthread.php?t=47995)

birdman 06-08-2009 05:42 PM

Strange Out Of Stock Behavior on Products page
 
I have a fashion site with variants on most products. I display SOLD OUT on the product page, and on the products (category) page when a product is out of stock, for the most part this works. I have the following code in products.tpl to handle this:
Code:

{if $products[product].avail le 0}<div class="sellout">SOLD OUT</div>{/if}
My problem comes when a user puts the last available item for the first variant in their cart, the product also appears as SOLD OUT on my products (category) page. It only appears this way to the customer with the product in their cart. So, say I have a dress in size 6,8 and 10, if there is one size 6 left and a customer puts it in their cart, the product then appears to the customer as sold out in the products list (category pages) regardless of the availability of the other sizes. This freaks customers out as they then become uncertain of a product's availability, and perhaps don't follow through.

My question (finally) how can I change this behavior so it only says SOLD OUT in my product listings if ALL variants are SOLD OUT, not just when someone has the last one of something in their cart?

I realise the importance of the default functionality on the product page, to prevent someone adding unavailable stock to their cart, but on the category pages it is confusing, especially when other variants might still be available.

Thanks in advance.

birdman 06-08-2009 07:30 PM

Re: Strange Out Of Stock Behavior on Products page
 
Okay, so I think I've found where I can fix this strange behavior but am wondering if anyone can think of any adverse consequences of doing this.

In include/search.php there is the following code:
Code:

$in_cart = 0;
if (!empty($cart['products']) && is_array($cart['products'])) {
# Modify product's quantity based the cart data
foreach ($cart['products'] as $cv) {
                if ($cv['productid'] == $v['productid'] && intval($v['variantid']) == intval($cv['variantid']))
                                                        $in_cart += $cv['amount'];
                                        }
                                        $products[$k]['in_cart'] = $in_cart;
                                        $products[$k]['avail'] -= $in_cart;
                                        if ($products[$k]['avail'] < 0) {
                                                $products[$k]['avail'] = 0;
                                        }
                                }


When I comment out the line:
Code:

$products[$k]['avail'] -= $in_cart;
like so:
Code:

//$products[$k]['avail'] -= $in_cart;

then it prevents the behavior I'm talking about.

Can anyone think of any other consequences of doing this?


All times are GMT -8. The time now is 01:08 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.