Greetings all!
Here is the code changes and additions to add the ability to
have up to six distribution files per product. You can of course
change the code to add more if you want, but six was the right
amount for my needs.
This is a modification of X-Cart Pro 3.5.3
I am new to mysql and php, so I don't know if I made a mistake with
the first line to rename the 'distribution' column to 'distribution1'.
I made the changes to the 'xcart_products' table by hand using
myPHPadmin, so I didn't actually use the code below to alter the table.
Some of the changes I listed below require you to search and replace
the variable and column names in the files. I didn't list the code
for those files because they just required a simple search and replace.
Please let me know if you need any more details on the mod. This is
my first mod, so it's a little sloppy.
SQL stuff:
Code:
ALTER TABLE `xcart_products` CHANGE `distribution` `distribution1` varchar(255) NOT NULL;
ALTER TABLE `xcart_products` ADD `distribution2` varchar(255) NOT NULL default '' AFTER `distribution1`,
ADD `distribution3` varchar(255) NOT NULL default '' AFTER `distribution2`,
ADD `distribution4` varchar(255) NOT NULL default '' AFTER `distribution3`,
ADD `distribution5` varchar(255) NOT NULL default '' AFTER `distribution4`,
ADD `distribution6` varchar(255) NOT NULL default '' AFTER `distribution5`;
-------------------
customer/cart.php
-------------------
Code:
Code section:
#
# Do addition to cart
# With options
#
$options=array();
if(!empty($product_options)) {
if (is_array($product_options))
foreach($product_options as $key=>$product_option)
$product_options[$key] = stripslashes($product_option);
if ($active_modules["Product_Options"])
func_check_product_options ($productid, $product_options);
foreach($product_options as $key=>$product_option)
$options[]=array("optclass"=>$key,"optionindex"=>$product_option);
}
$found = false;
if (!empty($cart) and @$cart["products"] and $added_product["product_type"]!="C") {
foreach ($cart["products"] as $k=>$v) {
if (($v["productid"] == $productid) && (!$found) && ($v["options"] == $options) && empty($v["hidden"])) {
$found = true;
# Changed $distribution to $distribution1 and distribution to distribution1
$distribution1 = array_pop(func_query_first("select distribution1 from $sql_tbl[products] where productid='$productid'"));
if (($cart["products"][$k]["amount"] >=1) && ($distribution1))
{$cart["products"][$k]["amount"]=1; $amount=0;}
$cart["products"][$k]["amount"] += $amount;
}
}
}
---------------------
customer/download.php
---------------------
Code:
#
# $Id: download.php,v 1.20.2.2 2003/12/10 11:52:36 mclap Exp $
#
# This module adds support for downloading electronicaly distributed goods
#
require "./auth.php";
if ($HTTP_GET_VARS["action"] != "get") {
#
# Prepare the appearing of download page
#
include $xcart_dir."/include/categories.php";
if ($id) {
$productid = array_pop(func_query_first("SELECT productid FROM $sql_tbl[download_keys] WHERE download_key = '$id'"));
if ($productid) {
$product_data = func_query_first("SELECT * FROM $sql_tbl[products] WHERE productid='$productid'");
if($active_modules["Extra_Fields"]) {
$extra_fields_provider=$product_data["provider"];
include $xcart_dir."/modules/Extra_Fields/extra_fields.php";
}
$smarty->assign("product", $product_data);
# Change: pass urls for each file.
if ($product_data["distribution1"] != "") {
$smarty->assign("url1", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=1");
}
if ($product_data["distribution2"] != "") {
$smarty->assign("url2", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=2");
}
if ($product_data["distribution3"] != "") {
$smarty->assign("url3", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=3");
}
if ($product_data["distribution4"] != "") {
$smarty->assign("url4", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=4");
}
if ($product_data["distribution5"] != "") {
$smarty->assign("url5", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=5");
}
if ($product_data["distribution6"] != "") {
$smarty->assign("url6", $http_location."/customer/download.php?".$QUERY_STRING."&action=get&file=6");
}
}
}
$smarty->assign("main", "download");
$smarty->display("customer/home.tpl");
exit;
}
if (empty($id)) exit();
$chunk_size = 100*1024; # 100 Kb
$query = "SELECT * FROM $sql_tbl[download_keys] WHERE download_key = '$id'";
$res = func_query_first($query);
# If there is corresponding key in database and not expired
if ((count($res) > 0) AND ($res['expires'] > time())) {
# check if there is valid distribution for this product
$productid = $res['productid'];
# Change: changed variable names to use correct file distribution.
$filedistribution = 'distribution'.$file;
$result = func_query_first("SELECT $filedistribution, product, provider FROM $sql_tbl[products] WHERE productid = '$productid'");
$distributionfile = $result[$filedistribution];
$provider = $result['provider'];
if (empty($provider) || $single_mode)
$distribution = $files_dir_name.$distributionfile;
else
$distribution = $files_dir_name."/$provider".$distributionfile;
if ($fd = @fopen($distribution, "rb")) {
$fname = basename($distribution);
$size = filesize($distribution);
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"$fname\"");
header("Content-length: $size");
for($i=0; $i<=$size; $i+=$chunk_size) {
$contents = fread ($fd, $chunk_size);
echo $contents;
}
fclose ($fd);
} else {
# If no such distributive
$smarty->assign("product", $result['product']);
$smarty->display("modules/Egoods/no_distributive.tpl");
exit();
}
} else {
db_query("DELETE FROM $sql_tbl[download_keys] WHERE expires <= '".time()."'");
$smarty->display("modules/Egoods/wrong_key.tpl");
exit;
}
--------------------------
include/product_modify.php
--------------------------
Code:
Code section:
#
# Update product data
#
# change: added distribution1 - distribution6
db_query("update $sql_tbl[products] set product='$product', categoryid='$categoryid', categoryid1='$categoryid1', categoryid2='$categoryid2', categoryid3='$categoryid3', brand='$brand', model='$model', descr='$descr', fulldescr='$fulldescr', avail='$avail', list_price='$list_price', weight='$weight', productcode='$productcode', forsale='$forsale', distribution1='$distribution1', distribution2='$distribution2', distribution3='$distribution3', distribution4='$distribution4', distribution5='$distribution5', distribution6='$distribution6', free_shipping='$free_shipping', shipping_freight='$shipping_freight', discount_avail='$discount_avail', min_amount='$min_amount', param00='$param00', param01='$param01', param02='$param02', param03='$param03', param04='$param04', param05='$param05', param06='$param06', param07='$param07', param08='$param08', param09='$param09', low_avail_limit='$low_avail_limit', $apply_vat free_tax='$free_tax' $apply_canadian_taxes where productid='$productid'");
----------------
include/func.php
----------------
Code:
Replaced all instances of 'distribution' with 'distribution1'
----------------------------
modules/egoods/send_keys.php
----------------------------
Code:
Replaced all instances of 'distribution' with 'distribution1'
----------------------------------
skin1/admin/main/product_links.tpl
----------------------------------
Code:
Replaced all instances of $product.distribution with $product.distribution1
-------------------------------
skin1/customer/main/buy_now.tpl
-------------------------------
Code:
Replaced $product.distribution with $product.distribution1
----------------------------
skin1/customer/main/cart.tpl
----------------------------
Code:
Replaced $products[product].distribution with $products[product].distribution1
-------------------------------
skin1/customer/main/product.tpl
-------------------------------
Code:
Replaced {if $product.distribution eq ""} with {if $product.distribution1 eq "" and $product.distribution2 eq "" and $product.distribution3 eq "" and $product.distribution4 eq "" and $product.distribution5 eq "" and $product.distribution6 eq ""}
-------------------------------
skin1/modules/egoods/egoods.tpl
-------------------------------
Code:
{* $Id: egoods.tpl,v 1.5 2002/10/17 13:54:57 zorg Exp $ *}
{* changed: provider can now add up to six product files. *}
<tr>
<td colspan=2 valign=middle class=Text>
Guidelines:
Please try to keep filesizes reasonable by splitting your product into multiple files if necessary.
This will reduce problems for dial-up customers getting disconnected while downloading your product.
We suggest a maximum filesize of 5MB (30mins at 56kps) for each file.
</td>
</tr>
<tr>
<td valign=middle class=Text>Product File #1</td>
<td valign="middle">
{include file=main/popup_files_js.tpl}
<INPUT type=hidden name=distribution1_filename>
<input type="text" name="distribution1" size="24" value="{ $product.distribution1 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution1_filename', 'modifyform.distribution1');">
</td>
</tr>
<tr>
<td valign=middle class=Text>Product File #2</td>
<td valign="middle">
<INPUT type=hidden name=distribution2_filename>
<input type="text" name="distribution2" size="24" value="{ $product.distribution2 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution2_filename', 'modifyform.distribution2');">
</td>
</tr><tr>
<td valign=middle class=Text>Product File #3</td>
<td valign="middle">
<INPUT type=hidden name=distribution3_filename>
<input type="text" name="distribution3" size="24" value="{ $product.distribution3 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution3_filename', 'modifyform.distribution3');">
</td>
</tr><tr>
<td valign=middle class=Text>Product File #4</td>
<td valign="middle">
<INPUT type=hidden name=distribution4_filename>
<input type="text" name="distribution4" size="24" value="{ $product.distribution4 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution4_filename', 'modifyform.distribution4');">
</td>
</tr><tr>
<td valign=middle class=Text>Product File #5</td>
<td valign="middle">
<INPUT type=hidden name=distribution5_filename>
<input type="text" name="distribution5" size="24" value="{ $product.distribution5 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution5_filename', 'modifyform.distribution5');">
</td>
</tr><tr>
<td valign=middle class=Text>Product File #6</td>
<td valign="middle">
<INPUT type=hidden name=distribution6_filename>
<input type="text" name="distribution6" size="24" value="{ $product.distribution6 }">
<input type=button value="Browse..." onClick="popup_files('modifyform.distribution6_filename', 'modifyform.distribution6');">
</td>
</tr>
I also removed code from the email templates for sending the download keys.
-----------------------------------
skin1/mail/egoods_download_keys.tpl
-----------------------------------
Code:
Removed: {$lng.lbl_filename}: {$products[prod_num].distribution_filename}
(You don't have to remove this, but I didn't want to list the filenames in
the email, just in case the provider needs to add a file to the product he
may have forgotten to add.)
----------------------------------------
skin1/mail/html/egoods_download_keys.tpl
----------------------------------------
Code:
Removed:
<tr>
<td></td>
<td><tt>{$lng.lbl_filename}:</tt></td>
<td></td>
<td><tt>{$products[prod_num].distribution_filename}</tt></td>
</tr>
Please let me know if there is anything that I may have missed.
I have run lots of tests on it and it works so far.
Best regards,
Steve Castle