1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Anybody familiar with simpleCart.js?

Discussion in 'JavaScript' started by KangBroke, Sep 6, 2014.

  1. #1
    I have this snippit of code below, And when I try to add a XX item to the store, it is adding $9 to the price not $2.00
    When I add a XXX item it is adding $12 to the item.

    I have never really learned much javascript, and this is my first time fooling with simpleCart.JS

    The documentation is right here.
    http://simplecartjs.org/documentation/beforeadd-event

    Any Help is appreciated.


    
    simpleCart.bind( 'beforeAdd' , function( item ){
    
    if( item.get( 'size' ) == 'XX'){
    item.price( item.price() + 2.00 );
    }
    if( item.get( 'size' ) == 'XXX'){
    item.price( item.price() + 3.00 );
    }
    if( item.get( 'size' ) == 'XXXX'){
    item.price( item.price() + 4.00 );
    }
    });
    Code (JavaScript):
     
    KangBroke, Sep 6, 2014 IP
  2. seductiveapps.com

    seductiveapps.com Active Member

    Messages:
    200
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    looks like your item.price() is a getter+setter function, so you could be (probably are) updating the central storage location of the item's price each time this set of IFs gets called with a new item to add to the basket..

    what you need to do is to replace "item.price()" with the variable containing the base price of the item in question (which you should have somewhere, so stick that in a global "inventory" array of items for the entire webshop)
     
    seductiveapps.com, Nov 16, 2014 IP