View Single Post
  #1  
Old 02-04-2007, 09:12 PM
 
gfiebich gfiebich is offline
 

Senior Member
  
Join Date: Feb 2003
Location: St. Paul, MN
Posts: 108
 

Default Schedule Item Availability

This mod was done in x-cart pro 4.0.19. I believe it should work fine in x-cart gold 4.0.19 as well, but I haven't tested it. Once in place, the mod allows you to schedule item availability by start and end dates. Expired items behave in the same manner as a standard Disabled item (unavailable for viewing or ordering in the storefront). This mod adds 2 new fields to the xcart_products table. No warranty is expressed or implied. Make sure you backup your database and site files before attempting the mod. Special thanks to PhilJ for his suggestions and free mods!
  1. Paste the following into the "Apply SQL Patch" text field on the Patch/Upgrade page of your site admin:
    Code:
    alter table xcart_products add start_date int(11) not null default '0'; alter table xcart_products add end_date int(11) not null default '0'; INSERT INTO `xcart_languages` VALUES ('US', 'Schedule Item Availability', 'lbl_schedule_availability', 'Schedule Item Availability', 'Labels'); INSERT INTO `xcart_languages` VALUES ('US', 'how to use the start_date and end_date fields', 'txt_sale_date_instructions', 'This feature causes an item to appear in the storefront during a specific time period. Both Start and End dates must be provided if you wish to schedule a sale. Leaving either or both fields blank disables the scheduling functionality. Dates may be provided in nearly any format (ie. \"June 1, 2006\", \"tomorrow\", \"6/22/2006 1:22pm\", etc.). ', 'Text');
    Click apply.
  2. Open include/product_modify.php and look for
    PHP Code:
    # Update product data 
    In the db_query that appears below this, insert the following among similar lines.
    PHP Code:
    start_date='".strtotime($start_date)."'end_date='".strtotime($end_date)."' 
    Depending on your version, you may need to format this a little differently:
    PHP Code:
    "start_date" => '".strtotime($start_date)."'"end_date" => '".strtotime($end__date)."' 
  3. Open skin1/main/product_details.tpl and paste the following somewhere near the bottom (just above the Extra Fields works well).
    PHP Code:
    <TR
    {if 
    $productids ne ''}<TD width="15" class="TableSubHead">&nbsp;</TD>{/if}
    <
    TD colspan="2"><BR>{include file="main/subheader.tpl" title=$lng.lbl_schedule_availability}</TD>
    </
    TR>
    <
    TR
    <
    TD colspan="2">{$lng.txt_sale_date_instructions}</TD>
    </
    TR>

    <
    tr>
     <
    td class="FormButton" nowrap>Start Date</td>
     <
    td class="ProductDetails"><input type="text" name="start_date" size="18" autocomplete="off" value="{if $product.productid eq ""}{else}{if $product.start_date ne 0}{$product.start_date|date_format:"%m/%d/%Y %H:%M"}{/if}{/if}" /></td>
    </
    tr>
    <
    tr>
     <
    td class="FormButton" nowrap>End Date</td>
     <
    td class="ProductDetails"><input type="text" name="end_date" size="18" autocomplete="off" value="{if $product.productid eq ""}{else}{if $product.end_date ne 0}{$product.end_date|date_format:"%m/%d/%Y %H:%M"}{/if}{/if}" /></td>
    </
    tr
  4. Open include/func.php and find
    PHP Code:
    if (!$always_select && ($product["forsale"] == "N" || ($product["forsale"] == "B" && empty($pconf)))) { 
    and replace with this
    PHP Code:
    if (($product["start_date"] != "0") && ($product["end_date"] != "0")) {
                
    $rightnow strtotime(now);

                    if (((
    $rightnow $product["end_date"]) || ($rightnow $product["start_date"]))) {
                    
    $offsale "true";
                    }

            }
            
            if (!
    $always_select && ($offsale == "true" || $product["forsale"] == "N" || ($product["forsale"] == "B" && empty($pconf)))) { 
  5. Open include/search.php and find
    PHP Code:
    $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."'"
    and replace with this
    PHP Code:
    $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."' AND 
        ((from_unixtime( unix_timestamp( ) )
        BETWEEN from_unixtime( start_date )
        AND from_unixtime( end_date )
        ) OR (
        (`start_date` IS NULL
        OR start_date =0
        ) OR (
        end_date IS NULL
        OR end_date =0
        )))"


That's it! I haven't tested my steps against a stock 4.0.19 installation, so your mileage may vary. If you want to add a calendar picker to the product admin fields, take a look at PhilJ's "Product Options Date/Time Picker" freebie mod.

-Glen
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote