Post by rezter » Thu Dec 09, 2010 11:02 am

I was wondering if it's possible to make items that have options appear as "Out of Stock" in the drop down menu and then impossible to add to the cart? For example: I am selling clothing items so I have the options of sizes, but users can still add the item to their cart if it's out of stock in the selected size. I realize that it comes up with a warning in the shopping cart and stops them from checking out but I would prefer if they couldn't add it to the cart to begin with.

Newbie

Posts

Joined
Tue Dec 07, 2010 10:09 am

Post by i2Paq » Thu Dec 09, 2010 7:48 pm

I believe this is not possible.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by JAY6390 » Thu Dec 09, 2010 7:50 pm

You could do it,but it would require quite a bit of hacking to get right, it's certainly no easy feat

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by Johnathan » Fri Dec 10, 2010 1:47 am

It's actually not that hard, you just have to disable the option when there's no quantity. I do this on my site A Trade For A Trade. For an example, take a look at this product. Here are the edits required:

1. IN:

Code: Select all

/catalog/model/catalog/product.php
AFTER:

Code: Select all

'prefix'                  => $product_option_value['prefix'] 
ADD:

Code: Select all

, 'quantity' => $product_option_value['quantity'] 
2. IN:

Code: Select all

/catalog/controller/product/product.php
AFTER:

Code: Select all

'prefix'          => $option_value['prefix'] 
ADD:

Code: Select all

, 'quantity' => $option_value['quantity'] 
3. IN:

Code: Select all

/catalog/view/theme/YOURTHEME/template/product/product.tpl
REPLACE:

Code: Select all

><?php echo $option_value['name']; ?>
WITH:

Code: Select all

<?php if($option_value['quantity'] == '0') {
    echo ' disabled="disabled">' . $option_value['name'] . ' (sold out)';
} else {
    echo '>' . $option_value['name'];
} ?>
The only caveat is that the first option sort-wise should have stock, or else it will be selected by default when the page loads. I'm sure there's a way around this (e.g. using jQuery) if someone wants to take the time to figure it out.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by rezter » Sat Dec 11, 2010 11:49 am

Thank you very much bro. It seems to work perfectly for me even when I deliberately put an out of stock option as the first in the sort order it automatically went to the next one upon loading the page so it is impossible to add it to the cart. Much appreciated my friend.

It may also be noted that if the item is out of stock (irrespective of the options) it can still be added to the cart... you are stopped in the cart by a notice and you can't progress to purchasing it but my aim was to stop people adding out of stock items to their cart. So what I did to resolve it was very simply used this code:

In:

Code: Select all

/catalog/view/theme/YOURTHEME/template/product/product.tpl
Find:

Code: Select all

<?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
<?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
Replace with:

Code: Select all

<?php if($product_info['quantity'] == '0') { echo $stock; } else { echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
<?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
<?php } ?>
Basically.... if it's Out Of Stock it replaces the "Qty: #" and "Add to Cart" button with text that simply says "Out of Stock".

Newbie

Posts

Joined
Tue Dec 07, 2010 10:09 am

Post by Johnathan » Sat Dec 11, 2010 11:07 pm

Yeah, I do the same thing on A Trade For A Trade. As a customer, I prefer it when I don't have to jump through hoops to find out if I can order a product or not.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by sekmo » Mon Oct 03, 2011 9:15 pm

Now in the 1.5 there's an option for that, right?

User avatar
Newbie

Posts

Joined
Mon Sep 26, 2011 9:50 pm
Who is online

Users browsing this forum: No registered users and 103 guests