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

Add multiple products to cart

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-19-2004, 07:18 AM
 
funkydunk funkydunk is offline
 

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

Default Add multiple products to cart

As it is my birthday tomorrow (cakes appreciated)

Here is a little mod that allows you to run the product listing page as an order form where the visitor can add in amounts for several products at a time and have them all added to the cart simultaeneously.

First of all create a new php script in customer: add_multiple.php

Code:
<?php // add_multiple.php funkydunk 2004 require "./auth.php"; include $xcart_dir."/shipping/shipping.php"; //include "./nocookie_warning.php"; x_session_register("cart"); x_session_register("intershipper_rates"); x_session_register("intershipper_recalc"); x_session_unregister("secure_oid"); x_session_register("extended_userinfo"); x_session_register("anonymous_checkout"); # # $order_secureid (for security reasons) # x_session_register("order_secureid"); # # Loop through products and add to cart # code taken from cart.php if ($amount) { foreach ($amount as $key=>$value) { $productid = $key; $amount = $value; $added_product = func_select_product($productid, (!empty($user_account['membership'])?$user_account['membership']:""), false, true); $amount = abs(intval($amount)); # # Add to cart amount of items that is not much than in stock # if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C") if ($amount > $added_product["avail"]) $amount = $added_product["avail"]; if ($productid && $amount) { if ($amount < $added_product["min_amount"]) { func_header_location ("error_message.php?minimum_amount"); } # # 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; $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; } } } if (!$found) { # # Add product to the cart # if (!empty($price)) # price value is defined by customer if admin set it to '0.00' $free_price = abs(doubleval($price)); $cartid = func_generate_cartid($cart["products"]); $cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$options, "free_price"=>@price_format(@$free_price)); if(!empty($active_modules["Product_Configurator"])) include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php"; } $intershipper_recalc = "Y"; } } } // end of loop to add all products to the cart # # Redirect # /* if($mode=="add" and $productid) { if($config["General"]["redirect_to_cart"]=="Y") func_header_location("cart.php"); else func_header_location("home.php?cat=$cat&page=$page"); } */ func_header_location("cart.php"); x_session_save(); $smarty->display("customer/home.tpl"); ?>

Then create two language fields:
err_minimum_amount
err_minimum_amount_txt

These will be shown at the top of the error page that is shown if the user does not order enough of something as follows:

Then create a new template in skin1/main/minimum_amount.tpl :
Code:
{* minimum_amount.tpl - funkydunk 2004 *} { include file="location.tpl" last_location=$lng.err_minimum_amount} {$lng.err_minimum_amount_txt}

Then amend skin1/common_templates.tpl by inserting:

Code:
{* new funkydunk *} {elseif $main eq "minimum_amount"} {include file="main/minimum_amount.tpl"} {* end *}

before the final {else}

Then amend the products.tpl and products_t.tpl as follows:
(this is the code for products.tpl without images but you can get the idea from this

Code:
{* $Id: products.tpl,v 1.36 2003/11/11 14:02:37 svowl Exp $ amended by funkydunk 2004 *} {if $usertype eq "C" and $config.Appearance.products_per_row ne "" and $config.Appearance.products_per_row gt 0 and $config.Appearance.products_per_row lt 4 and ($featured eq "Y" or $config.Appearance.featured_only_multicolumn eq "N")} {include file="customer/main/products_t.tpl" products=$products} {else} {if $products} <form action="add_multiple.php" method ="post" name="orderform"> <table border="0" width="100%" cellpadding="2" cellspacing="0" align="center"> <tr> <td valign="top" class="headerrow">product</td> <td valign="top" width="80" class="headerrow" align="right">price</td> <td valign="top" width="80" class="headerrow" align="center">info</td> <td valign="top" width="100" class="headerrow" align="center">quantity</td> </tr> {section name=product loop=$products} {counter assign="row"} <tr> <td valign="top" class="listrow"><a href=product.php?productid={$products[product].productid}>{$products[product].product}</a> {if $products[product].min_amount gt 1} <FONT class=small>({$lng.txt_need_min_amount} {$products[product].min_amount} {$lng.lbl_items})</FONT>{/if} </td> <td valign="top" width="80" class="listrow" nowrap align="right">{include file="currency.tpl" value=$products[product].price}</td> <td valign="top" width="80" class="listrow" align="center"><a href=product.php?productid={$products[product].productid}>[img]{$ImagesDir}/info.gif[/img]</a></td> <td valign="top" width="100" class="listrow" align="center"> {if ($active_modules.Product_Options ne "" and $products[product].product_options)} {else} <input type="text" size="4" maxlength="10" name="amount[{$products[product].productid}]" value="0"> {/if} </td> </tr> {/section} <tr> <td valign="top" colspan="4" align="right"> {if $js_enabled} {include file="buttons/button.tpl" button_title="ADD ALL TO CART" style="button"} {else} {include file="submit_wo_js.tpl" value="ADD ALL TO CART"} {/if} </td> </tr> </table> </form> {else} {$lng.lbl_no_products_found} {/if} {/if}


There are a few style sheets references in there that aren't standard but you should be able to get it working.

PLEASE NOTE THAT YOU SHOULD BACKUP BEFORE DOING ANY MODS FROM THE FORUM.


This was built for version 3.5.x gold but should work on Pro and may even work on 3.4 shops.

Have fun
__________________
ex x-cart guru
Reply With Quote
  #2  
Old 04-19-2004, 08:31 AM
  lyncca's Avatar 
lyncca lyncca is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Fort Worth, Texas
Posts: 455
 

Default

Thats really cool I wonder if I can find use for this somewhere!

But you know, on your birthday you aren't supposed to work or even the day before for that matter!

Have a great birthday \
Reply With Quote
  #3  
Old 04-19-2004, 08:45 AM
 
funkydunk funkydunk is offline
 

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

Default

day before is fine - the day after is the problem
__________________
ex x-cart guru
Reply With Quote
  #4  
Old 04-19-2004, 08:53 AM
  lyncca's Avatar 
lyncca lyncca is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Fort Worth, Texas
Posts: 455
 

Default



I think I would have to agree with you there.
Reply With Quote
  #5  
Old 04-19-2004, 09:55 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

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

Default

Funkydunk, happy b-day, this code work with product options?
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #6  
Old 04-19-2004, 10:50 AM
 
funkydunk funkydunk is offline
 

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

Default

it wont display the amount box if there are any if that is what you mean
__________________
ex x-cart guru
Reply With Quote
  #7  
Old 04-19-2004, 04:08 PM
 
jeeya jeeya is offline
 

X-Adept
  
Join Date: May 2003
Location: USA
Posts: 807
 

Default

Good Code! Happy B-Day Funky! What About Cake on B-Day?
__________________
X-Cart Version 4.1.8
Hosted on Linux
Reply With Quote
  #8  
Old 04-20-2004, 01:56 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

Happy Birthday Mate,

21 today eh

Make sure you have a day off
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #9  
Old 04-20-2004, 03:15 AM
 
funkydunk funkydunk is offline
 

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

Default

day off

moving to new offices today
__________________
ex x-cart guru
Reply With Quote
  #10  
Old 04-20-2004, 03:16 AM
 
funkydunk funkydunk is offline
 

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

Default

Quote:
Originally Posted by raxitpatel
Good Code! Happy B-Day Funky! What About Cake on B-Day?
yeah cakes can be sent to me if you really want :LOL
__________________
ex x-cart guru
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 02:02 AM.

   

 
X-Cart forums © 2001-2020