Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question combine shipping based on cart quantity and item name

    I am trying to combine shipping across different items in a javascript shopping cart. I can comine shipping based on how many items are in the cart, and characteristics of the item being added. But not both. I need the script to combine shipping based on how many items are in the cart, as well as the item name of the item being added to the cart.

    I assume I need to check the cart quantity in 1 function, then have it call 1 of 2 other functions based on how many items are in the cart. The 2nd function would charge the shipping based on the item name. I don't know if the code is wrong, and where I should put the 2 additional functions I am adding. It isn't working though.

    I am adding 2 ways I have tried below.

    Code:
    me.shipping = function(){
    
      switch(me.quantity){
        case '0':
          return 0;
        break;    
        case '1':
          return oneItemInCart();
        break;
        default: otherNumber;
          return moreThanOneItemInCart();
        break; 
    }
    
    function oneItemInCart();
    {
    if(item.name)
    {
    if(item.name.match = "Cricut Cartridge")
    return 4.39
    else if(item.name.match = "Glitter")
    return 5.00
    else
    return quantity*0.00;
    }
    }
    
    function moreThanOneItemInCart();
    {
    if(item.name)
    {
    if(item.name.match = "Cricut Cartridge")
    return item.quantity*3.00-3.00+4.39
    if(item.name.match = "Glitter")
    return item.quantity*4.00-4.00+5.00
    else
    return quantity*0.00;
    }
    }






    Code:
    	me.shipping = function(){
    		if( parseInt(me.quantity,10)===0 )
    			return 0;
    else if( parseInt(me.quantity,10)===1)
    			return oneItemInCart();
    else if( parseInt(me.quantity,10) > 1)
    			return moreThanOneItemInCart();
    else
    return quantity*0.00;
    
    function oneItemInCart();
    {
    if(item.name)
    {
    if(item.name.match = "Cricut Cartridge")
    return 4.39
    else if(item.name.match = "Glitter")
    return 5.00
    else
    return quantity*0.00;
    }
    }
    
    function moreThanOneItemInCart();
    {
    if(item.name)
    {
    if(item.name.match = "Cricut Cartridge")
    return item.quantity*3.00-3.00+4.39
    if(item.name.match = "Glitter")
    return item.quantity*4.00-4.00+5.00
    else
    return quantity*0.00;
    }
    }


    Here is the original document - the part I edited is the me.shipping part
    http://simplecartjs.com/
    Last edited by question123; 12-08-2010 at 08:54 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •