Jump to content

 

mdekok3000

Member Since 06 Feb 2008
Offline Last Active Jan 31 2011 04:40 PM
-----

Topics I've Started

1.3.5 SP4 Content Encoding Error

17 September 2009 - 02:58 PM

I got an error that I just can't figure out. After installation of 1.3.5 SP4, I get a "Content Encoding Error" on both the front and admin side.

Also during installation it says set_magic_quotes_gpc() deprecated or something like that.

Can't access admin panel (Fatal error)

16 September 2009 - 06:52 PM

I logged into admin panel and got this error:

Fatal error: Smarty error: [in top.tpl line 1]: syntax error: invalid attribute name: 'top_quick_links.tpl\' (Smarty_Compiler.class.php, line 1546) in C:\wamp\www\lib\templater\Smarty.class.php on line 1095

MOD: Add products to cart automatically from items listed in an uploaded text file.

10 January 2009 - 08:05 AM

This mod will allow your customers to import a text file with a structure like this:

Item #1 Name|Quantity
Item #2 Name|Quantity
Item #3 Name|Quantity

For each item, the mod will search your products for the cheapest items in stock with that name and add them to the cart.

If a person wants 6 of a product and the first cheapest product it finds with that name has only 4 in stock. It will add all 4 and then, if it found another item with the same name, it will add the next cheapest and continue doing this until all 6 are added. If the requested quantity is not available, it will add all in stock.

It has been tested with:
- Out-of-stock items
- Items tying for lowest price

Great for products such as Trading Card Game cards because the name of the item that the person enters must match the name of the product in the store. This avoids adding unwanted, similarly-named products to the cart.

To install this mod, follow these steps:

1. Create a new directory in your store root called uploads. Set the permissions to 777.

2. Create a new php file under the store root called upload.php.


<?php
if(copy($_FILES["uploaded"]["tmp_name"],"./uploads/items.txt")) {
include "item_details.php";
} else {
echo "<p>Sorry, there was a problem uploading your file. <a href=\"javascript:history.go(-1);\">Click here</a> to return.</p>";
}
?>
3. Create a new php file under the store root called item_details.php. Modify the settings in this file before using.


<html>
<head>
<title>Confirm Selections</title>
</head>
<body>
<?php
//Settings
$db_host = "";
$db_name = "";
$db_user = "";
$db_password = "";
$store_path = "/store";
$return_path = "javascript:history.go(-1);";
//End Settings

function open_site($website){
$readSite = "";
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
if($openSite = @fopen ($website,"r")) {
while(!feof($openSite)) {
$readSite .= fread($openSite, 4096);
}
fclose($openSite);
}
return $readSite;
}

$tmp = open_site("uploads/items.txt");
$tmp = explode("
",$tmp);
$items = array();
for($i=0;$i<count($tmp);$i++) {
if($tmp[$i] != "") {
$items[count($items)] = $tmp[$i];
}
}
for($i=1;$i<count($items);$i++) {
for($j=0;$j<$i;$j++) {
$item1 = explode(" ",$items[$i]);
$item2 = explode(" ",$items[$j]);
$qty1 = $item1[0];
$qty2 = $item2[0];
array_shift($item1);
array_shift($item2);
$name1 = implode(" ",$item1);
$name2 = implode(" ",$item2);
$item1= trim($name1);
$item2 = trim($name2);
if($item1 == $item2) {
$items[$j] = ($qty1 + $qty2) . " $item1";
$items[$i] = "";
}
}
}
$tmp = $items;
$items = array();
for($i=0;$i<count($tmp);$i++) {
if($tmp[$i] != "") {
$items[count($items)] = $tmp[$i];
}
}

define("IN_CSCART","TRUE");
require "core/db_mysql.php";
require "core/fn_database.php";
require "core/fn_common.php";

$db_conn = db_initiate($db_host, $db_user, $db_password, $db_name);
if (!$db_conn) {
fn_error(debug_backtrace(), "Cannot connect to the database server", false);
}
if (defined("MYSQL5")) {
db_query("set @@sql_mode=''");
}
?>
<form action="<?php echo $store_path; ?>/index.php" method="post" name="products_bulk_purchase" id="products_bulk_purchase" onsubmit="window.location = '<?php echo $store_path; ?>/index.php?target=checkout&mode=cart';">
<input type="hidden" name="target" value="checkout" />
<input type="hidden" name="mode" value="add" />
<?php
$s1 = 0;
$s2 = 0;
for($i=0;$i<count($items);$i++) {
$item = explode("|",$items[$i]);
$name = trim($item[0]);
$qtyr = trim($item[1]);
$product_ids = db_get_array("SELECT product_id FROM cscart_product_descriptions WHERE product = \"$name\";");
if(count($product_ids) == 0) {
$out .= "<tr>
<td colspan=\"2\">$name</td>
</tr>
";
$s2++;
} else {
for($j=0;$j<count($product_ids);$j++) {
$product_ids[$j] = $product_ids[$j]["product_id"];
}
$product_ids2 = db_get_array("SELECT product_id FROM cscart_product_prices WHERE product_id IN (" . implode(",",$product_ids) . ") ORDER BY price ASC;");
for($j=0;$j<count($product_ids2);$j++) {
$product_ids2[$j] = $product_ids2[$j]["product_id"];
}
$qtya = 0;
for($j=0;$j<count($product_ids2);$j++) {
$pid = $product_ids2[$j];
$qtyh = db_get_field("SELECT amount FROM cscart_products WHERE product_id = $pid AND avail = 'Y';");
$price = db_get_field("SELECT price FROM cscart_product_prices WHERE product_id = $pid;");
if($qtyh > 0 && $qtyr > 0) {
$qtyh = min($qtyh,$qtyr);
$qtyr -= $qtyh;
$qtya += $qtyh;
$s1++;
?>
<input type="checkbox" id="bulk_addition_<?php echo $pid; ?>" style="display:none" name="product_data[<?php echo $pid; ?>][amount]" value="<?php echo $qtyh; ?>" checked="checked" />
<?php
}
}
if($qtya > 0) {
$out2 .= "<tr>
<td valign=\"top\">$name</td>
<td valign=\"top\" align=\"left\">$qtya</td>
</tr>
";
}
if($qtyr > 0) {
$out .= "<tr>
<td valign=\"top\">$name</td>
<td valign=\"top\" align=\"left\">$qtyr</td>
</tr>
";
$s2++;
}
}
}

if($s1 == 0) {
?>
<h3>No items will be added to the cart.</h3>
<?php
} else {
?>
<h3>The following items will be added to the cart:</h3>
<table cellpadding="3" cellspacing="0" border="0" width="300">
<?php echo $out2; ?>
</table>
<br />
<?php
}
if($s2 > 0) {
?>
<h3>The following items were either out of stock or not found:</h3>
<table cellpadding="3" cellspacing="0" border="0" width="300">
<?php echo $out; ?>
</table>
<br />
<?php
}
?>
<input type="submit" value="Continue" /> <input type="button" value="Return" onclick="window.location = '<?php echo $return_path; ?>';" />
</form>
</body>
</html>
4. Then insert this form code in your store wherever you want the upload form to be displayed:


<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>

MOD: Let computer know filesize of the files it's downloading.

14 October 2008 - 05:10 PM

Right now, when someone tries to download some file from an order. The computer is unable to tell how much further it has to go. For example:

Posted Image

Here's my fix:

In "/core/fn_common.php", add the 2 parts in red below:

[COLOR=Red]//
// Get the file or directory size
//
function getsize($file) {
    if (!is_dir($file)) {
        return filesize($file);
    }
    $size = 0;
    foreach (scandir($file) as $f) {
        if ($f == '.' or $f == '..') {
            continue;
        }
        $size += getsize($file . '/' . $f);
    }
    return $size;
}[/COLOR]

//
// Download the file
//
function fn_get_file($path, $disposition_filename='', $encode_name=false, $content_disposition="attachment")
{
    $file = basename($path);
    $fd = fopen($path, 'r');
    if ($fd) {
        header("Content-type: application/octet-stream");
        if (!$disposition_filename) {
            $disposition_filename = $file;
        }
        // If file name contains non latin simbols than it should be encoded for Internet Explorer
        if ($encode_name) {
            $disposition_filename = rawurlencode($disposition_filename);
        }
        header("Content-disposition: $content_disposition; filename=\"$disposition_filename\"");
        [COLOR=Red]header("Content-Length: " . getsize($path) . "\n");[/COLOR]
        while (!feof($fd)) {
            echo(fread($fd, 3000)); // Read by 3k blocks to avoid memory leaks
            fn_flush();
        }
        exit();
    }
}
The result is this:

Posted Image