VirtueMart Forum

VirtueMart 2 + 3 => General Questions => Topic started by: snowgoose on April 29, 2019, 20:55:37 pm

Title: How to Display Out of Stock Items But Disable Add to Cart
Post by: snowgoose on April 29, 2019, 20:55:37 pm
Hi,
I have come across lots of similar questions to this on the forum, but no answer!

I am trying to set up a shop selling unique items. For example, shoulder bags that are hand made so although there may be 20 shoulder bags, every one is different. I have set up "shoulder bags" as a category and then each unit shoulder bag is a separate item so therefore only 1 in stock of each item.
I would like to show the items that are sold so people can see the sort of things that have been sold, but of course I don't want people to be able to order another one becasue the item is unique and there will never be another one. Ideally, the picture should say "SOLD" underneath and the "ADD TO CART" button should be disabled or not there.
I can make the item say "SOLD OUT" but then people can keep ordering more (why does this happen as I have set the stock level to 1 for every item?). The only way I can see to prevent ordering an infinite number of 1 item is to make it invisible when sold out. Is this really the only way??

Thanks
Dave
VM3.2.15 Joomla 3.9.5
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: Jörgen on April 29, 2019, 21:40:24 pm
Hello

In back end You find under VM configuration -> shop front end a setting stock control for out of stock items. Choose the right version for Your need.

Jörgen @ Kreativ Fotografi
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: snowgoose on April 29, 2019, 23:29:20 pm
Hi Jorgen,
That is where I was looking, but there is no setting to do what I want. All settings that still show an out-of-stock product also allow you to buy it (even though it is out of stock...I find this very strange....how can anyone buy something that is out of stock???). The only setting that stops anyone buying an out-of-stock item is the one that makes the item disappear. I don't want it to disappear...I just want it to still display the item and say "out of stock".

Is this possible please?
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: Jörgen on April 30, 2019, 08:41:29 am
The only explanation is that You are using a custom template with outdated code. The stock VM core works as expected, You can not buy out of stock items and out of stock items will be marked sold or similar.

Jörgen @ Kreativ Fotografi
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: snowgoose on April 30, 2019, 09:49:18 am
Hi,
That shouldn't be the reason. I am using the default Protostar template which comes with Joomla and I am using the latest Joomla and VM releases.
The options I have are the following:
So please, which one of the above should I use to meet my requirements? None meet them. Is there another way to do this? I cannot understand why the option to make an item unorderable with 'sold out' written over it. This is available on all other shops I have used.

Thank you
Dave
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: Jörgen on April 30, 2019, 10:04:08 am
OK, then You have to do a override.

templates/your-template/html/sublayouts/addtocartbar.php

Copy the original file from components/com_virtuemart...../sublayouts/addtocartbar.php, if you do not have any override yet.

Lookup the piece of code that shows the notify button. Comment out or replace with whatever you like.
Code: [Select]
echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $product->virtuemart_product_id)
regards

Jörgen
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: GJC Web Design on May 03, 2019, 12:17:53 pm
Displays 'notify Me' instead of 'Add to Cart' button (I don't wan this because customers will think they can get more stock added) and replace the Notify button with a sold out etc label
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: Jörgen on May 03, 2019, 12:45:18 pm
Killing the link to the button obviously.

Jörgen
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: snowgoose on May 03, 2019, 17:33:19 pm
Sorry for the late reply, but I had problems understanding the override. However, I realised that the path you gave me was slightly wrong. Should have been templates/your-template/html/com_virtuemart/sublayouts/addtocartbar.php (I should have realised but I haven't done any overrides before).

For those interested, this is what I did:
In CONFIGURATION...SHOPFRONT...ACTION WHEN A PRODUCT IS OUT OF STOCK choose "Displays notify me instead of add to cart button"
I then went to Joomla menu EXTENSIONS...LANGUAGE(S)...OVERRIDES. In the LANGUAGE CONSTANT box I put COM_VIRTUEMART_CART_NOTIFY (this is the constant that currently says "Notify Me" when the item is out of stock). I then put in the TEXT box "Sorry, this item is sold".
Now when an item is out of stock instead of "notify me" it says "sorry, this item is out of stock".
This is almost good enough, but the words are still a clickable link which I don't want. So I copied addtocartbar.php as Jorgen kindly showed me in this post. I then removed the code that created a link and left just the text.
REPLACE: <a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $product->virtuemart_product_id); ?>" class="notify"><?php echo vmText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?></a>
WITH:   <?php echo vmText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?>So now when an item is out of stock, it can be displayed and labelled as out of stock and not orderable.

Maybe this will help someone.

Many thanks to Jorgen for pointing me in the right direction.
Dave
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: Studio 42 on May 03, 2019, 17:34:49 pm
With the new "Discontinued" option, does it not work ?
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: jjk on May 03, 2019, 22:47:09 pm
Perhaps this helps: https://forum.virtuemart.net/index.php?topic=139178.msg488840#msg488840
I'm still using it to display sold out art prints without the 'Add to cart' button. However it might work only because I've also disabled the 'Add to cart' button in the category views. Example: https://kiekebusch.com/en/automobile-art/1955-mille-miglia-detail

(I think the 'Discontinued' option is meant for products which a shop still has in stock, but which are being produced anymore. It doesn't disable the 'Add to cart' view.)
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: snowgoose on May 03, 2019, 23:13:07 pm
@Studio42....the discontinued function does not do what I want.

@JJK, yes I saw your solution when searching for a solution for me. I hadn't considered disabling add to cart for category view but I can see now that it would work well for me. Nice website btw.

The method I am using works well so I'll stick with it, but thanks all for your ideas.

Dave
Title: Re: How to Display Out of Stock Items But Disable Add to Cart
Post by: GJC Web Design on May 04, 2019, 10:26:03 am
Quote
With the new "Discontinued" option, does it not work ?

seems to only mark them as such in the DB - I guess the idea is then to use this in your templates