Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Schedule Item Availability

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 02-05-2007, 03:47 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,058
 

Default Re: Schedule Item Availability

Nice one Glen, I'll definitely try this one out
__________________
xcartmods.co.uk
Reply With Quote
  #3  
Old 02-27-2007, 03:32 AM
  Warwick's Avatar 
Warwick Warwick is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Somewhere on the web through European connection
Posts: 868
 

Default 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
__________________
Installs: X-Cart 4.1.x - 4.4.x ∙∙ MySQL version: 5.0.45 ∙∙ Apache version: 2.2.8 (Unix) ∙∙ PHP version: 5.25
X-Cart add-ons: all ∙∙ Mods: A lot; too many ∙∙ Skin templates: Many
∙∙ Experience: Somewhere beyond newbie
-----------------------------------
------------------------------------------------------------------------------------------------------
Looking for the best dutch language pack? 4.1.x - 4.6.x compatibel, native speaker translation! More info
Reply With Quote
  #4  
Old 03-26-2007, 07:55 PM
  DataViking's Avatar 
DataViking DataViking is offline
 

eXpert
  
Join Date: Jan 2003
Location: Las Vegas, NV
Posts: 361
 

Default Re: Schedule Item Availability

very nice, have anyone try it in v 4.1
__________________
Web Design Web Design and Custom X-Cart Projects

http://www.dataviking.com

Mention the forums for discounts!
x-cart Version 4.1.8
Reply With Quote
  #5  
Old 04-20-2007, 01:18 AM
 
Kitman Kitman is offline
 

Member
  
Join Date: Oct 2006
Posts: 27
 

Default Re: Schedule Item Availability

Is there a demo available for this at all?
__________________
XCART GOLD 4.0.12
PHP 4.3.9
MySQL Server 4.0.22-nt
MySQL Client 3.23.49
Web Server Microsoft-IIS/6.0
Reply With Quote
  #6  
Old 04-20-2007, 06:07 AM
 
gfiebich gfiebich is offline
 

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

Default 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
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
  #7  
Old 06-14-2007, 11:35 PM
 
YINIA YINIA is offline
 

Member
  
Join Date: Dec 2006
Posts: 20
 

Default 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.
__________________
YINIA.com
----
version 4.1
using Mac OS X
Reply With Quote
  #8  
Old 07-22-2007, 10:24 PM
 
pavant pavant is offline
 

Advanced Member
  
Join Date: Oct 2004
Location: Chicago, Illinois
Posts: 84
 

Default 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.
__________________
X-Cart Gold v 4.1.10
PHP 5.2.4
MySQL 5.0.45 standard
Apache/2.2.6
OS - Linux
Reply With Quote
  #9  
Old 09-14-2007, 05:54 PM
 
ChrisBarnett ChrisBarnett is offline
 

Member
  
Join Date: Jun 2007
Posts: 13
 

Default 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!
__________________
X-Cart - 4.1.7 PRO
PHP - 4.4.4
MySQL 5.0.27
Apache 1.3.37
Linux
Reply With Quote
  #10  
Old 01-21-2008, 05:51 PM
 
MACWIllo MACWIllo is offline
 

Member
  
Join Date: Nov 2006
Posts: 17
 

Default 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.
__________________
X-cart 4.1.8
www.mooo.com.au
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:36 PM.

   

 
X-Cart forums © 2001-2020