Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicolaj Kirkgaard Nielsen 4 posts 25 karma points
    Aug 06, 2015 @ 07:15
    Nicolaj Kirkgaard Nielsen
    0

    Getting free shipping rule values in basket

    Hello!

    I've set up TeaCommerce to apply free shipping on orders over xxx amount, by creating an order amount rule in the Marketing section. This works great and also allows me to differentiate the cutoff based on the selected currency like I wanted.

    Now I want to display to the user what the cutoff point is for the selected currency ("Free shipping for orders over xxx"). How do I do this?

  • Anders Burla 2560 posts 8256 karma points
    Aug 06, 2015 @ 10:51
    Anders Burla
    0

    There is no API to fetch this information as the marketing system is really generic and have loads of possibilities. What you can do is properly to fetch the specific campaign using the CampaignService and then loop the rules and find your rule and the currency settings for it and use that to print on the webshop.

  • Nicolaj Kirkgaard Nielsen 4 posts 25 karma points
    Aug 07, 2015 @ 08:26
    Nicolaj Kirkgaard Nielsen
    1

    After alot of noodeling i figured this out. I'll post the code here for anyone else wanting to do this:

        public decimal getCurrentFreeShippingLimit() {
    
            // Get the campaign by name
            IEnumerable<Campaign> campaigns = CampaignService.Instance.GetAllActive(storeId).Where(campaign => (campaign.Name == "Gratis fragt"));
            Campaign freeShipping = campaigns.First();
    
            // Get the first rule of the first group
            OrderAmountRule rule = (OrderAmountRule)freeShipping.RulesGroups.First().Rules.First();
    
            // Get the rule that corresponds to the current currency
            Currency currency = TC.GetCurrentCurrency(storeId);
            KeyValuePair<long, decimal> shippingAmonut = rule.Amounts.Where(amount => amount.Key == currency.Id).First();
    
            // Output the value, ie. the free shipping cutoff point
            return shippingAmonut.Value;
    
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft