This mod will add “Avail until” field to the Admin/Catalog/Products/Update screen. Currently, only “Avail since” appears there - which lets you “soft launch” products. “Avail until” will let you “expire” products without using the “Status = Disabled” option. As others have mentioned, using “Status = Disabled” results in a 404 error for customers and spiders visiting defunct items - which is less than ideal.
Note: the following involves changes to existing files in 2.0.12 and does not use hooks. This means that the next time you upgrade CS-Cart, there will be conflicts which you will need to resolve manually.
First, we add the new field and language to the database. In phpmyadmin, enter the following SQL statment:```php
ALTER TABLE cscart_products
ADD avail_until
INT( 11 ) UNSIGNED NOT NULL DEFAULT ‘0’ AFTER avail_since
;
INSERT INTO cscart_language_values
(lang_code
, name
, value
) VALUES (‘EN’, ‘available_until’, ‘Avail until’);
INSERT INTO cscart_language_values
(lang_code
, name
, value
) VALUES (‘EN’, ‘product_gone’, ‘This item is no longer available.’);
```
Now, open /skins/basic/admin/views/products/update.tpl, and find this: ```php
{$lang.available_since}:
{include file=“common_templates/calendar.tpl” date_id=“date_avail_holder” date_name=“product_data[avail_since]” date_val=$product_data.avail_since|default:“” start_year=$settings.Company.company_start_year}
{$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}
Now, open /skins/basic/admin/views/products/m_update.tpl, and find this: ```php {elseif $field == "avail_since"}
{include file="common_templates/calendar.tpl" date_id="field_`$field`__date" date_name="override_$name[$field]" date_val=$smarty.const.TIME start_year=$settings.Company.company_start_year extra=" disabled=\"disabled\"" date_meta="input-text-disabled"}
```and paste this just below:```php {* Avail Until mod *}
{elseif $field == "avail_until"}
{include file="common_templates/calendar.tpl" date_id="field_`$field`__date" date_name="override_$name[$field]" date_val=$smarty.const.TIME start_year=$settings.Company.company_start_year extra=" disabled=\"disabled\"" date_meta="input-text-disabled"}
```Now, find this:```php {elseif $field == "avail_since"}
{include file="common_templates/calendar.tpl" date_id="date_avail_holder_`$product.product_id`" date_name="$name[`$product.product_id`][$field]" date_val=$product.$field start_year=$settings.Company.company_start_year}
```and paste this just below:```php {* Avail Until mod *}
{elseif $field == "avail_until"}
{include file="common_templates/calendar.tpl" date_id="date_avail_until_holder_`$product.product_id`" date_name="$name[`$product.product_id`][$field]" date_val=$product.$field start_year=$settings.Company.company_start_year}
```
Now, open /controllers/admin/products.php (we have a few edits here) and find:```php $product_data = !empty($_REQUEST['override_products_data']) ? $_REQUEST['override_products_data'] : array();
if (isset($product_data['avail_since'])) {
$product_data['avail_since'] = fn_parse_date($product_data['avail_since']);
} ```and paste this just below:```php // Avail Until mod
if (isset($product_data['avail_until'])) {
$product_data['avail_until'] = fn_parse_date($product_data['avail_until']);
} ```Now, find this:```php array(
'name' => '[data][avail_since]',
'text' => fn_get_lang_var('available_since')
), ```and paste this just below:```php // Avail Until mod
array(
'name' => '[data][avail_until]',
'text' => fn_get_lang_var('avail_until')
), ```Now, find this:```php 'avail_since' => 'products_data',
```and paste this just below:```php // Avail Until mod
'avail_until' => 'products_data', ```Now, find this:```php } elseif ($field == 'avail_since') {
$desc = 'available_since'; ```and paste this just below:```php // Avail Until mod
} elseif ($field == 'avail_until') {
$desc = 'available_until'; ```Now, find this:```php if (!empty($product_data['avail_since'])) {
$_data['avail_since'] = fn_parse_date($product_data['avail_since']);
} ```and paste this just below:```php // Avail Until mod
if (!empty($product_data['avail_until'])) {
$_data['avail_until'] = fn_parse_date($product_data['avail_until']);
} ```Now, open /core/fn.catalog.php and find this:```php 'avail_since',
```and paste this just below:```php //Avail Until mod
'avail_until', ```Finally, open /skins/yourskin/customer/common_templates/product_data.tpl and find this:```php {if $product.avail_since <= $smarty.const.TIME || ($product.avail_since > $smarty.const.TIME && $product.buy_in_advance == "Y")}
{if $product.has_options && !$show_product_options && !$details_page}
{include file="buttons/button.tpl" but_id="button_cart_`$obj_id`" but_text=$lang.select_options but_href="$index_script?dispatch=products.view&product_id=`$product.product_id`" but_role="text" but_name=""}
{else}
{if $extra_button}{$extra_button} {/if}
{include file="buttons/add_to_cart.tpl" but_id="button_cart_`$obj_id`" but_name="dispatch[checkout.add..`$obj_id`]" but_role=$but_role}
{assign var="cart_button_exists" value=true}
{/if}
{/if}
{if $product.avail_since > $smarty.const.TIME}
{include file="common_templates/coming_soon_notice.tpl" avail_date=$product.avail_since add_to_cart=$product.buy_in_advance}
{/if}
```and replace with this:```php {*Avail Until mod *}
{if ($product.avail_until + 86400) > $smarty.const.TIME || $product.avail_until == 0}
{if $product.avail_since <= $smarty.const.TIME || ($product.avail_since > $smarty.const.TIME && $product.buy_in_advance == "Y")}
{if $product.has_options && !$show_product_options && !$details_page}
{include file="buttons/button.tpl" but_id="button_cart_`$obj_id`" but_text=$lang.select_options but_href="$index_script?dispatch=products.view&product_id=`$product.product_id`" but_role="text" but_name=""}
{else}
{if $extra_button}{$extra_button} {/if}
{include file="buttons/add_to_cart.tpl" but_id="button_cart_`$obj_id`" but_name="dispatch[checkout.add..`$obj_id`]" but_role=$but_role}
{assign var="cart_button_exists" value=true}
{/if}
{/if}
{/if}
{if (($product.avail_until + 86400) < $smarty.const.TIME) && ($product.avail_until > 0) }
{$lang.product_gone}
{else}
{if $product.avail_since > $smarty.const.TIME}
{include file="common_templates/coming_soon_notice.tpl" avail_date=$product.avail_since add_to_cart=$product.buy_in_advance}
{/if}
{/if}
```(One note about this change: I add 86400 seconds to the avail_until here date because I would expect the item to be available on the day of expiration, and gone the next.)
There are quite a few edits involved in this mod, so please double-check your work if it doesn't perform as expected. Also, be sure to clear your cache with "&cc" in the URL when testing.
cheers,
Glen