X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   One page, add multiple quantities, of multiple products (https://forum.x-cart.com/showthread.php?t=2437)

Jon 04-24-2003 11:44 AM

One page, add multiple quantities, of multiple products
 
What I'd like to do is have one page with all products listed (I have this already):

I'd like to have a quantity box beside each product that defaults to 0.

The user can then go down the list and add a quantity beside any product they want to add.

Then go down to the bottom of the list and hit an Add To Cart button.

The products with quantities selected would be added to their cart, and they would be transfered into the check out process.

Has this been done? Any suggestions on implementation? The list is easy, the transfer of multiple items to checkout is the more difficult aspect.

Thanks in advance for any direction.

B00MER 04-24-2003 12:04 PM

good luck with this one, adding multiple items to cart.php is a difficult task, I think funkydunk may have the most insight on this. ;)

Jon 04-24-2003 12:08 PM

It will be done, oh yes, it will be done. And if I build it, they will order.

funkydunk 04-24-2003 01:56 PM

Done this mod, so that on the products.tpl page there is a quantity box to fill in and if these are filled in on any product and if any add to cart button is clicked all are added to the cart.

Jon 04-24-2003 02:52 PM

Mind sharing :D

B00MER 04-24-2003 03:24 PM

:lol:

anoack 04-25-2003 12:44 AM

Would you please care to reply to this post? I would really like to know how to do this one. It would help me out allot man!

Thanks in advance!

-Austin

funkydunk 04-25-2003 01:15 AM

okay.....feeling generous today cos it's friday. :D

Note this will work for up to 10 products per page.

It is not the most elegant of code but it works and that is what counts really :wink:

new customer/main/products.tpl code:

Code:

{* $Id: products.tpl,v 1.16.2.2 2002/11/13 07:17:50 alfiya Exp $ *}
{* multiple add to cart products page by funkydunk.net 2003 *}

<form action="addmultiple.php" method="get" name="orderform">
{section name=product loop=$products}
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td width=90 align=center valign=top>
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{include file="product_thumbnail.tpl" productid=$products[product].productid image_x=70 product=$products[product].product}
{$lng.lbl_see_details}</a>
</td>
<td width= "300">
{$products[product].product|escape}

{$products[product].descr|truncate:300:"...":true}

{if $active_modules.Subscriptions ne "" and $products[product].catalogprice}

{include file="modules/Subscriptions/subscription_info_inlist.tpl"}

{else}
{if $products[product].price ne 0}
{if $products[product].discount ne 0}

{$lng.lbl_market_price}: <s>
{math equation="price/(1-(discount/100))" price=$products[product].price discount=$products[product].discount format="%d.00" assign=unformatted}{include file="currency.tpl" value=$unformatted}
</s>{/if}
</td>

<td width= "60" align="right">
{include file="currency.tpl" value=$products[product].price}
{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}
{if $products[product].discount ne 0}, save {$products[product].discount}%{/if}
{else}
{$lng.lbl_enter_your_price}
{/if}
{/if}</td>

<td width= "60" align="right">
Quantity: <input type=text name=amount{%product.index%} size=3>


<input type=hidden name=productid{%product.index%} value="{$products[product].productid}">
<a href="javascript: document.orderform.submit()">
{include file="buttons/add_to_cart.tpl"}</a>
</td>
</tr><tr>
<td colspan="4"><hr size="1" noshade></td>
</tr></table>{/section}
<input type=hidden name=cat value="{$smarty.get.cat}">
<input type=hidden name=page value="{$smarty.get.page}">
<input type=hidden name=mode value=add>
</form>


new php file - customer/addmultiple.php

Code:

<?php
// addmultiple.php by funkydunk.net 2003
// adapted copy of x-cart cart.php Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. 
// only works with up to 10 products per page - obviously could be improved
// this was put together to fit the requirements that i had not yours :)
// there are prob bits of code in here that are not needed but hey..

require "../smarty.php";
require "../config.php";
@include "./https.php";
require "./auth.php";

include "./nocookie_warning.php";

session_register("cart");
session_register("intershipper_rates");
session_register("intershipper_recalc");

$intershipper_recalc = "Y";

#
# $order_secureid (for security reasons)
#
session_register("order_secureid");

#
# Register member if not registerred yet
# (not a newbie - do not show help messages)
#
$smarty->assign("register_script_name","addmultiple.php");

require "../include/register.php";
 if ($auto_login) {
    header("Location: cart.php?mode=checkout&registered=");
    exit;
}

if (!empty($login)) $userinfo = func_userinfo($login, $current_area);

if ($mode=="add"){ // get the variables posted from the main page and add them to the array for cart items.
       
// takes the values from the products.tpl form and adds them into an array to work with for the looping through the add to cart process

if ($amount0) {
$item ["productid"] = $productid0;
$item ["amount"] = $amount0;
$added[] = $item;
}
if ($amount1) {
$item ["productid"] = $productid1;
$item ["amount"] = $amount1;
$added[] = $item;
}
if ($amount2) {
$item ["productid"] = $productid2;
$item ["amount"] = $amount2;
$added[] = $item;
}
if ($amount3) {
$item ["productid"] = $productid3;
$item ["amount"] = $amount3;
$added[] = $item;
}
if ($amount4) {
$item ["productid"] = $productid4;
$item ["amount"] = $amount4;
$added[] = $item;
}
if ($amount5) {
$item ["productid"] = $productid5;
$item ["amount"] = $amount5;
}
if ($amount6) {
$item ["productid"] = $productid6;
$item ["amount"] = $amount6;
$added[] = $item;
}
if ($amount7) {
$item ["productid"] = $productid7;
$item ["amount"] = $amount7;
$added[] = $item;
}
if ($amount8) {
$item ["productid"] = $productid8;
$item ["amount"] = $amount8;
$added[] = $item;
}
if ($amount9) {
$item ["productid"] = $productid9;
$item ["amount"] = $amount9;
$added[] = $item;
}
}
// end of adding products to array - bit rough and ready but then that's me :)

// count how many products in array

$count = count($added);

for ($row = 0; $row < $count; $row++) {
// start of loop through products added..puts all the added prodcust into a multi-dimensional array

$productid = $added[$row]["productid"];
$amount = $added[$row]["amount"];
$mode = "add";

// this is a chunk of code from the original 2.2.x cart.php script built by x-cart Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved.

#
# Add to cart
#
if($mode=="add" && $productid!="") {

        $added_product=func_select_product($productid, $user_account['membership']);

#
# Add to cart amount of items that is not much than in stock
#
        $amount = array_pop(func_query_first("select least('$amount',avail) from $sql_tbl[products] where productid='$productid'"));

        if ($productid && $amount) {

                if ($amount < $added_product[min_amount]) {
                        header ("Location: error_message.php?access_denied");
                        exit;
                }

#
# Do addition to cart
# With options
#
                $options=array();

                $found = false;
                if ($cart["products"]) {
                        foreach ($cart["products"]  as $k=>$v) {
                                if (($v["productid"] == $productid) and (!$found) and ($v["options"] == $options)) {
                                        $found = true;
                               
                                        $distribution = array_pop(func_query_first("select distribution from $sql_tbl[products] where productid='$productid'"));
                                        if (($cart["products"][$k]["amount"] >=1) && ($distribution))               
                                                {$cart["products"][$k]["amount"]=1; $amount=0;}

                                        $cart["products"][$k]["amount"] += $amount;
                                }
                        }
                }
#
# price value is defined by customer if administrator set it to '0.00'
#
                if (!$found)
                        $cart["products"][]=array("productid"=>$productid,"amount"=>$amount, "options"=>$options, "price"=>$price);

                $intershipper_recalc = "Y";

        }
       

}



if (!func_is_cart_empty($cart)) {

        $products = func_products_in_cart($cart, $userinfo["membership"]);

        /*if($active_modules["Subscriptions"]) {
            include "../modules/Subscriptions/subscription.php";
        }*/
       
        if (!empty ($cart["products"]) && ($login || !($config["Shipping"]["enable_all_shippings"] == "Y"))) {
                $destination_condition = " and destination=".($userinfo["s_country"]!=$config["Company"]["location_country"]?"'I'":"'L'");
        }
#
# Fetch real shipping values
#
        if($config["Shipping"]["realtime_shipping"]=="Y" && !empty($cart["products"]) && $login) {
                if ($intershipper_recalc != "N") {
                        if ($config["Shipping"]["use_intershipper"] == "Y")
                                require "../shipping/intershipper.php";
                        else
                                require "../shipping/myshipper.php";

                        $intershipper_rates = func_shipper (func_weight_shipping_products($products));

                        $intershipper_recalc = "N";
                }
        }

        if (!empty($cart["products"])) {
                if (!$login || $config["Shipping"]["realtime_shipping"]!="Y")
                        $shipping = func_query("select * from $sql_tbl[shipping] where active='Y' $destination_condition order by orderby");
                else {
                        $shipping = array ();
                        if($intershipper_rates)
                                foreach($intershipper_rates as $intershipper_rate) {
                                        $result = func_query_first("select * from $sql_tbl[shipping] where subcode='$intershipper_rate[methodid]' and active='Y' order by orderby");
                                        if ($result)
                                                $shipping[] = $result;
                        }
                        $result = func_query ("SELECT * FROM $sql_tbl[shipping] WHERE code='' AND active='Y' $destination_condition ORDER BY orderby");
                        if ($result) {
                                foreach ($result as $res) {
                                        $shipping [] = $res;
                                }
                        }
                                function array_cmp($a, $b) {
                                        if ($a[orderby] == $b[orderby]) return 0;
                                        return ($a[orderby] > $b[orderby]) ? 1: -1;
                                }
                                usort($shipping, "array_cmp");
                }
        }
        if (count($shipping)==0) unset($shipping);
        $smarty->assign("shipping", $shipping);
}


#
# If cart is not empty put products details into products array
#
if (!func_is_cart_empty($cart)) {

#
# Calculate all prices
#
                $cart = array_merge ($cart, func_calculate($cart, $products, $login, $current_area));
                $smarty->assign("cart",$cart);

}


} // end of loop that added the product to the cart - shall we do that again

// assign values to smarty cos I'm feeling generous
// here you go smarty have these

$smarty->assign("userinfo",$userinfo);
$smarty->assign("products",$products);
$smarty->assign("giftcerts",$giftcerts);
$smarty->assign("order",$order);

// Redirect once finished looping through products added to cart
// bored now..can I go to the cart..please?

header("Location: cart.php");

?>


This will take the customer to the cart at the end of the process.

No warranty is given with and PLEASE BACKUP beforehand.

anoack 04-25-2003 07:32 AM

Your a Saint!

Thanks allot man!

funkydunk 04-25-2003 07:46 AM

presume it worked then? :D

anoack 04-25-2003 08:08 AM

Also,
I was thinking that I could take something like this and modify it.

This is what I was thinking about doing.

I want to have it to on certain products where people can click a checkbox to add a product to the existing one.

E.G.
You goto the product details.
You have the "Add to shopping cart" Button with the Qty: Value next to it.

I also want to have a checkbox right below it that has it to where you can add another product.
Like right below it you would have a check box with a Qty value next to it.

By checking it and selecting a QTY Value it will add both the product and the extra product you selected.

Can that be done?

B00MER 04-25-2003 09:34 AM

:!: Just wanted to make a side note here for funkydunk, alot of time and effort was more than likely put into this mod as well as others he feels generous enough to post, so just think of it in terms of him saving you development time and money, so the moral of the story is please give something back be it donations, hosting space, etc. as this really encourages funkydunk as well as other developers like myself, shan, and the countless others who help keep the forums rich of code, fixes, and walk throughs.

< steps off soapbox >

:D

funkydunk 04-25-2003 10:08 AM

blood, sweat and tears m8 :lol:

costs me a fortune when I have generous days :wink:

funkydunk 04-25-2003 10:10 AM

sorry to answer the question

Quote:

Can that be done?

yep...anything is possible

anoack 04-25-2003 10:22 AM

Cool,
Well if you can help me out with that I sure can paypal you some money or I could give you space on my new co-location server.
Its a new machine Dual Xeon 2.8 100mbit line. Plenty of space.

Let me know man!

Thanks,

funkydunk 04-25-2003 11:13 PM

Thanks for the offer of the hosting but I have my own dedicated servers so wouldn't be needing any extra.

This is possible but I would not be able to do anything with this for a couple of weeks as paying clients always come first and always will...that and i'm moving house so will be out of action for a couple of days.

Have a start yourself, really shouldn't be that difficult and should mainly be template changes within the produc.tpl file with changing the location of the form tags and the form action....html stuff really. :D

This php script will cope with that input aswell as the multiple add to cart.

anoack 04-25-2003 11:20 PM

Allright well cool I will get to work on that I will let you guys know how I do.

Thanks,

gfiebich 09-15-2005 12:57 PM

Has anyone implemented this mod on a 4.0.x site? If so, any code changes required?
thanks,
Glen

aop 12-28-2005 07:04 PM

Has anyone know if Funkydunk or Anoack finally implemented this Mod ?
In two years maybe someone else did it.
If anyone know about this Mod or something similar, please let me know.
I'll be happy to give my $ support.
Thanks !!

BodyBalance 04-28-2008 06:03 AM

Re: One page, add multiple quantities, of multiple products
 
Any chance someone has this working in 4.0.19? This is exactly what I am looking for.

agent9 04-30-2008 09:27 PM

Re: One page, add multiple quantities, of multiple products
 
I needed the same functionality and was told by xcart that the lite commerce version with the wholesale mod would work, and it does.

BodyBalance 05-07-2008 05:34 AM

Re: One page, add multiple quantities, of multiple products
 
I have never looked at lite commerce. Is there any possibility this could be modified to work with xcart? I already purchased the license for xcart.

agent9 05-07-2008 06:57 PM

Re: One page, add multiple quantities, of multiple products
 
Sorry but I have no idea.

ITVV 05-23-2008 06:12 AM

Re: One page, add multiple quantities, of multiple products
 
Hi Guys,

Has anyone managed to get this working on 4.1.7 please?

If so could you please be so kind as to post your code.

Is funkydunk still around these days?

Thanks all

Nick

intel352 05-26-2008 11:39 AM

Re: One page, add multiple quantities, of multiple products
 
BCSE has a mod where you can add all products listed on each page when browsing a Category.

Alternatively, you can set up a product with variants, and use the Variant Chart module (link in my signature), which shows each variant per row, along with options per variant, and wholesale prices per variant, with ability to add all listed variants to the cart, in whatever qty.


All times are GMT -8. The time now is 11:23 AM.

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