예제 #1
0
        /// <summary>
        /// Recalculates the kit
        /// </summary>
        /// <param name="optionList">Option list specifying the variant</param>
        public void Recalculate(string optionList)
        {
            //DETERMINE THE BASE PRICE OF THE PRODUCT
            LSDecimal basePrice  = 0;
            LSDecimal baseWeight = 0;
            //CHECK FOR A SPECIFIED VARIANT
            ProductVariant variant = ProductVariantDataSource.LoadForOptionList(_Product.ProductId, optionList);

            if (variant == null)
            {
                //NO VARIANT, SET VALUES FROM BASE PRODCUT
                _OptionList = string.Empty;
                basePrice   = _Product.Price;
                baseWeight  = _Product.Weight;
            }
            else
            {
                //VARIANT PRESENT, CHECK VARIANT FOR CORRECT VALUES
                _OptionList = optionList;
                basePrice   = (variant.Price == 0) ? _Product.Price : variant.Price;
                baseWeight  = (variant.Weight == 0) ? _Product.Weight : variant.Weight;
            }
            _MinPrice      = basePrice;
            _MaxPrice      = basePrice;
            _DefaultPrice  = basePrice;
            _MinWeight     = baseWeight;
            _MaxWeight     = baseWeight;
            _DefaultWeight = baseWeight;
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent component = pkc.KitComponent;
                if (component.KitProducts.Count > 0)
                {
                    switch (component.InputType)
                    {
                    case KitInputType.IncludedHidden:
                    case KitInputType.IncludedShown:
                        //ALL OF THESE GO INTO MINIMUM AND DEFAULT PRICES
                        foreach (KitProduct kp in component.KitProducts)
                        {
                            LSDecimal kpPrice  = kp.CalculatedPrice;
                            LSDecimal kpWeight = kp.CalculatedWeight;
                            _MinPrice      += kpPrice;
                            _MaxPrice      += kpPrice;
                            _DefaultPrice  += kpPrice;
                            _MinWeight     += kpWeight;
                            _MaxWeight     += kpWeight;
                            _DefaultWeight += kpWeight;
                        }
                        break;

                    case KitInputType.CheckBox:
                        //NONE GO INTO MINIMUM
                        //ALL GO INTO MAXIMUM
                        //DEFAULT SELECTED
                        foreach (KitProduct kp in component.KitProducts)
                        {
                            LSDecimal kpPrice  = kp.CalculatedPrice;
                            LSDecimal kpWeight = kp.CalculatedWeight;
                            _MaxPrice  += kpPrice;
                            _MaxWeight += kpWeight;
                            if (kp.IsSelected)
                            {
                                _DefaultPrice  += kpPrice;
                                _DefaultWeight += kpWeight;
                            }
                        }
                        break;

                    case KitInputType.DropDown:
                    case KitInputType.RadioButton:
                        //LOWEST PRICE / WEIGHT GOES INTO MINIMUM
                        //HIGHEST PRICE / WEIGHT GOES INTO MAXIMUM
                        //DEFAULT SELECTED
                        LSDecimal tempDefaultPrice;
                        LSDecimal tempDefaultWeight;
                        LSDecimal tempHighPrice;
                        LSDecimal tempLowPrice;
                        LSDecimal tempHighWeight;
                        LSDecimal tempLowWeight;
                        //GET FIRST KIT PRODUCT
                        KitProduct firstKp       = component.KitProducts[0];
                        LSDecimal  firstKpPrice  = firstKp.CalculatedPrice;
                        LSDecimal  firstKpWeight = firstKp.CalculatedWeight;
                        //CHECK FOR HEADER OPTION
                        if (string.IsNullOrEmpty(component.HeaderOption))
                        {
                            //NO HEADER OPTION, VALUES MUST START WITH FIRST KIT PRODUCT
                            tempHighPrice     = firstKpPrice;
                            tempHighWeight    = firstKpWeight;
                            tempLowPrice      = firstKpPrice;
                            tempLowWeight     = firstKpWeight;
                            tempDefaultPrice  = firstKpPrice;
                            tempDefaultWeight = firstKpWeight;
                        }
                        else
                        {
                            //HEADEROPTION IS PRESENT
                            tempHighPrice  = firstKpPrice > 0 ? firstKpPrice : 0;
                            tempHighWeight = firstKpWeight > 0 ? firstKpWeight : 0;
                            tempLowPrice   = firstKpPrice < 0 ? firstKpPrice : 0;
                            tempLowWeight  = firstKpWeight < 0 ? firstKpWeight : 0;
                            if (firstKp.IsSelected)
                            {
                                tempDefaultPrice  = firstKpPrice;
                                tempDefaultWeight = firstKpWeight;
                            }
                            else
                            {
                                tempDefaultPrice  = 0;
                                tempDefaultWeight = 0;
                            }
                        }
                        bool foundDefault = firstKp.IsSelected;
                        //LOOP THE REMAINING PRODUCTS IN COLLECTION TO CALCULATE VALUES
                        for (int index = 1; index < component.KitProducts.Count; index++)
                        {
                            KitProduct kp       = component.KitProducts[index];
                            LSDecimal  kpPrice  = kp.CalculatedPrice;
                            LSDecimal  kpWeight = kp.CalculatedWeight;
                            if (kpPrice > tempHighPrice)
                            {
                                tempHighPrice = kpPrice;
                            }
                            if (kpPrice < tempLowPrice)
                            {
                                tempLowPrice = kpPrice;
                            }
                            if (kpWeight > tempHighWeight)
                            {
                                tempHighWeight = kpWeight;
                            }
                            if (kpWeight < tempLowWeight)
                            {
                                tempLowWeight = kpWeight;
                            }
                            if ((!foundDefault) && (kp.IsSelected))
                            {
                                tempDefaultPrice  = kpPrice;
                                tempDefaultWeight = kpWeight;
                                foundDefault      = true;
                            }
                        }
                        _MinPrice      += tempLowPrice;
                        _MinWeight     += tempLowWeight;
                        _MaxPrice      += tempHighPrice;
                        _MaxWeight     += tempHighWeight;
                        _DefaultPrice  += tempDefaultPrice;
                        _DefaultWeight += tempDefaultWeight;
                        break;
                    }
                }
            }
            _Calculated = true;
        }
예제 #2
0
        private void Calculate()
        {
            Product product = ProductDataSource.Load(_ProductId);

            if (product != null)
            {
                if (string.IsNullOrEmpty(_OptionList))
                {
                    //NO VARIANT, SET VALUES FROM BASE PRODCUT
                    _Sku    = product.Sku;
                    _Price  = GetPriceFromRules(product);
                    _Weight = product.Weight;
                }
                else
                {
                    //VARIANT PRESENT, CHECK VARIANT FOR CORRECT VALUES
                    ProductVariant variant = ProductVariantDataSource.LoadForOptionList(_ProductId, _OptionList);
                    if (variant == null)
                    {
                        throw new InvalidOptionsException("The options specified for " + product.Name + " are invalid.");
                    }
                    _Sku = variant.Sku;
                    if (variant.Price != 0)
                    {
                        if (variant.PriceMode == ModifierMode.Modify)
                        {
                            _Price = GetPriceFromRules(product) + variant.Price;
                        }
                        else
                        {
                            _Price = variant.Price;
                        }
                    }
                    else
                    {
                        _Price = GetPriceFromRules(product);
                    }
                    if (variant.Weight != 0)
                    {
                        if (variant.WeightMode == ModifierMode.Modify)
                        {
                            _Weight = product.Weight + variant.Weight;
                        }
                        else
                        {
                            _Weight = variant.Weight;
                        }
                    }
                    else
                    {
                        _Weight = product.Weight;
                    }
                }

                // CALCULATE PRICE WITH TAX IF SPECIFIED
                if (_CalculateTax)
                {
                    _PriceWithTax = TaxHelper.GetShopPrice(_Price, product.TaxCodeId);
                }

                //CHECK FOR KIT PRODUCTS
                if (_KitProductIds != null)
                {
                    foreach (int kitProductId in _KitProductIds)
                    {
                        KitProduct kp = KitProductDataSource.Load(kitProductId);
                        if (kp != null)
                        {
                            _Price  += kp.CalculatedPrice;
                            _Weight += kp.CalculatedWeight;

                            // CALCULATE PRICE WITH TAX IF SPECIFIED
                            if (_CalculateTax)
                            {
                                int          taxCodeId = 0;
                                KitComponent component = kp.KitComponent;
                                if (component.InputType == KitInputType.IncludedHidden)
                                {
                                    taxCodeId = product.TaxCodeId;
                                }
                                else if (kp.Product != null)
                                {
                                    taxCodeId = kp.Product.TaxCodeId;
                                }
                                _PriceWithTax += TaxHelper.GetShopPrice(kp.CalculatedPrice, taxCodeId);
                            }
                        }
                    }
                }
                _Calculated = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Verifies that the inventory settings for a kit product are sufficient
        /// for the product to be included in the kit purchase.
        /// </summary>
        /// <param name="kp">The kit product to check</param>
        /// <returns>False is returned when there is not sufficient quantity of the
        /// product to be included as part of the kit.</returns>
        /// <remarks>This method does not check whether inventory is enabled for the store.</remarks>
        private bool VerifyInventory(KitProduct kp)
        {
            InventoryManagerData invData = kp.CheckStock();

            return(invData.InventoryMode == InventoryMode.None || invData.InStock >= kp.Quantity || invData.AllowBackorder);
        }