/// <summary>
        /// Maps the <see cref="OfferComponentDefinition"/> to a <see cref="OfferComponentConfiguration"/> so
        /// that it can be serialized and saved to the database as JSON more easily.
        /// </summary>
        /// <param name="definition">
        /// The definition.
        /// </param>
        /// <returns>
        /// The <see cref="OfferComponentConfiguration"/>.
        /// </returns>
        internal static OfferComponentConfiguration AsOfferComponentConfiguration(this OfferComponentDefinition definition)
        {
            if (!OfferComponentResolver.HasCurrent)
            {
                throw new NullReferenceException("The OfferComponentResolver singleton has not been instantiated");
            }

            var type = OfferComponentResolver.Current.GetTypeByComponentKey(definition.ComponentKey);

            if (type != null)
            {
                return(new OfferComponentConfiguration()
                {
                    OfferSettingsKey = definition.OfferSettingsKey,
                    OfferCode = definition.OfferCode,
                    ComponentKey = definition.ComponentKey,
                    TypeFullName = type.FullName,
                    Values = definition.ExtendedData.AsEnumerable().ToArray()
                });
            }

            var nullRef = new NullReferenceException("Was not able to resolve the OfferComponentType with key: " + definition.ComponentKey);

            LogHelper.Error(typeof(OfferComponentDefinitionExtensions), "Unable to resolve OfferCompoent", nullRef);
            throw nullRef;
        }
Beispiel #2
0
        /// <summary>
        /// Gets an instantiated offer component by it's definition.
        /// </summary>
        /// <param name="definition">
        /// The definition.
        /// </param>
        /// <returns>
        /// The <see cref="OfferComponentBase"/>.
        /// </returns>
        public OfferComponentBase GetOfferComponent(OfferComponentDefinition definition)
        {
            var type    = this.GetTypeByComponentKey(definition.ComponentKey);
            var ctlArgs = new object[] { definition };

            var attempt = ActivatorHelper.CreateInstance <OfferComponentBase>(type, ctlArgs);

            return(attempt.Success ? attempt.Result : null);
        }
Beispiel #3
0
        /// <summary>
        /// The get offer component.
        /// </summary>
        /// <param name="definition">
        /// The definition.
        /// </param>
        /// <typeparam name="T">
        /// The type of component to be returned
        /// </typeparam>
        /// <returns>
        /// The <see cref="T"/>.
        /// </returns>
        /// <remarks>
        /// TODO decide if this should be removed - probably be more useful if it did not require a definition
        /// and simply returned an new instantion of the type T
        /// </remarks>
        internal T GetOfferComponent <T>(OfferComponentDefinition definition) where T : OfferComponentBase
        {
            var typeOfT = typeof(T);
            var type    = _instanceTypes.FirstOrDefault(x => x.IsAssignableFrom(typeOfT));

            if (type == null)
            {
                return(null);
            }

            var ctlArgs = new object[] { definition };

            var attempt = ActivatorHelper.CreateInstance <OfferComponentBase>(type, ctlArgs);

            return(attempt.Success ? attempt.Result as T : null);
        }
        public void Can_Resolve_An_OfferComponent_By_Type()
        {
            var config = new OfferComponentConfiguration()
                             {
                                 ComponentKey =
                                     new Guid("A035E592-5D09-40BD-BFF6-73C3A4E9DDA2"),
                                 TypeFullName = typeof(OneCouponPerCustomerConstraint).Name,
                                 Values =   Enumerable.Empty<KeyValuePair<string, string>>()
                             };

            var definition = new OfferComponentDefinition(config);

            var resolved = _resolver.GetOfferComponent<OneCouponPerCustomerConstraint>(definition);

            Assert.NotNull(resolved);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CouponDiscountLineItemReward"/> class.
 /// </summary>
 /// <param name="definition">
 /// The <see cref="OfferComponentDefinition"/>.
 /// </param>
 public CouponDiscountLineItemReward(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferConstraintComponentBase"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 protected OfferConstraintComponentBase(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotUsableWithOtherCouponsConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The <see cref="OfferComponentDefinition"/>.
 /// </param>
 public NotUsableWithOtherCouponsConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MaximumQuantityConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public MaximumQuantityConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OfferComponentBase"/> class.
        /// </summary>
        /// <param name="definition">
        /// The <see cref="OfferComponentDefinition"/>.
        /// </param>
        protected OfferComponentBase(OfferComponentDefinition definition)
        {
            Mandate.ParameterNotNull(definition, "definition");

            this._definition = definition;
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OfferComponentBase"/> class.
        /// </summary>
        /// <param name="definition">
        /// The <see cref="OfferComponentDefinition"/>.
        /// </param>
        protected OfferComponentBase(OfferComponentDefinition definition)
        {
            Mandate.ParameterNotNull(definition, "definition");

            this._definition = definition;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionPriceRulesConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public CollectionPriceRulesConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExcludeTaxesIncludedInProductPrices"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public ExcludeTaxesIncludedInProductPrices(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotUsableByAnonymousCustomersConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public NotUsableByAnonymousCustomersConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MaximumNumberOfRedemptionsConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public MaximumNumberOfRedemptionsConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionAlterationCouponConstraintBase"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 protected CollectionAlterationCouponConstraintBase(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LineItemQuantityFilterRulesConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public LineItemQuantityFilterRulesConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductSelectionFilterConstraint"/> class.
 /// </summary>
 /// <param name="settings">
 /// The settings.
 /// </param>
 public ProductSelectionFilterConstraint(OfferComponentDefinition settings)
     : base(settings)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OneCouponPerCustomerConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The <see cref="OfferComponentDefinition"/>.
 /// </param>
 public OneCouponPerCustomerConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CouponFreeShippingReward"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public CouponFreeShippingReward(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionQuantityRulesConstraint"/> class. 
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public CollectionQuantityRulesConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExcludeShippingCostConstraint"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 public ExcludeShippingCostConstraint(OfferComponentDefinition definition)
     : base(definition)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferRewardComponentBase"/> class.
 /// </summary>
 /// <param name="definition">
 /// The definition.
 /// </param>
 protected OfferRewardComponentBase(OfferComponentDefinition definition)
     : base(definition)
 {
 }