Copied to clipboard

Flag this post as spam?

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


  • René Pjengaard 100 posts 609 karma points c-trib
    Oct 30, 2018 @ 13:41
    René Pjengaard
    0

    Add order property value to award

    Hi Tea Commerce,

    is it possible to give an award based on a order property?

    Let´s say that i have added a property named "fixeddiscountpct", and the value is 7. I then create a rule under Markering, checking for the "fixeddiscountpct" property > 0.

    In the awards section i wan´t to add the value from the "fixeddiscountpct" property. Is this possible?

    enter image description here

    Best regards René

  • Rune Grønkjær 1294 posts 2856 karma points
    Oct 30, 2018 @ 15:01
    Rune Grønkjær
    0

    Hi René,

    To do that you would need to create a custom award. It's pretty simple to do so. You can check out how Tea Commerce for Umbraco is doing it: https://github.com/TeaCommerce/Tea-Commerce-for-Umbraco/tree/master/Source/TeaCommerce.Umbraco.Configuration/Marketing/Models/Awards

    And the front end stuff: https://github.com/TeaCommerce/Tea-Commerce-for-Umbraco/tree/master/Source/TeaCommerce.Umbraco.Application/Marketing/Awards/OrderLineAmountAward

    You just make your own and apply whatever discount you need.

    /Rune

  • René Pjengaard 100 posts 609 karma points c-trib
    Oct 30, 2018 @ 15:34
    René Pjengaard
    0

    Hi Rune,

    thank you for the answer. Do you have an example for a Order Amount Award? It doesn´t seem that there is a AOrderAmountAward to inherit from? Or am i missing something?

    /René

  • Rune Grønkjær 1294 posts 2856 karma points
    Oct 31, 2018 @ 06:54
    Rune Grønkjær
    100

    The standard order amount award looks like this:

    using Newtonsoft.Json;
    using System.Collections.Generic;
    using System.Linq;
    using TeaCommerce.Api.Common;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.Services;
    
    namespace TeaCommerce.Api.Marketing.Models.Awards {
    
      [Award( "OrderAmountAward" )]
      public class OrderAmountAward : AAward, IOrderAward {
    
        public OrderAmountAwardType Type { get; set; }
    
        public bool UsePercentage { get; set; }
        public decimal? Percentage { get; set; }
        public IDictionary<long, decimal> Amounts { get; set; }
    
        public OrderAmountAward() {
          Amounts = new Dictionary<long, decimal>();
        }
    
        public override void LoadSettings() {
          var settings = JsonConvert.DeserializeAnonymousType( Settings, new { Type = OrderAmountAwardType.SubtotalPrice, UsePercentage = "true", Percentage = "", Amounts = new Dictionary<long, string>() } );
    
          if ( settings == null ) return;
    
          Type = settings.Type;
          UsePercentage = bool.Parse( settings.UsePercentage );
          Percentage = settings.Percentage.ParseToDecimal();
          if ( Percentage != null ) {
            Percentage = Percentage.Value / 100M;
          }
          if ( settings.Amounts != null ) {
            Amounts = settings.Amounts.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.ParseToDecimal() ?? 0M );
          }
        }
    
        public void ApplyTo( Order order, Campaign campaign ) {
          order.MustNotBeNull( "order" );
          campaign.MustNotBeNull( "campaign" );
    
          Currency currency = CurrencyService.Instance.Get( order.StoreId, order.CurrencyId );
    
          if ( UsePercentage && Percentage != null && Percentage.Value > 0 ) {
    
            if ( Type == OrderAmountAwardType.SubtotalPrice ) {
              order.SubtotalPrice.Discounts.Add( new Discount( campaign.Name, order.SubtotalPrice.Value.Value * Percentage.Value, order.SubtotalPrice.Value.Vat * Percentage.Value, order.SubtotalPrice.Value.WithVat * Percentage.Value, currency ) );
            } else if ( Type == OrderAmountAwardType.ShipmentPrice ) {
              order.ShipmentInformation.TotalPrice.Discounts.Add( new Discount( campaign.Name, order.ShipmentInformation.TotalPrice.Value.Value * Percentage.Value, order.ShipmentInformation.TotalPrice.Value.Vat * Percentage.Value, order.ShipmentInformation.TotalPrice.Value.WithVat * Percentage.Value, currency ) );
            } else if ( Type == OrderAmountAwardType.PaymentPrice ) {
              order.PaymentInformation.TotalPrice.Discounts.Add( new Discount( campaign.Name, order.PaymentInformation.TotalPrice.Value.Value * Percentage.Value, order.PaymentInformation.TotalPrice.Value.Vat * Percentage.Value, order.PaymentInformation.TotalPrice.Value.WithVat * Percentage.Value, currency ) );
            } else if ( Type == OrderAmountAwardType.TotalPrice ) {
              order.TotalPrice.Discounts.Add( new Discount( campaign.Name, order.TotalPrice.WithDiscounts.Value * Percentage.Value, order.TotalPrice.WithDiscounts.Vat * Percentage.Value, order.TotalPrice.WithDiscounts.WithVat * Percentage.Value, currency ) );
            }
          } else if ( Amounts.ContainsKey( order.CurrencyId ) ) {
            decimal amount = Amounts[ order.CurrencyId ];
    
            if ( amount > 0m ) {
              if ( Type == OrderAmountAwardType.SubtotalPrice ) {
                order.SubtotalPrice.Discounts.Add( new Discount( campaign.Name, amount, order.VatRate, currency ) );
              } else if ( Type == OrderAmountAwardType.ShipmentPrice ) {
                order.ShipmentInformation.TotalPrice.Discounts.Add( new Discount( campaign.Name, amount, order.ShipmentInformation.VatRate, currency ) );
              } else if ( Type == OrderAmountAwardType.PaymentPrice ) {
                order.PaymentInformation.TotalPrice.Discounts.Add( new Discount( campaign.Name, amount, order.PaymentInformation.VatRate, currency ) );
              } else if ( Type == OrderAmountAwardType.TotalPrice ) {
                order.TotalPrice.Discounts.Add( new Discount( campaign.Name, amount, order.VatRate, currency ) );
              }
            }
          }
        }
      }
    }
    
  • René Pjengaard 100 posts 609 karma points c-trib
    Oct 31, 2018 @ 11:55
    René Pjengaard
    0

    Thanks Rune,

    now i´m right on track!

    /René

  • Rune Grønkjær 1294 posts 2856 karma points
    Oct 31, 2018 @ 12:03
    Rune Grønkjær
    0

    Good to hear :)

Please Sign in or register to post replies

Write your reply to:

Draft