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)
-   -   Egoods: Multiple downloadable files for each product. (https://forum.x-cart.com/showthread.php?t=6178)

Stevemike 01-23-2004 06:52 PM

Egoods: Multiple downloadable files for each product.
 
Hi all.

I'm new to x-cart and I am using x-cart pro 3.5.3 to create a digital product shopping site.

I needed to be able to attach multiple files for each product instead of being limited to the one 'distribution' file.

I have finished modifying the php and tpl files to do it and I was wondering if I can share it in this forum. I read a message in another section of the forums asking about such a feature, but I guess I'm supposed to post it in this category.

What parts of the code should I post so that it's not too confusing. I am using the 'pro' version, so I think the line numbers are a little different than for the 'gold' version.

Best regards,

Steve Castle

adpboss 01-23-2004 07:00 PM

Steve,

That's great that you are willing to share your hard work.

Perhpas browse through some of the other mods posted here to get a feel for how you want to present your work.

I look forward to checking it out!

shan 01-24-2004 05:30 AM

as long as you add comment tags to your code and state which version is done for then all should be good

Stevemike 01-24-2004 09:44 AM

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

DataViking 01-24-2004 12:45 PM

thanks for the MOD I will try it soon.

navro 03-10-2005 12:26 PM

ANyway customer/download.php can be modified for v.4.0.?
 
I have version 4.0.0 and I trying to modify this script for multiple esd files. Can anyone help?

Quote:

<?php
/************************************************** ***************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2004 Ruslan R. Fazliev <rrf@rrf.ru> |
| All rights reserved. |
+-----------------------------------------------------------------------------+
| PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS distribution1. THE AGREEMENT TEXT IS ALSO AVAILABLE |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
| |
| THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
| FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
| AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
| PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
| CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
| COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
| (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
| LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
| AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
| OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
| THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2004 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\************************************************* ****************************/

#
# $Id: download.php,v 1.1.2.1 2004/07/20 12:22:51 max Exp $
#
# This module adds support for downloading electronicaly distributed goods
#

@set_time_limit(2700);

require "./auth.php";

if ($HTTP_GET_VARS["action"] != "get") {
#
# Prepare the appearing of download page
#
include $xcart_dir."/include/categories.php";

if($active_modules["Manufacturers"])
include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";

if ($id) {

$productid = func_query_first_cell("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";
}

$distribution1 = $product_data['distribution1'];
$provider = $product_data['provider'];

if (!preg_match("/^(http|ftp|https):\/\//", $distribution1)) {
if (empty($provider) || $single_mode)
$distribution1 = $files_dir_name.$distribution1;
else
$distribution1 = $files_dir_name."/$provider".$distribution1;

$remote_file = false;
$fd = func_fopen($distribution1, "rb");
}
else {
$remote_file = true;
$fd = fopen($distribution1, "rb");
}
$file = '';
while($string = @fread($fd, 1024))
$file .= $string;

$product_data['length'] = number_format(strlen($file), 0, '', ' ');

fclose($fd);
$smarty->assign("product", $product_data);
$smarty->assign("url", $xcart_catalogs['customer']."/download.php?".$QUERY_STRING."&action=get");
}

}

$location[] = array(func_get_langvar_by_name("lbl_download"), "");

$smarty->assign("main", "download");

# Assign the current location line
$smarty->assign("location", $location);

func_display("customer/home.tpl",$smarty);
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 distribution1 for this product
$productid = $res['productid'];

$result = func_query_first("SELECT distribution1, product, provider FROM $sql_tbl[products] WHERE productid = '$productid'");

$distribution1 = $result['distribution1'];
$provider = $result['provider'];

if (!preg_match("/^(http|ftp|https):\/\//", $distribution1)) {
if (empty($provider) || $single_mode)
$distribution1 = $files_dir_name.$distribution1;
else
$distribution1 = $files_dir_name."/$provider".$distribution1;

$remote_file = false;
$fd = func_fopen($distribution1, "rb");
}
else {
$remote_file = true;
$fd = fopen($distribution1, "rb");
}

if ($fd) {

$fname = basename($distribution1);

header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"$fname\"");

if (!$remote_file) {
$size = filesize($distribution1);
header("Content-length: $size");
}

@fpassthru($fd);

fclose ($fd);

} else {
# If no such distributive
$smarty->assign("product", $result['product']);

# Assign the current location line
$smarty->assign("location", $location);

func_display("modules/Egoods/no_distributive.tpl",$smarty);
exit();
}
} else {
db_query("DELETE FROM $sql_tbl[download_keys] WHERE expires <= '".time()."'");

# Assign the current location line
$smarty->assign("location", $location);

func_display("modules/Egoods/wrong_key.tpl",$smarty);
exit;
}
?>


Amy 10-26-2005 03:06 PM

any updates?

Amy 11-05-2005 06:52 PM

anyone with insight on altering this for Pro 4.0.*

wjbrewer 11-20-2005 08:16 AM

I had this mod done by X-cart. They charged $125, but it has paid for itself already. It seemed pretty complicated. It took a couple of weeks of testing and tweaking for it to work correctly. They changed a lot of things to get it to work. Maybe that is why it is not standard, when it seems it should be. Why have variants if there is only one product to download?

Amy 11-20-2005 08:13 PM

ahhhh thanks for letting me know :)


All times are GMT -8. The time now is 10:23 PM.

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