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

One page, add multiple quantities, of multiple products

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-24-2003, 11:44 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default 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.
Reply With Quote
  #2  
Old 04-24-2003, 12:04 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

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.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #3  
Old 04-24-2003, 12:08 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

It will be done, oh yes, it will be done. And if I build it, they will order.
Reply With Quote
  #4  
Old 04-24-2003, 01:56 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

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.
__________________
ex x-cart guru
Reply With Quote
  #5  
Old 04-24-2003, 02:52 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Mind sharing
Reply With Quote
  #6  
Old 04-24-2003, 03:24 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #7  
Old 04-25-2003, 12:44 AM
  anoack's Avatar 
anoack anoack is offline
 

Senior Member
  
Join Date: Dec 2002
Location: Austin, TX
Posts: 113
 

Default

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
Reply With Quote
  #8  
Old 04-25-2003, 01:15 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

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

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

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.
__________________
ex x-cart guru
Reply With Quote
  #9  
Old 04-25-2003, 07:32 AM
  anoack's Avatar 
anoack anoack is offline
 

Senior Member
  
Join Date: Dec 2002
Location: Austin, TX
Posts: 113
 

Default

Your a Saint!

Thanks allot man!
Reply With Quote
  #10  
Old 04-25-2003, 07:46 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

presume it worked then?
__________________
ex x-cart guru
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


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 10:24 PM.

   

 
X-Cart forums © 2001-2020