Custom ordering configuration

davidzupecdavidzupec Member
in Help edited October 2014
Hello, in my code directly below I have it configured so that if a user orders 6 or more beverages they get a price discount that equals a free one. It works fine when they order 6 or more of the same beverage but if they order 4 of one beverage and 2 of another beverage it doesn't work even though they have a total of 6 in their cart. I thought I had it working properly in the 1.0 Version but now I have the 2.0 Version. Any suggestions as to how I can make the latter scenario work? Thank you!

 var beverages  = 0;
    var multiplier = 1;
    for ( var p = 0; p < FC.json.items.length; p++ ) {
      switch ( FC.json.items[p].category ) {
        case "BEVERAGE":
          beverages += FC.json.items[p].quantity;
    if ( beverages > 0 ) { 
      multiplier = Math.ceil( beverages / 6 ); // 1-6 > 1, 7-12 > 2, 13-18 > 3, etc
      FC.customLiveShipping.update('all', '+' + ( multiplier * 13 ) );
      FC.customLiveShipping.update(60, 0);
    var zip = FC.json.shipping_address.postal_code;
    var valid_zips = [11201,11203,11207,11211,11220,11206,10026,10001,10029,10010,10012,10004,10002,10021,10023,10031,11361,11354,11365,11412,11101,11374,11691,11004,11414,11368,11414,11368,11732,11581,11590,11213,11214,11218,11236,11224,11205,11210,11208,11222,11232,11221,10027,10011,10035,10016,10013,10005,10003,10028,10024,10032,11362,11355,11366,11423,11102,11375,11692,11005,11415,11369,11415,11369,11771,11582,11593,11216,11228,11219,11239,11229,11215,11225,11237,10030,10018,10017,10014,10006,10009,10044,10025,10033,11363,11356,11367,11432,11103,11379,11693,11411,11416,11370,11416,11370,11583,11594,11233,11230,11235,11217,11226,10037,10019,10022,10007,10128,10034,11364,11357,11433,11104,11385,11694,11413,11417,11372,11417,11372,11595,11238,11231,10039,10020,10038,10040,11358,11434,11105,11695,11422,11418,11373,11418,11373,11597,10036,10280,11359,11435,11106,11697,11426,11419,11377,11419,11377,11360,11436,11427,11420,11378,11420,11378,11428,11421,11421,11429];

  • fc_adamfc_adam FoxyCart Team

    Are all your different drinks within the same "BEVERAGE" category?
  • Hi fc_adam, yes there are only 2 different drinks and they're in the same beverage category.

    Thank you!
  • fc_adamfc_adam FoxyCart Team

    Could you link me to your store so I can take a look and add them and try it out please? Feel free to whisper if you want to keep it private.
  • fc_adamfc_adam FoxyCart Team
    @davidzupec - Ah ok. So you're talking about the discount applied to the products - which doesn't actually relate to the javascript you posted. That is related to the shipping snippet.

    The reason you're not seeing the discount apply across both products is because you're using a product level discount (added as part of the add to cart forms). Product level discounts will only apply to a single product. What you're needing is to apply that discount on the "BEVERAGE" category directly for a category level discount - which will then apply to any products within that category.

    To do that, you'd need to remove the discount in your forms, and instead navigate to the category in your store's administration, and set up the discount there.
  • Hi fc_adam, on my admin in the category section I do already have the discount set up in there as well. In my javascript the way it works is every 6 products gives you a discount of one free. So if they ordered 12 they would get 2 free, if they ordered 18 then 3 free and so forth.
  • fc_adamfc_adam FoxyCart Team

    You do have a discount on the default category, but not one on your "BEVERAGE" category.

    Could you point me to the javascript you're referring to that should be providing a discount? The javascript you pasted in your initial post relates to setting the shipping cost based on the quantity of products.
  • davidzupecdavidzupec Member
    edited October 2014
    Hi @fc_adam, my apologies I thought that javascript I was referring to in my code is what handled the discount. Do I then need to use that same discount code for the default category and put it into my beverage category in order for it to work?

    Thank you,
  • fc_adamfc_adam FoxyCart Team

    That's correct - you'll need to apply the category discount to the "BEVERAGE" category for that to apply to the products within that category.
Sign In or Register to comment.