X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Schedule Item Availability (https://forum.x-cart.com/showthread.php?t=28582)

gfiebich 02-04-2007 09:12 PM

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

PhilJ 02-05-2007 03:47 AM

Re: Schedule Item Availability
 
Nice one Glen, I'll definitely try this one out :)

Warwick 02-27-2007 03:32 AM

Re: Schedule Item Availability
 
This is very cool; is there anybody who has got this working for 4.1.3?

I've looked through the code but it appears that it's quite different in 4.0.19 compared to 4.1.3 :(

DataViking 03-26-2007 07:55 PM

Re: Schedule Item Availability
 
very nice, have anyone try it in v 4.1

Kitman 04-20-2007 01:18 AM

Re: Schedule Item Availability
 
Is there a demo available for this at all?

gfiebich 04-20-2007 06:07 AM

Re: Schedule Item Availability
 
Sorry, no demo. Here is what the addition looks like on the Product Management screen in the admin (with PhilJ's date picker added):

http://www.hosthaste.com/schedule_mod.png

YINIA 06-14-2007 11:35 PM

Re: Schedule Item Availability
 
Quote:

Originally Posted by bmaworld
very nice, have anyone try it in v 4.1

Yeah, that. :) I'm not getting it to work in my version 4.1.3.

pavant 07-22-2007 10:24 PM

Re: Schedule Item Availability
 
I liked this mod so I modified for my 4.1.8 xcart. Here's what I have:

Step 1: SQL patch
Quote:


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', 'lbl_schedule_availability', 'Schedule Item Availability', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', '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');


Step 2: Change /include/product_modify.php

After
Quote:

"free_tax" => $free_tax,

Add
Quote:


"start_date" => '".strtotime($start_date)."',
"end_date" => '".strtotime($end__date)."',


Step 3: Open skin1/main/product_details.tpl and paste the following somewhere near the bottom (just above the Extra Fields works well).
Quote:


<
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>


Step 4: Open include/func/func.product.php and find
Quote:


if (!$always_select && ($product["forsale"] == "N" || ($product["forsale"] == "B" && empty($pconf)))) {


Replace with:
Quote:

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)))) {



Step 5: Open include/search.php and find:
Quote:


if (!empty($data["forsale"]))
$where[] = "$sql_tbl[products].forsale = '".$data["forsale"]."'";


Replace with:
Quote:


$where[] = "$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)))";


Hope this helps you 4.1 xcart babies. I make no promises that this code will work with your site; each environment is different and your code may function differently especially if it has already been moded. I can't provide any support for this mod. Install only if you have the resources to fix any problems that may occur.

ChrisBarnett 09-14-2007 05:54 PM

Re: Schedule Item Availability
 
Does anyone have sample code to put on the admin page?

I'm assuming thats missing because on the admin backend it doesn't ask me what dates I want.


*EDIT TO ADD*

I've uploaded that calender control...but I guessing that I need the code calls the calender for both of those fields (Start & Finish dates)

Thanks!

MACWIllo 01-21-2008 05:51 PM

Re: Schedule Item Availability
 
hi there,

Just tried to put this mod into my 4.1.9 store and its not quite working. I looked in my database and the fields have been created ok in the product's table, however the start date and end date come through as 0 everytime.. is this a problem with my version?

do you think if i put the values into the database myself (in unixtime i'm guessing) that it will work?

Cheers, Pete.


All times are GMT -8. The time now is 12:48 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.