Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / Is there a way to mark an entire category at out of stock?

Is there a way to mark an entire category at out of stock?

20 Jan 2016, 8:04 PM
#1
jcrewe avatar

jcrewe

Zen Follower

Join Date:
Jul 2011
Posts:
107
Plugin Contributions:
0

Post #1 by jcrewe

Hi there :)

I am wondering if there is a somewhat easy way to mark an entire category as Out of Stock? I am currently out of stock of material I require to make every item that I have in a particular category. The only way I have been able to stop customers from ordering from that category is to change my store status to Showcase with Prices. The problem with doing this is that I have other categories in which I do not require the out of stock material that I can still process. I don't want to disable the category all together either. Is there any way I can indicate a particular category is out of stock, still have the category showing but each item would be marked as out of stock and allow ordering of items that ARE in stock?? I hope that makes sense..lol! I'll add more specific details below in case it's confusing..lol!

Thanks :)

Specific details: I make personalized chocolate bar wrappers, wine bottle labels, invitations etc. I have run out of foil that I use to overwrap the chocolate bar before wrapping with the personalized wrapper, therefore, it basically renders all of my chocolate bar wrappers as 'out of stock' or 'unavailable' since I am out of stock on a key material. That said, all of my other items are still available since they don't require the overwrap.

20 Jan 2016, 8:06 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Post #2 by ajeh

Is this Category the master_categories_id of all of these products?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

20 Jan 2016, 8:22 PM
#3
jcrewe avatar

jcrewe

Zen Follower

Join Date:
Jul 2011
Posts:
107
Plugin Contributions:
0

Post #3 by jcrewe

Yes, it is the master category and then contains sub categories. So basically, the main category is 'Chocolate Bar Wrappers' and then that category contains sub categories such as 'Wedding', 'Birthday', 'Baby Shower' etc. i would like to know if there is a way to set the main (top) category as Out of Stock or Currently Unavailable.

Thanks :)

20 Jan 2016, 9:02 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #4 by mc12345678

Well may have a code way to do this... Could create a file in your admin directory:

Say call it

disable_category.php

to "activate" whichever option chosen below, then once logged into the admin goto/open:

admin/disable_category.php?cat_disable=10

to perform the applicable action from below for the category and all of the product below it that has the category_id of 10...

<?php
require('includes/application_top.php');

$prod_list = array();

if (isset($_GET['cat_disable']) && $_GET['cat_disable'] != '' && is_numeric($_GET['cat_disable'])) {
  $cat_to_disable = $_GET['cat_disable'];
} else {
  $cat_to_disable = false;
}

if ($cat_to_disable !== false) {
  $prod_list = zen_get_categories_products_list($cat_to_disable);
}

foreach ($prod_list as $prod_id => $cat) {
  $db->Execute('update ' . TABLE_PRODUCTS . ' p set p.products_status = 0 where p.products_id = ' . (int)$prod_id);
}

Or you could disable the product category which would disable the product...
This will disable the product from view (in a default install). If instead you want to set the quantity available to 0 and you have your store setup to not disable the product when quantity is 0, then:

<?php
require('includes/application_top.php');

$prod_list = array();

if (isset($_GET['cat_disable']) && $_GET['cat_disable'] != '' && is_numeric($_GET['cat_disable'])) {
  $cat_to_disable = $_GET['cat_disable'];
} else {
  $cat_to_disable = false;
}

if ($cat_to_disable !== false) {
  $prod_list = zen_get_categories_products_list($cat_to_disable);
}

foreach ($prod_list as $prod_id => $cat) {
  $db->Execute('update ' . TABLE_PRODUCTS . ' p set p.products_quantity = 0 where p.products_id = ' . (int)$prod_id);
}

Or... If you replace the call_for_price icon with your out-of-stock notification, then:

<?php
require('includes/application_top.php');

$prod_list = array();

if (isset($_GET['cat_disable']) && $_GET['cat_disable'] != '' && is_numeric($_GET['cat_disable'])) {
  $cat_to_disable = $_GET['cat_disable'];
} else {
  $cat_to_disable = false;
}

if ($cat_to_disable !== false) {
  $prod_list = zen_get_categories_products_list($cat_to_disable);
}

foreach ($prod_list as $prod_id => $cat) {
  $db->Execute('update ' . TABLE_PRODUCTS . ' p set p.product_is_call = 1 where p.products_id = ' . (int)$prod_id);
}

This will set the product to still being "available" (shown on screen) but requires calling for price instead of providing a price.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Jan 2016, 4:00 AM
#5
jcrewe avatar

jcrewe

Zen Follower

Join Date:
Jul 2011
Posts:
107
Plugin Contributions:
0

Post #5 by jcrewe

mc12345678:

Well may have a code way to do this... Could create a file in your admin directory:

Say call it

disable_category.php

to "activate" whichever option chosen below, then once logged into the admin goto/open:

admin/disable_category.php?cat_disable=10

to perform the applicable action from below for the category and all of the product below it that has the category_id of 10...

<?php require('includes/application_top.php'); $prod_list = array(); if (isset($_GET['cat_disable']) && $_GET['cat_disable'] != '' && is_numeric($_GET['cat_disable'])) { $cat_to_disable = $_GET['cat_disable']; } else { $cat_to_disable = false; } if ($cat_to_disable !== false) { $prod_list = zen_get_categories_products_list($cat_to_disable); } foreach ($prod_list as $prod_id => $cat) { $db->Execute('update ' . TABLE_PRODUCTS . ' p set p.products_status = 0 where p.products_id = ' . (int)$prod_id); } ``` Thanks mc12345678 for your response. I like the sounds of the first option you outlined but I'm wondering if you might need to dumb it down a little for me because what I did didn't seem to work...lol! I copied the code you provided and created a new file under /public_html/zcadmin called Disable_category.php. I then logged into my admin but I can't seem to find it anywhere to edit/activate. Clearly I've done it wrong :blink:
21 Jan 2016, 6:50 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #6 by mc12345678

jcrewe:

Thanks mc12345678 for your response. I like the sounds of the first option you outlined but I'm wondering if you might need to dumb it down a little for me because what I did didn't seem to work...lol! I copied the code you provided and created a new file under /public_html/admin called Disable_category.php. I then logged into my admin but I can't seem to find it anywhere to edit/activate. Clearly I've done it wrong :blink:

So, once you have logged in to the admin, in your browser use the path described above... Once complete press your back button to go back to your normal admin...

So on login your browser likely has something like: http s :// yourstore . Com/YOUR_SECRET_ADMIN/index.php

Change index.php to Disable_category.php and also add the parameter ?cat_disable=20 (where 20 is the category_id at the top of the tree of product to modify)

So:
http s :// yourstore . Com/YOUR_SECRET_ADMIN/Disable_category.php?cat_disable=25

Would do whatever was programmed to category_id 25

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Jan 2016, 2:20 PM
#7
jcrewe avatar

jcrewe

Zen Follower

Join Date:
Jul 2011
Posts:
107
Plugin Contributions:
0

Post #7 by jcrewe

mc12345678:

So, once you have logged in to the admin, in your browser use the path described above... Once complete press your back button to go back to your normal admin...

So on login your browser likely has something like: http s :// yourstore . Com/YOUR_SECRET_ADMIN/index.php

Change index.php to Disable_category.php and also add the parameter ?cat_disable=20 (where 20 is the category_id at the top of the tree of product to modify)

So:
http s :// yourstore . Com/YOUR_SECRET_ADMIN/Disable_category.php?cat_disable=25

Would do whatever was programmed to category_id 25

When I do that, I get a blank white screen as if the path goes nowhere and then when I check my site you can still order a product from that category :(

21 Jan 2016, 2:47 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #8 by mc12345678

Okay, while I'd like to troubleshoot the code (see what error logs are generated) if the desire is as described, disable the top category, and answer that you want all of the sub-information disabled as well... That will provide the same result as the code was written. Also, did you clear the cache of the browser between running it (yes a white screen was expected) and checking the store front...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Jan 2016, 10:50 PM
#9
jcrewe avatar

jcrewe

Zen Follower

Join Date:
Jul 2011
Posts:
107
Plugin Contributions:
0

Post #9 by jcrewe

Okay, so I dug around to see if I could see if anything was happening and it appears that the code has only disabled some of the products....and the weird thing is that I cannot for the life of me find a pattern on why some were disabled and some weren't. For example, in the main category in the quantity column is now shows 176 of 322 active. So, it 'deactivated' 176 listings. Unfortunately, this really wasn't what I was going for. I'd still like the products to show on my site but I would like them to show as 'sold out' or the add to cart button removed such as when the store is set to showcase.

Something I failed to ask in my previous message is once I have 'activated' the disable_category code, how do I DE-activate it so the products become enabled again?

Thanks :)

22 Jan 2016, 12:53 AM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #10 by mc12345678

jcrewe:

Okay, so I dug around to see if I could see if anything was happening and it appears that the code has only disabled some of the products....and the weird thing is that I cannot for the life of me find a pattern on why some were disabled and some weren't. For example, in the main category in the quantity column is now shows 176 of 322 active. So, it 'deactivated' 176 listings. Unfortunately, this really wasn't what I was going for. I'd still like the products to show on my site but I would like them to show as 'sold out' or the add to cart button removed such as when the store is set to showcase.

Something I failed to ask in my previous message is once I have 'activated' the disable_category code, how do I DE-activate it so the products become enabled again?

Thanks :)

So the code file that was generated above only activates when called upon... That happens by knowing the admin directory and the filename. To prevent any including yourself from deactivating product, remove the file from the server.

As to undoing the sql that was run, could assign a status of 1 for all product that has zero quantity, but this will include product that was previously disabled because of having zero quantity remaining...

Maybe I overlooked it, but I did try to find something that could be set to disable the add-to-cart and/or prevent product from being added to the cart..but, perhaps in a slightly more hurried fashion than desired (story of today) it was staring me in the face... I was thinking that the possibly could set the quantity add box such that one could not add the product, I suggested possibly making the product call for price as one of the several options presentedn. But even now not entirely sure I understand how the product was set before using the link manager and how it changed after using it... I tried to offer coded examples of how different results could be obtained with the expectation that the existing setup was understood... Bad on me to not ask more questions... Like said, been hurried a little today and as a result not getting/giving the best results...

Maybe some of the questions got answered, maybe someone else should offer assistance on this one/today...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...