This is a little trick that complements the Avail Until mod posted here:
[url]http://forum.cs-cart.com/showthread.php?t=16014[/url]
You will need to have that mod installed before you use this.
I will warn you that I am not a programmer… I just came up with this to fit my needs and thought I’d share my rough draft with everyone. I haven’t fully tested it, but it appears to be working the way I intended it. Try it at your own risk.
Two options:
Option #1 - Adds a new option for toggling product status between active and hidden based on the availability date range. When the option is selected, it will It will make your product active when it is within the available date range and hide it when it is outside the available date range. You can leave the option unselected for products where the product status should remain unchanged regardless of availability.
Option #2 - The most simple option… This also toggles product status between active and hidden based on the availabilty date range, however, there is no option to include/exclude products. Use this if ALL of your products need to be hidden when they are outside of the availability date range. It won’t do anything to products that don’t have dates set. It only works on products that have both an available since date AND an available until date.
Instructions for each option are listed in separate posts below…
[SIZE=“4”]Option #1 Instructions[/SIZE]
Adds a new option for toggling product status between active and hidden based on the availability date range. When the option is selected, it will It will make your product active when it is within the available date range and hide it when it is outside the available date range. You can leave the option unselected for products where the product status should remain unchanged regardless of availability.
First you need to run this myql command.
```php ALTER TABLE `cscart_products` ADD `avail_hide` char( 1 ) NOT NULL DEFAULT 'N' AFTER `avail_until`; ```
Then you need to add a language variable:
1. Go to Content > Languages
2. Click Add language variable
3. In the Language variable field "avail_hide" (without the quotes)
4. Enter "Hide when not available?" as the value (without the quotes)
Now you're ready to add the checkbox to your products.update page....
In /skins/basic/admin/views/products/update.tpl
Search for the edit you made for the Avail Until mod. It looks like this:
```php {* Avail Until mod *}
{$lang.available_until}:
{include file="common_templates/calendar.tpl" date_id="date_avail_until_holder" date_name="product_data[avail_until]" date_val=$product_data.avail_until|default:"" start_year=$settings.Company.company_start_year}
Just below that, we will add a checkbox for the option "Hide when not available?":
```php {* Avail Hide mod *}
{$lang.avail_hide}:
Next you need to set up a cron job that will update your product status. You should set this up to run at the time of day when you want your products to switch out. For example, I am running a deals site and want my new deals to hit the store at 8 p.m. so I will run this at 8 p.m. If you want products to update at midnight I think you might want to run this at least a few seconds after midnight. I'm not smart enough to make a definite recommendation. ;)
I don't know how to set up a cron job the old fashioned way, so my instructions here aren't really complete. Maybe someone else can add better instructions. I use webmin, so I set it up like this:
command: (tbl_name is the name of your store's mysql table)
```php mysql tbl_name ```
Input to command:
```php UPDATE `cscart_products` set `status` = 'A' WHERE `avail_hide` = 'Y' AND (`avail_since` != 0 AND `avail_until` != 0) AND `avail_since` <= UNIX_TIMESTAMP() AND (`avail_until` + 86400 >= UNIX_TIMESTAMP());
UPDATE `cscart_products` set `status` = 'H' WHERE `avail_hide` = 'Y' AND (`avail_since` != 0 AND `avail_until` != 0) AND ((`avail_until` + 86400 <= UNIX_TIMESTAMP()) OR `avail_since` >= UNIX_TIMESTAMP()); ```
webmin then gives me options for when to run the cron job. I'm not sure how YOU will do it... sorry.
NOTE: You won't be able to mark your "Hide product when not available?" checkbox in the [URL="http://kb2.cs-cart.com/same-value-all-products"]bulk editor[/URL]. I didn't take the time to code it because it would be easier for me to go into mysql and change the values. If you want to mass edit all of your products to be hidden when they are not available, you can run this mysql command:
```php UPDATE `cscart_products` set `avail_hide` = 'Y'; ```
[SIZE=“4”]Option #2 Instructions[/SIZE]
The most simple option… This also toggles product status between active and hidden based on the availabilty date range, however, there is no option to include/exclude products. Use this if ALL of your products need to be hidden when they are outside of the availability date range. It won’t do anything to products that don’t have dates set. It only works on products that have both an available since date AND an available until date.
All you need to do is set up a cron job on your server to updated the product status. You should set this up to run at the time of day when you want your products to switch out. For example, I am running a deals site and want my new deals to hit the store at 8 p.m. so I will run this at 8 p.m. If you want products to update at midnight I think you might want to run this at least a few seconds after midnight. I'm not smart enough to make a definite recommendation. ;)
I don't know how to set up a cron job the old fashioned way, so my instructions here aren't really complete. Maybe someone else can add better instructions. I use webmin, so I set it up like this:
command: (tbl_name is the name of your store's mysql table)
```php mysql tbl_name ```
Input to command:
```php UPDATE `cscart_products` set `status` = 'A' WHERE (`avail_since` != 0 AND `avail_until` != 0) AND `avail_since` <= UNIX_TIMESTAMP() AND (`avail_until` + 86400 >= UNIX_TIMESTAMP());
UPDATE `cscart_products` set `status` = 'H' WHERE (`avail_since` != 0 AND `avail_until` != 0) AND ((`avail_until` + 86400 <= UNIX_TIMESTAMP()) OR `avail_since` >= UNIX_TIMESTAMP()); ```
webmin then gives me options for when to run the cron job. I'm not sure how YOU will do it... sorry.