-
Help w/PayPal Shopping Cart in AS2
Edit - Mods, you can delete this. I got it figured out.
Hi - I am using a Flash AS2 template for a PayPal shopping cart on my site. As the code is now, a new shipping charge is added to the buyers total for every item added. I would like it to have only 1 shipping charge, no matter how many items are added!
Below is the code for the cart.. any help is greatly appreciated.
Actionscript Code:
import caurina.transitions.Tweener; cartItems = new Array(); itemNr = -1; itemQty = 1;
cartin = false; ctrl_mc.cart_mc.onRelease = showCart; attachMovie("cart","cart_mc",15000,{_x:Stage.width}); cart_mc.title_txt.autoSize = true; cart_mc.title_txt.text = "YOUR CART IS EMPTY !"; cart_mc.bg_mc._height = cart_mc.title_txt._y+cart_mc.title_txt._height+15; cart_mc.bg_mc._width = cart_mc.title_txt._width+100; cart_mc._y = (Stage.height-cart_mc.bg_mc._height)/2;
totalprice = 0; totalship = 0; cart_mc.createEmptyMovieClip("cartitems_mc",10); cart_mc.cartitems_mc._y = cart_mc.title_txt._y+65; cart_mc.cartitems_mc._x = cart_mc.title_txt._x; cart_mc.close_mc._x = cart_mc.bg_mc._width-45;
cartLoader = new MovieClipLoader(); cartLst = new Object(); cartLst.onLoadInit = resizeCartThumb; cartLoader.addListener(cartLst);
cartLength = 0;
function addToCart(itemId) { totalship += Math.floor(shipping*100)/100; cart_mc.total_mc.ship_txt.text = "SHIPPING: "+currency+totalship; sameItem = false; itemCode = _global.itemPrefix+"_"+titles[itemId]+"_"+itemId; if (cartLength>0) { for (i=0; i<cartLength; i++) { if (cartItems[i][0] == itemCode) { cartItems[i][1]++; cart_mc.cartitems_mc["c"+i].minus_mc._visible = true; cart_mc.cartitems_mc["c"+i].qty_txt.text = cartItems[i][1]; cart_mc.cartitems_mc["c"+i].price_txt.text = currency+Math.floor(cartItems[i][2]*cartItems[i][1]*100)/100; totalprice += Number(cartItems[i][2]); gtotal = totalprice+totalship; cart_mc.total_mc.subtotal_txt.text = "ITEM TOTAL: "+currency+totalprice; cart_mc.total_mc.total_txt.text = "TOTAL: "+currency+gtotal; sameItem = true; } else if (i == cartLength-1 && sameItem != true) { itemNr++; cartItems[itemNr] = [itemCode, itemQty, prices[itemId], titles[itemId], thumbs[itemId]]; cart_mc.cartitems_mc.attachMovie("cartSample","c"+itemNr,itemNr,{_y:itemNr*45, id:itemNr}); cart_mc.cartitems_mc["c"+itemNr].title_txt.text = (itemNr+1)+". "+cartItems[itemNr][3]; cart_mc.cartitems_mc["c"+itemNr].qty_txt.text = cartItems[itemNr][1]; cart_mc.cartitems_mc["c"+itemNr].uprice_txt.text = currency+Math.floor(cartItems[itemNr][2]*100)/100; cart_mc.cartitems_mc["c"+itemNr].price_txt.text = currency+Math.floor(cartItems[itemNr][2]*cartItems[itemNr][1]*100)/100; totalprice += Number(cartItems[itemNr][2]); gtotal = totalprice+totalship; cart_mc.total_mc.subtotal_txt.text = "ITEM TOTAL: "+currency+totalprice; cart_mc.total_mc.total_txt.text = "TOTAL: "+currency+gtotal;
if (itemNr>=7) { cart_mc.enableScroll(cart_mc.cartitems_mc); } else if (itemNr<7) { cart_mc.total_mc._y = cart_mc.cartitems_mc._height+80; Tweener.addTween(cart_mc,{_y:(sh-((cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125))/2, time:.5}); Tweener.addTween(cart_mc.bg_mc,{_height:(cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125, time:.5}); } cartLoader.loadClip(cartItems[itemNr][4],cart_mc.cartitems_mc["c"+itemNr].image_mc); } } } else { cart_mc.title_txt.text = "ITEMS IN CART"; cart_mc.total_mc._visible = true; cart_mc.linedesc_mc._visible = true; itemNr++; cartItems[itemNr] = [itemCode, itemQty, prices[itemId], titles[itemId], thumbs[itemId]]; cart_mc.cartitems_mc.attachMovie("cartSample","c"+0,0,{_y:0*45, id:0}); cart_mc.cartitems_mc["c"+0].title_txt.text = 1+". "+cartItems[0][3]; cart_mc.cartitems_mc["c"+0].qty_txt.text = cartItems[0][1]; cart_mc.cartitems_mc["c"+0].uprice_txt.text = currency+Math.floor(cartItems[0][2]*100)/100; cart_mc.cartitems_mc["c"+0].price_txt.text = currency+Math.floor(cartItems[0][2]*cartItems[0][1]*100)/100; totalprice += Number(cartItems[0][2]); gtotal = totalprice+totalship; cart_mc.total_mc.subtotal_txt.text = "ITEM TOTAL: "+currency+totalprice; cart_mc.total_mc.total_txt.text = "TOTAL: "+currency+gtotal; cart_mc.total_mc._y = cart_mc.cartitems_mc._height+80; Tweener.addTween(cart_mc.close_mc,{_x:cart_mc.cartitems_mc["c"+0]._width+25, time:.5}); if (cartin != true) { Tweener.addTween(cart_mc,{_y:(sh-((cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125))/2, time:.5}); } else { Tweener.addTween(cart_mc,{_x:sw-cart_mc.cartitems_mc["c"+0]._width-65, _y:(sh-((cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125))/2, time:.5}); } Tweener.addTween(cart_mc.bg_mc,{_width:cart_mc.cartitems_mc["c"+0]._width+65, _height:(cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125, time:.5}); cartLoader.loadClip(cartItems[0][4],cart_mc.cartitems_mc["c"+0].image_mc); } cartLength = cartItems.length; }
function resizeCartThumb() { for (j=0; j<cartLength; j++) { cart_mc.cartitems_mc["c"+j].image_mc.forceSmoothing = true; cart_mc.cartitems_mc["c"+j].image_mc._width = 40; cart_mc.cartitems_mc["c"+j].image_mc._height = 40; } }
function showCart() { cartin = true; big_mc.enabled = false; removeInfo(); Tweener.addTween(cart_mc,{time:.7, _x:sw-cart_mc.bg_mc._width, transition:"easeOutBack"}); } function hideCart() { cartin = false; big_mc.enabled = true; Tweener.addTween(cart_mc,{time:.7, _x:sw, transition:"easeOutBack"}); }
updateItem = function (toUpdate, totship) { cart_mc.cartitems_mc["c"+toUpdate].qty_txt.text = cartItems[toUpdate][1]; cart_mc.cartitems_mc["c"+toUpdate].price_txt.text = currency+cartItems[toUpdate][2]*cartItems[toUpdate][1]; gtotal = totalprice+totship; cart_mc.total_mc.subtotal_txt.text = "ITEM TOTAL: "+currency+totalprice; cart_mc.total_mc.total_txt.text = "TOTAL: "+currency+gtotal; cart_mc.total_mc.ship_txt.text = "SHIPPING: "+currency+totship; };
function updateCart(toDelete, totship, totprice) { removeMovieClip(cart_mc.cartitems_mc["c"+toDelete]); totship = Math.floor(totship*100)/100; totprice = Math.floor(totprice*100)/100; gtotal = totprice+totship; if (totship == 0) { cart_mc.total_mc._visible = false; cart_mc.linedesc_mc._visible = false; cart_mc.title_txt.text = "YOUR CART IS EMPTY !"; Tweener.addTween(cart_mc.bg_mc,{_height:cart_mc.title_txt._y+cart_mc.title_txt._height+15, time:.5}); cart_mc.bg_mc._width = cart_mc.title_txt._width+100; Tweener.addTween(cart_mc,{_x:sw-cart_mc.bg_mc._width, _y:(sh-cart_mc.title_txt._y+cart_mc.title_txt._height+15)/2, time:.5}); Tweener.addTween(cart_mc.close_mc,{_x:cart_mc.bg_mc._width-45, time:.5}); totalprice = totalship=totship=0; cartLength = 0; itemNr--; } else { cart_mc.total_mc.subtotal_txt.text = "ITEM TOTAL: "+currency+totprice; cart_mc.total_mc.total_txt.text = "TOTAL: "+currency+gtotal; cart_mc.total_mc.ship_txt.text = "SHIPPING: "+currency+totship; cartItems.splice(toDelete,1); itemNr--; for (k=toDelete+1; k<cartLength; k++) { cart_mc.cartitems_mc["c"+k].swapDepths(k-1); cart_mc.cartitems_mc["c"+k].id = (k-1); cart_mc.cartitems_mc["c"+k].title_txt.text = k+". "+cartItems[k-1][3]; cart_mc.cartitems_mc["c"+k]._y -= 45; cart_mc.cartitems_mc["c"+k]._name = "c"+(k-1); } cartLength = cartItems.length; if (itemNr>=7) { cart_mc.enableScroll(cart_mc.cartitems_mc); } else if (itemNr<7) { cart_mc.disableScroll(); cart_mc.total_mc._y = cart_mc.cartitems_mc._height+80; Tweener.addTween(cart_mc,{_y:(sh-((cart_mc.title_txt._y*2)+45*itemNr+125))/2, time:.5}); Tweener.addTween(cart_mc.bg_mc,{_height:(cart_mc.title_txt._y*2)+cart_mc.cartitems_mc._height+125, time:.5}); } } }
According to PayPal's site:
Number of items. If profile-based shipping rates are configured with a basis of quantity, the sum of quantity values is used to calculate the shipping charges for the transaction. PayPal appends a sequence number to uniquely identify the item in the PayPal Shopping Cart (e.g., quantity1, quantity2). Note: The value for quantity must be a positive integer. Null, zero, or negative numbers are not allowed.
This is also the code for PayPal Checkout:
function checkOut() {
var paypal = new LoadVars();
paypal.cmd = "_xclick";
paypal.cmd = "_cart";
paypal.upload = "1";
paypal.handling = "0";
for (pp=0; pp<=_root.cartLength-1; pp++) {
paypal["item_name_"+(pp+1)] = cartItems[pp][3];
paypal["quantity_"+(pp+1)] = cartItems[pp][1];
paypal["amount_"+(pp+1)] = cartItems[pp][2]
}
paypal.business = payedto;
paypal.currency_code = currcode;
paypal.shipping_1 = totalship;
paypal.send("https://www.paypal.com/cgi-bin/webscr","POST");
}
Last edited by AlxSTi; 01-21-2011 at 01:43 PM.
-
Senior Member
glad it all worked out for you.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|