Пример #1
0
        public bool ProcessCartItemMatchCondition(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            bool resultFlag;
            bool isFound = condition.ItemFound.Value; // false = not found, true = found
            bool proceed = true;
            bool matched;
            bool decider = condition.IsAll.Value; //true = IsAll, false = IsAny

            for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
            {
                resultFlag = FindItem(items, condition.ChildOfferConditions[i], offeredItemIncluded);

                // does it match the expected?
                matched = isFound == resultFlag;

                // does it need to proceed?
                proceed = decider == matched;

                if (!proceed)
                {
                    break;
                }
            }

            // does it match the condition?
            return(decider == proceed);
        }
Пример #2
0
 private bool IsProductAttrCombination(OfferCondition condition)
 {
     return(condition.ItemFound.HasValue &&
            condition.IsAll.HasValue &&
            condition.IsAny.HasValue &&
            condition.Matched.HasValue);
 }
Пример #3
0
        private OfferRule BuildOfferRule(OfferRule rule)
        {
            var conditions = (List <OfferCondition>)GetOfferConditionListByOfferRuleId(rule.Id);

            if (conditions != null && conditions.Count > 0)
            {
                OfferCondition parent = conditions.Find(delegate(OfferCondition item) { return(item.ParentId == 0); });

                if (parent != null)
                {
                    rule.Condition = parent;
                    rule.Condition.ChildOfferConditions = BuildTreeOfferConditionInfoByParent(parent,
                                                                                              conditions,
                                                                                              parent.Id);
                }
            }

            rule.Action = GetOfferActionByOfferRuleId(rule.Id);

            rule.RelatedItems = _offerRelatedItemRepository.Table.Where(o => o.OfferRuleId == rule.Id).ToList();
            for (int i = 0; i < rule.RelatedItems.Count; i++)
            {
                var productId = rule.RelatedItems[i].ProductId;
                var product   = _productRepository.Table.Where(x => x.Id == productId)
                                .Select(x => new { x.Name, x.OptionType })
                                .FirstOrDefault();

                if (product != null)
                {
                    rule.RelatedItems[i].ProductName = product.Name;
                }
            }

            return(rule);
        }
Пример #4
0
        private OfferAction GetOfferActionByOfferRuleId(int offerRuleId)
        {
            OfferAction action = _offerActionRepository.Table.Where(a => a.OfferRuleId == offerRuleId).FirstOrDefault();

            if (action != null)
            {
                List <OfferCondition> conditions = (List <OfferCondition>)GetOfferConditionListByOfferActionId(action.Id);

                if (conditions != null && conditions.Count > 0)
                {
                    OfferCondition parent = conditions.Find(delegate(OfferCondition item) { return(item.ParentId == 0); });

                    if (parent != null)
                    {
                        action.Condition = parent;
                        action.Condition.ChildOfferConditions = BuildTreeOfferConditionInfoByParent(parent,
                                                                                                    conditions,
                                                                                                    parent.Id);
                    }
                }

                if (action.OptionOperator != null)
                {
                    action.OptionOperator = _offerOperatorRepository.Return(action.OptionOperatorId);
                }
            }

            return(action);
        }
Пример #5
0
        public IList <CartItem> GetMatchedConditionItems(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            var foundItems = items.Where(x =>
            {
                if (x.Product.OpenForOffer)
                {
                    if (offeredItemIncluded)
                    {
                        return(_attributeUtility.ValidateAttribute(
                                   _attributeUtility.GetAttributeValue(condition.OfferAttribute.Id, x.Product),
                                   condition.OfferOperator.Operator,
                                   condition.Operand));
                    }
                    else
                    {
                        // Exclude items with assigned offer rule id
                        if (x.ProductPrice.OfferRuleId <= 0)
                        {
                            return(_attributeUtility.ValidateAttribute(
                                       _attributeUtility.GetAttributeValue(condition.OfferAttribute.Id, x.Product),
                                       condition.OfferOperator.Operator,
                                       condition.Operand));
                        }
                        return(false);
                    }
                }
                return(false);
            })
                             .ToList();

            return(foundItems);
        }
Пример #6
0
        public bool ProcessCatalogAttributeCondition(OfferCondition condition, Product product)
        {
            var value = _attributeUtility.GetAttributeValue(condition.OfferAttribute.Id, product);

            return(_attributeUtility.ValidateAttribute(
                       value,
                       condition.OfferOperator.Operator,
                       condition.Operand));
        }
Пример #7
0
 private bool IsProductSubselection(OfferCondition condition)
 {
     return(condition.IsTotalQty.HasValue &&
            condition.IsTotalAmount.HasValue &&
            (condition.OfferOperator != null) &&
            condition.Operand != null &&
            condition.IsAll.HasValue &&
            condition.IsAny.HasValue &&
            condition.Matched.HasValue);
 }
Пример #8
0
        public bool ProcessCartSubselectionCondition(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            bool resultFlag;
            bool proceed    = true;
            bool isTotalQty = condition.IsTotalQty ?? false; // false = total amount, true = total quantity
            bool decider    = condition.IsAll ?? false;      //true = IsAll, false = IsAny

            int     qty    = 0;
            decimal amount = 0M;

            for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
            {
                if (isTotalQty)
                {
                    int resultQty = CalculateQty(items, condition.ChildOfferConditions[i], offeredItemIncluded);

                    if (decider == false)
                    {
                        qty += resultQty;
                    }
                    else
                    {
                        qty = resultQty;
                    }

                    resultFlag = _attributeUtility.ValidateAttribute(qty.ToString(), condition.OfferOperator.Operator, condition.Operand);
                }
                else
                {
                    decimal resultAmount = CalculateAmount(items, condition.ChildOfferConditions[i], offeredItemIncluded);

                    if (decider == false)
                    {
                        amount += resultAmount;
                    }
                    else
                    {
                        amount = resultAmount;
                    }

                    resultFlag = _attributeUtility.ValidateAttribute(amount.ToString(), condition.OfferOperator.Operator, condition.Operand);
                }

                // does it need to proceed?
                proceed = decider == resultFlag;

                if (!proceed)
                {
                    break;
                }
            }

            // does it match the condition?
            return(decider == proceed);
        }
Пример #9
0
        public bool ProcessCartCondition(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded, bool useInitialPrice)
        {
            if (condition == null)
            {
                return(false);
            }
            if (condition.Matched == null)
            {
                return(false);
            }
            bool resultFlag;
            bool expected = condition.Matched.Value;
            bool matched;
            bool proceed = true;
            bool decider = condition.IsAll.Value; //true = IsAll, false = IsAny

            for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
            {
                // process cart attribute / subselection / item matching condition
                switch (condition.ChildOfferConditions[i].Type)
                {
                case OfferConditionType.Attribute:
                    resultFlag = ProcessCartAttributeCondition(items, condition.ChildOfferConditions[i], offeredItemIncluded, useInitialPrice);
                    break;

                case OfferConditionType.Subselection:
                    resultFlag = ProcessCartSubselectionCondition(items, condition.ChildOfferConditions[i], offeredItemIncluded);
                    break;

                case OfferConditionType.ItemMatched:
                    resultFlag = ProcessCartItemMatchCondition(items, condition.ChildOfferConditions[i], offeredItemIncluded);
                    break;

                case OfferConditionType.None:
                default:
                    resultFlag = ProcessCartCondition(items, condition.ChildOfferConditions[i], offeredItemIncluded, useInitialPrice);
                    break;
                }

                // does it match the expected?
                matched = expected == resultFlag;

                // does it need to proceed?
                proceed = decider == matched;

                if (!proceed)
                {
                    break;
                }
            }

            // does it match the condition?
            return(decider == proceed);
        }
Пример #10
0
        public int CalculateQty(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            int qty          = 0;
            var matchedItems = GetMatchedConditionItems(items, condition, offeredItemIncluded);

            if (matchedItems != null)
            {
                qty = matchedItems.Select(x => x.Quantity).DefaultIfEmpty(0).Sum();
            }

            return(qty);
        }
Пример #11
0
        public decimal CalculateAmount(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            decimal amount       = 0M;
            var     matchedItems = GetMatchedConditionItems(items, condition, offeredItemIncluded);

            if (matchedItems != null)
            {
                amount = matchedItems.Select(x => x.Quantity * x.ProductPrice.OfferPriceInclTax).DefaultIfEmpty(0).Sum();
            }

            return(amount);
        }
Пример #12
0
        public bool ProcessCatalogCondition(int offerRuleId, OfferCondition condition, Product product)
        {
            if (condition == null)
            {
                _logger.InsertLog(LogLevel.Error, "Condition is null. Offer Rule ID={{{0}}}", offerRuleId);
                return(false);
            }

            if (product == null)
            {
                _logger.InsertLog(LogLevel.Error, "Product is null.");
                return(false);
            }

            bool resultFlag;
            bool expected = condition.Matched.Value;
            bool matched;
            bool proceed = true;
            bool decider = condition.IsAll.Value; //true = IsAll, false = IsAny

            for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
            {
                // process condition / attribute condition
                switch (condition.ChildOfferConditions[i].Type)
                {
                case OfferConditionType.Attribute:
                    resultFlag = ProcessCatalogAttributeCondition(condition.ChildOfferConditions[i], product);
                    break;

                case OfferConditionType.Subselection:
                case OfferConditionType.ItemMatched:
                case OfferConditionType.None:
                default:
                    resultFlag = ProcessCatalogCondition(offerRuleId, condition.ChildOfferConditions[i], product);
                    break;
                }

                // does it match the expected?
                matched = expected == resultFlag;

                // does it need to proceed?
                proceed = decider == matched;

                if (!proceed)
                {
                    break;
                }
            }

            // does it match the condition?
            return(decider == proceed);
        }
Пример #13
0
        private void InsertConditionWithOfferActionId(OfferCondition condition, int offerActionId, int parentId = 0)
        {
            condition.OfferActionId = offerActionId;
            condition.ParentId      = parentId;
            _offerConditionRepository.Create(condition);

            if (condition.ChildOfferConditions != null && condition.ChildOfferConditions.Count > 0)
            {
                foreach (var cond in condition.ChildOfferConditions)
                {
                    InsertConditionWithOfferActionId(cond, offerActionId, condition.Id);
                }
            }
        }
Пример #14
0
        private List <OfferCondition> BuildTreeOfferConditionInfoByParent(OfferCondition target,
                                                                          List <OfferCondition> conditions,
                                                                          int parentId)
        {
            List <OfferCondition> list = conditions.FindAll(delegate(OfferCondition cond) { return(cond.ParentId == parentId); });

            if (list != null && list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].ChildOfferConditions = BuildTreeOfferConditionInfoByParent(list[i], conditions, list[i].Id);
                }
            }

            return(list);
        }
Пример #15
0
 private void RemoveCondition(OfferCondition root, int nodeId)
 {
     if (root.ChildOfferConditions != null)
     {
         for (int i = 0; i < root.ChildOfferConditions.Count; i++)
         {
             if (root.ChildOfferConditions[i].Id == nodeId)
             {
                 root.ChildOfferConditions.Remove(root.ChildOfferConditions[i]);
                 break;
             }
             else
             {
                 RemoveCondition(root.ChildOfferConditions[i], nodeId);
             }
         }
     }
 }
Пример #16
0
        public bool ProcessCartActionCondition(OfferCondition condition, CartItem item)
        {
            bool resultFlag;
            bool expected = condition.Matched.Value;
            bool matched;
            bool proceed = true;
            bool decider = condition.IsAll.Value; //true = IsAll, false = IsAny

            for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
            {
                // process condition / attribute condition
                switch (condition.ChildOfferConditions[i].Type)
                {
                case OfferConditionType.Attribute:
                    resultFlag = ProcessCartActionAttributeCondition(condition.ChildOfferConditions[i], item);
                    break;

                case OfferConditionType.None:
                case OfferConditionType.Subselection:
                case OfferConditionType.ItemMatched:
                default:
                    resultFlag = ProcessCartActionCondition(condition.ChildOfferConditions[i], item);
                    break;
                }

                // does it match the expected?
                matched = expected == resultFlag;

                // does it need to proceed?
                proceed = decider == matched;

                if (!proceed)
                {
                    break;
                }
            }

            // does it match the condition?
            return(decider == proceed);
        }
Пример #17
0
        private OfferCondition SearchCondition(OfferCondition root, int nodeId)
        {
            if (root.Id == nodeId)
            {
                return(root);
            }

            OfferCondition foundCondition = null;

            if (root.ChildOfferConditions != null)
            {
                for (int i = 0; i < root.ChildOfferConditions.Count; i++)
                {
                    foundCondition = SearchCondition(root.ChildOfferConditions[i], nodeId);

                    if (foundCondition != null && foundCondition.Id == nodeId)
                    {
                        return(foundCondition);
                    }
                }
            }

            return(null);
        }
Пример #18
0
        private bool IsRelatedToOfferRule(OfferCondition condition, Product product)
        {
            foreach (var childCondition in condition.ChildOfferConditions)
            {
                if (childCondition.OfferAttribute != null)
                {
                    if (childCondition.OfferAttribute.IsCatalog)
                    {
                        bool matched = _attributeUtility.ValidateAttribute(
                            _attributeUtility.GetAttributeValue(childCondition.OfferAttribute.Id, product),
                            childCondition.OfferOperator.Operator,
                            childCondition.Operand);

                        if (matched)
                        {
                            return(true);
                        }
                    }
                    else if (childCondition.OfferAttribute.IsCart)
                    {
                        if (childCondition.ChildOfferConditions.Count > 0)
                        {
                            return(IsRelatedToOfferRule(childCondition, product));
                        }

                        // At the moment, we have "total amount" and "total quantity" attributes that has IsCart = true.
                        // Thus, we assume that this condition will always return true.
                        return(true);
                    }
                }

                return(IsRelatedToOfferRule(childCondition, product));
            }

            return(false);
        }
Пример #19
0
        public bool ProcessCartAttributeCondition(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded, bool useInitialPrice)
        {
            var value = _attributeUtility.GetAttributeValue(condition.OfferAttribute.Id, items, offeredItemIncluded, useInitialPrice, false);

            return(_attributeUtility.ValidateAttribute(value, condition.OfferOperator.Operator, condition.Operand));
        }
Пример #20
0
        public int CalculateActionMatchedQty(IList <CartItem> items, OfferRule offerRule, OfferCondition condition)
        {
            var matchedItems = GetActionMatchedItems(items, offerRule, condition);
            int qty          = 0;

            if (matchedItems != null)
            {
                qty = matchedItems
                      .Where(x => x.Product.OpenForOffer == true)
                      .Select(x => x.Quantity).DefaultIfEmpty(0).Sum();
            }

            return(qty);
        }
Пример #21
0
        private void RenderCondition(string conditionType, string type, bool isCart, OfferCondition node, HtmlTextWriter writer)
        {
            // conditionType is integer. It could be attribute id too.
            // Thus, we need to cast it to integer first.

            var condition = int.Parse(conditionType);

            switch (condition)
            {
            case OFFER_CONDITIONS_COMBINATION:
                // Set default value
                node.IsAll   = true;
                node.IsAny   = false;
                node.Matched = true;

                RenderCombinationCondition(node.Id.ToString(), type, false, true, false, writer);

                writer.WriteBeginTag(UL);
                writer.Write(HtmlTextWriter.TagRightChar);
                RenderNewSelection(node.Id.ToString(), type, isCart, writer);
                writer.WriteEndTag(UL);

                writer.WriteEndTag(LI);
                break;


            case OFFER_PRODUCT_ATTR_COMBINATION:
                // Set default value
                node.ItemFound = true;
                node.IsAll     = true;
                node.IsAny     = false;
                node.Matched   = true;

                RenderProdAttrCombinationCondition(node.Id.ToString(), type, true, false, false, writer);

                writer.WriteBeginTag(UL);
                writer.Write(HtmlTextWriter.TagRightChar);
                RenderNewSelection(node.Id.ToString(), type, false, writer);
                writer.WriteEndTag(UL);

                writer.WriteEndTag(LI);

                break;

            case OFFER_PRODUCTS_SUBSELECTION:
                // Set default value
                node.IsTotalQty       = true;
                node.IsTotalAmount    = false;
                node.OfferAttribute   = _offerService.GetOfferAttribute((int)OfferAttributeType.TOTAL_ITEMS_QTY);
                node.OfferAttributeId = node.OfferAttribute.Id;
                node.OfferOperator    = _offerService.GetOfferOperatorsByAttribute(node.OfferAttribute.Id)[0];
                node.OfferOperatorId  = node.OfferOperator.Id;
                node.Operand          = string.Empty;
                node.IsAll            = true;
                node.IsAny            = false;
                node.Matched          = true;

                RenderProdSubselectionCondition(node.Id.ToString(),
                                                type,
                                                node.OfferOperator.Id,
                                                string.Empty,
                                                node.IsTotalQty.Value,
                                                node.IsTotalAmount.Value,
                                                false,
                                                false,
                                                writer);

                writer.WriteBeginTag(UL);
                writer.Write(HtmlTextWriter.TagRightChar);

                RenderNewSelection(node.Id.ToString(), type, false, writer);

                writer.WriteEndTag(UL);
                writer.WriteEndTag(LI);

                break;

            default:
                var attributeId = condition;
                var title       = GetTitleByAttributeId(attributeId);
                var attribute   = _offerService.GetOfferAttribute(attributeId);
                node.OfferAttribute   = attribute;
                node.OfferAttributeId = attribute.Id;

                var operators = _offerService.GetOfferOperatorsByAttribute(attributeId);

                if (operators.Count > 0)
                {
                    node.OfferOperator   = operators[0];
                    node.OfferOperatorId = operators[0].Id;
                    RenderOperation(title, node.Id.ToString(), type, operators[0].Id, string.Empty, operators, writer);
                }

                break;
            }
        }
Пример #22
0
        public decimal CalculateActionMatchedAmount(IList <CartItem> items, OfferRule offerRule, OfferCondition condition, bool isECcountry)
        {
            var     matchedItems = GetActionMatchedItems(items, offerRule, condition);
            decimal amount       = 0M;

            if (matchedItems != null)
            {
                if (offerRule.UseInitialPrice)
                {
                    SetToUseInitialPrice(matchedItems);
                }

                if (isECcountry)
                {
                    if (offerRule.UseInitialPrice)
                    {
                        amount = matchedItems
                                 .Where(x => x.Product.OpenForOffer == true)
                                 .Select(x => x.ProductPrice.PriceInclTax * x.Quantity).DefaultIfEmpty(0).Sum();
                    }
                    else
                    {
                        amount = matchedItems
                                 .Where(x => x.Product.OpenForOffer == true)
                                 .Select(x => x.ProductPrice.OfferPriceInclTax * x.Quantity).DefaultIfEmpty(0).Sum();
                    }
                }
                else
                {
                    if (offerRule.UseInitialPrice)
                    {
                        amount = matchedItems
                                 .Where(x => x.Product.OpenForOffer == true)
                                 .Select(x => x.ProductPrice.PriceExclTax * x.Quantity).DefaultIfEmpty(0).Sum();
                    }
                    else
                    {
                        amount = matchedItems
                                 .Where(x => x.Product.OpenForOffer == true)
                                 .Select(x => x.ProductPrice.OfferPriceExclTax * x.Quantity).DefaultIfEmpty(0).Sum();
                    }
                }
            }

            return(amount);
        }
Пример #23
0
        public List <CartItem> GetActionMatchedItems(IList <CartItem> items, OfferRule offerRule, OfferCondition condition)
        {
            var matchedItems = items.Where(x =>
            {
                // Exclude item bound to an offer provided that rule says offered item is NOT included
                if (x.ProductPrice.OfferRuleId > 0 && !offerRule.OfferedItemIncluded)
                {
                    return(false);
                }

                // If there is no condition, matched as default
                if (condition.ChildOfferConditions.Count <= 0)
                {
                    return(true);
                }

                return(ProcessCartActionCondition(condition, x));
            }).ToList();

            return(matchedItems);
        }
Пример #24
0
        public bool ProcessCartActionAttributeCondition(OfferCondition condition, CartItem item)
        {
            var value = _attributeUtility.GetAttributeValue(condition.OfferAttribute.Id, item.ProductId);

            return(_attributeUtility.ValidateAttribute(value, condition.OfferOperator.Operator, condition.Operand));
        }
Пример #25
0
        private OfferCondition ProcessOfferConditionHandler(HttpRequest request, HttpResponse response, OfferCondition root, string type)
        {
            string elementId    = request.Form["elementId"];
            int    nodeId       = Convert.ToInt32(elementId.Split('|')[0]); //It could be "id|new.." or just "id".
            string data         = request.Form["data"];
            string action       = request.Form[ACTION];
            string responseData = "ok";

            // If elementId contains "|new..", it means we need to create a new condition which the parent
            // is from id extracted from "id|new".
            // In other words, we will find the node by id. Once the node is found, we create a child node for it.
            var node = SearchCondition(root, nodeId);

            if (node == null)
            {
                responseData = "Condition could not be found. Please contact administrator.";
                response.Clear();
                response.Write(responseData);
                response.End();
                return(root);
            }

            StringBuilder  sb = new StringBuilder();
            StringWriter   tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            switch (action)
            {
            case LOAD_CONDITION:
                var isCart = type == CART;
                // Maximum possible value is 235959999, Int32.MaxValue is 2147483647
                var newId = Convert.ToInt32(DateTime.Now.ToString("HHmmssfff"));

                // Prepare child list of the found node
                int index = 0;

                if ((node.ChildOfferConditions == null) || (node.ChildOfferConditions.Count == 0))
                {
                    node.ChildOfferConditions = new List <OfferCondition>();
                    node.ChildOfferConditions.Add(new OfferCondition {
                        Id = newId
                    });
                }
                else
                {
                    index = node.ChildOfferConditions.Count - 1;
                    node.ChildOfferConditions.Add(new OfferCondition {
                        Id = newId
                    });
                    index = index + 1;
                }
                node.ChildOfferConditions[index].ParentId = node.Id;

                RenderCondition(data, type, isCart, node.ChildOfferConditions[index], hw);

                responseData = "ok|" + sb.ToString();
                break;

            case UPDATE_ALL_ANY:
                switch (data)
                {
                case FALSE:
                    node.IsAll = true;
                    node.IsAny = false;
                    break;

                case TRUE:
                    node.IsAll = false;
                    node.IsAny = true;
                    break;
                }

                break;

            case UPDATE_MATCHED:
                switch (data)
                {
                case TRUE:
                    node.Matched = true;
                    break;

                case FALSE:
                    node.Matched = false;
                    break;
                }

                break;

            case UPDATE_ITEM_FOUND:
                switch (data)
                {
                case TRUE:
                    node.ItemFound = true;
                    break;

                case FALSE:
                    node.ItemFound = false;
                    break;
                }

                break;

            case UPDATE_QTY_AMOUNT:
                switch (data)
                {
                case TRUE:
                    var attrSubtotal = _offerService.GetOfferAttribute((int)OfferAttributeType.SUBTOTAL);

                    if (attrSubtotal == null)
                    {
                        responseData = string.Format("Failed to load attribute '{0}:{1}'. Please contact administrator.", "subtotal", OfferAttributeType.SUBTOTAL);
                        _logger.InsertLog(LogLevel.Error, string.Format("Offer attribute could not be loaded. Offer Attribute ID={{{0}}}", OfferAttributeType.SUBTOTAL));
                    }
                    else
                    {
                        node.OfferAttribute   = attrSubtotal;
                        node.OfferAttributeId = attrSubtotal.Id;
                        node.IsTotalQty       = true;
                        node.IsTotalAmount    = false;
                    }
                    break;

                case FALSE:
                    var attrTotalItemsQty = _offerService.GetOfferAttribute((int)OfferAttributeType.TOTAL_ITEMS_QTY);

                    if (attrTotalItemsQty == null)
                    {
                        responseData = string.Format("Failed to load attribute '{0}:{1}'. Please contact administrator.", "total items quantity", OfferAttributeType.TOTAL_ITEMS_QTY);
                        _logger.InsertLog(LogLevel.Error, string.Format("Offer attribute could not be loaded. Offer Attribute ID={{{0}}}", OfferAttributeType.TOTAL_ITEMS_QTY));
                    }
                    else
                    {
                        node.OfferAttribute   = attrTotalItemsQty;
                        node.OfferAttributeId = attrTotalItemsQty.Id;
                        node.IsTotalQty       = false;
                        node.IsTotalAmount    = true;
                    }
                    break;
                }

                break;

            case DELETE_CONDITION:
                if (root.Id != node.Id)
                {
                    RemoveCondition(root, node.Id);
                }
                else
                {
                    responseData = "You are not allowed to remove root condition.";
                }
                break;

            case UPDATE_OPERATOR:
                var           operatorId = Convert.ToInt32(data);
                OfferOperator op         = _offerService.GetOfferOperator(operatorId);

                if (op == null)
                {
                    responseData = "There is no such operator. Please contact administrator.";
                    _logger.InsertLog(LogLevel.Error, string.Format("Offer operator could not be loaded. Offer Operator ID={{{0}}}", operatorId));
                }
                else
                {
                    node.OfferOperator   = op;
                    node.OfferOperatorId = op.Id;
                }
                break;

            case UPDATE_OPERAND:
                node.Operand = data;
                break;
            }

            response.Clear();
            response.Write(responseData);
            response.End();

            return(root);
        }
Пример #26
0
        public void RenderCondition(OfferCondition condition, HtmlTextWriter writer, OfferRenderType offerType)
        {
            string type   = string.Empty;
            bool   isCart = false;

            switch (offerType)
            {
            case OfferRenderType.Cart:
                type   = CART;
                isCart = true;
                break;

            case OfferRenderType.Catalog:
                type = CATALOG;
                break;

            case OfferRenderType.Action:
            default:
                type = ACTION;
                break;
            }

            if (condition.IsAll.HasValue && condition.IsAny.HasValue && condition.Matched.HasValue)
            {
                if (IsProductAttrCombination(condition))
                {
                    RenderProdAttrCombinationCondition(elementId: condition.Id.ToString(),
                                                       type: type,
                                                       itemFound: condition.ItemFound.Value,
                                                       isAny: condition.IsAny.Value,
                                                       enclosed: isCart,
                                                       writer: writer);

                    isCart = false;
                }
                else if (IsProductSubselection(condition))
                {
                    RenderProdSubselectionCondition(elementId: condition.Id.ToString(),
                                                    type: type,
                                                    operatorId: condition.OfferOperator.Id,
                                                    operand: condition.Operand,
                                                    isQuantity: condition.IsTotalQty.Value,
                                                    isAmount: condition.IsTotalAmount.Value,
                                                    isAny: condition.IsAny.Value,
                                                    enclosed: isCart,
                                                    writer: writer);

                    isCart = false;
                }
                else
                {
                    RenderCombinationCondition(elementId: condition.Id.ToString(),
                                               type: type,
                                               isAny: condition.IsAny.Value,
                                               matched: condition.Matched.Value,
                                               enclosed: isCart,
                                               writer: writer);
                }

                writer.WriteBeginTag(UL);
                writer.Write(HtmlTextWriter.TagRightChar);
                if (condition.ChildOfferConditions != null)
                {
                    for (int i = 0; i < condition.ChildOfferConditions.Count; i++)
                    {
                        RenderCondition(condition.ChildOfferConditions[i], writer, offerType);
                    }
                }

                RenderNewSelection(condition.Id.ToString(), type, isCart, writer);
                writer.WriteEndTag(UL);

                writer.WriteEndTag(LI);
            }
            else
            {
                string title      = GetTitleByAttributeId(condition.OfferAttributeId.Value);
                int    operatorId = condition.OfferOperatorId.Value;
                var    list       = _offerService.GetOfferOperatorsByAttribute(condition.OfferAttributeId.Value);

                RenderOperation(title, condition.Id.ToString(), type, operatorId, condition.Operand, condition.OfferAttributeId.Value, writer);
            }
        }
Пример #27
0
        private OfferCondition DetermineOfferConditionType(OfferCondition condition)
        {
            #region Is Item Matched?
            if (condition.IsAny.HasValue == true &&
                condition.IsAll.HasValue == true &&
                condition.Matched.HasValue == true &&
                condition.OfferAttributeId.HasValue == false &&
                condition.OfferOperatorId.HasValue == false &&
                condition.Operand == null &&
                condition.IsTotalQty.HasValue == false &&
                condition.IsTotalAmount.HasValue == false &&
                condition.ItemFound.HasValue == true)
            {
                condition.Type = OfferConditionType.ItemMatched;

                return(condition);
            }
            #endregion

            #region Is Subselection?
            if (condition.IsAny.HasValue == true &&
                condition.IsAll.HasValue == true &&
                condition.Matched.HasValue == true &&
                condition.OfferAttributeId.HasValue == true &&
                condition.OfferOperatorId.HasValue == true &&
                condition.Operand != null &&
                condition.IsTotalQty.HasValue == true &&
                condition.IsTotalAmount.HasValue == true &&
                condition.ItemFound.HasValue == false)
            {
                condition.Type = OfferConditionType.Subselection;

                condition.OfferAttribute = GetOfferAttribute(condition.OfferAttributeId.Value);
                condition.OfferOperator  = GetOfferOperator(condition.OfferOperatorId.Value);

                return(condition);
            }
            #endregion

            #region Is Attribute?
            if (condition.IsAll.HasValue == false &&
                condition.IsAny.HasValue == false &&
                condition.Matched.HasValue == false &&
                condition.OfferAttributeId.HasValue == true &&
                condition.OfferOperatorId.HasValue == true &&
                condition.Operand != null &&
                condition.IsTotalQty.HasValue == false &&
                condition.IsTotalAmount.HasValue == false &&
                condition.ItemFound.HasValue == false)
            {
                condition.Type = OfferConditionType.Attribute;

                condition.OfferAttribute = GetOfferAttribute(condition.OfferAttributeId.Value);
                condition.OfferOperator  = GetOfferOperator(condition.OfferOperatorId.Value);

                return(condition);
            }
            #endregion

            return(condition);
        }
Пример #28
0
 public int InsertOfferCondition(OfferCondition condition)
 {
     return(_offerConditionRepository.Create(condition));
 }
Пример #29
0
        public bool FindItem(IList <CartItem> items, OfferCondition condition, bool offeredItemIncluded)
        {
            var matchedItems = GetMatchedConditionItems(items, condition, offeredItemIncluded);

            return(matchedItems == null ? false : matchedItems.Count > 0);
        }