public override NBrightInfo CalculateItemPercentDiscount(int portalId, int userId, NBrightInfo cartItemInfo,String discountcode)
        {
            if (userId <= 0) return cartItemInfo;
            cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0"); // reset discount amount
            if (discountcode == "") return cartItemInfo;
            var clientData = new ClientData(portalId,userId);
            if (clientData.DiscountCodes.Count == 0) return cartItemInfo;

            Double discountcodeamt = 0;
            foreach (var d in clientData.DiscountCodes)
            {
                var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                var validutildate = DateTime.Today;
                if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                {
                    var usageleft = d.GetXmlPropertyDouble("genxml/textbox/usageleft");
                    var percentage = d.GetXmlPropertyDouble("genxml/textbox/percentage");
                    if (percentage > 0 && usageleft > 0)
                    {
                        var appliedtotalcost = cartItemInfo.GetXmlPropertyDouble("genxml/appliedtotalcost");
                        discountcodeamt = ((appliedtotalcost/100)*percentage);
                    }
                }
                if (discountcodeamt > 0) break;
            }
            cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", discountcodeamt);

            return cartItemInfo;
        }
Beispiel #2
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            var    shipData   = new ShippingData(Shippingkey);
            var    shipoption = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/rblshippingoptions");
            Double rangeValue = 0;

            if (shipData.CalculationUnit == "1")
            {
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/totalweight");
            }
            else
            {
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            }
            var countrycode = "";
            var regioncode  = "";
            var regionkey   = "";
            var postCode    = "";
            var total       = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");

            switch (shipoption)
            {
            case "1":
                countrycode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                regionkey   = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                postCode    = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/postalcode");
                break;

            case "2":
                countrycode = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/country");
                regionkey   = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/region");
                postCode    = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/textbox/postalcode");
                break;
            }

            var shippingcost = shipData.CalculateShippingByPC(postCode, rangeValue, total);

            if (shippingcost == -1)
            {
                if (regionkey != "")
                {
                    var rl = regionkey.Split(':');
                    if (rl.Count() == 2)
                    {
                        regioncode = rl[1];
                    }
                }
                shippingcost = shipData.CalculateShipping(countrycode, regioncode, rangeValue, total);
            }
            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
 public static NBrightInfo UpdateItemPercentDiscountCode(int portalId, int userId, NBrightInfo cartItemInfo, String discountcode)
 {
     cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0");
     foreach (var prov in ProviderList)
     {
         var newItemInfo = prov.Value.CalculateItemPercentDiscount(portalId, userId, cartItemInfo, discountcode);
         if (cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt") < newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"))
         {
             cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"));
         }
     }
     return(cartItemInfo);
 }
 public static NBrightInfo UpdateItemPercentDiscountCode(int portalId, int userId, NBrightInfo cartItemInfo, String discountcode)
 {
     cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0");
     foreach (var prov in ProviderList)
     {
         var newItemInfo = prov.Value.CalculateItemPercentDiscount(portalId, userId, cartItemInfo, discountcode);
         if (cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt") < newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"))
         {
             cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"));
         }
     }
     return cartItemInfo;
 }
Beispiel #5
0
        private int AddNew()
        {
            var nbi = new NBrightInfo(true);

            if (StoreSettings.Current.GetBool(StoreSettingKeys.sharecategories)) // option in storesetting to share products created here across all portals.
            {
                _portalId = -1;
            }
            else
            {
                _portalId = PortalSettings.Current.PortalId;
            }
            nbi.PortalId = _portalId;
            nbi.TypeCode = "CATEGORY";
            nbi.ModuleId = -1;
            nbi.ItemID   = -1;
            nbi.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
            nbi.SetXmlProperty("genxml/checkbox/chkishidden", "True");
            nbi.SetXmlPropertyDouble("genxml/hidden/recordsortorder", 99999);
            var itemId = _objCtrl.Update(nbi);

            // update again, so we get a valid sort order based on itemid
            nbi.ItemID = itemId;
            nbi.SetXmlPropertyDouble("genxml/hidden/recordsortorder", itemId);
            _objCtrl.Update(nbi);

            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                nbi = new NBrightInfo(true)
                {
                    PortalId     = _portalId,
                    TypeCode     = "CATEGORYLANG",
                    ModuleId     = -1,
                    ItemID       = -1,
                    Lang         = lang,
                    ParentItemId = itemId
                };
                _objCtrl.Update(nbi);
            }

            return(itemId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cartInfo"></param>
        /// <returns></returns>
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            // return zero if we have invalid data
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");

            var modCtrl = new NBrightBuyController();
            var info    = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (info == null)
            {
                return(cartInfo);
            }


            double shippingcost = 10;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_ShippingProviderlistidx") == 1)
            {
                shippingcost = 99.99;
            }

            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
Beispiel #7
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            var shipData = new ShippingData(Shippingkey);
            var shipoption = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/rblshippingoptions");
            Double rangeValue = 0;
            if (shipData.CalculationUnit == "1")
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/totalweight");
            else
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            var countrycode = "";
            var regioncode = "";
            var regionkey = "";
            var total = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            switch (shipoption)
            {
                case "1":
                    countrycode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                    regionkey = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                    break;
                case "2":
                    countrycode = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/country");
                    regionkey = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/region");
                    break;
            }

            if (regionkey != "")
            {
                var rl = regionkey.Split(':');
                if (rl.Count() == 2) regioncode = rl[1];
            }

            var shippingcost = shipData.CalculateShipping(countrycode, regioncode, rangeValue, total);
            var shippingdealercost = shippingcost;
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return cartInfo;
        }
Beispiel #8
0
        public void UpdateModels(String xmlAjaxData, string editlang)
        {
            var rtnstatuscode = "";
            var modelList     = NBrightBuyUtils.GetGenXmlListByAjax(xmlAjaxData, "", editlang);

            var basefields = "";

            // build xml for data records
            var strXml = "<genxml><interfaces>";

            foreach (var modelInfo in modelList)
            {
                // build list of xpath fields that need processing.
                var filedList = NBrightBuyUtils.GetAllFieldxPaths(modelInfo);
                foreach (var xpath in filedList)
                {
                    basefields += xpath + ",";
                }

                var objInfo = new NBrightInfo(true);

                var fields = basefields.Split(',');
                foreach (var f in fields.Where(f => f != ""))
                {
                    var datatype = modelInfo.GetXmlProperty(f + "/@datatype");
                    if (datatype == "date")
                    {
                        objInfo.SetXmlProperty(f, modelInfo.GetXmlProperty(f), TypeCode.DateTime);
                    }
                    else if (datatype == "double")
                    {
                        objInfo.SetXmlPropertyDouble(f, modelInfo.GetXmlProperty(f));
                    }
                    else if (datatype == "html")
                    {
                        objInfo.SetXmlProperty(f, modelInfo.GetXmlPropertyRaw(f));
                    }
                    else
                    {
                        objInfo.SetXmlProperty(f, modelInfo.GetXmlProperty(f));
                    }
                }
                strXml += objInfo.XMLData;
            }
            strXml += "</interfaces></genxml>";

            // replace models xml
            Info().ReplaceXmlNode(strXml, "genxml/interfaces", "genxml");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cartInfo"></param>
        /// <returns></returns>
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            // return zero if we have invalid data
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");
            var modCtrl = new NBrightBuyController();
            var info    = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (info == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }

            if (Merchant.IsEnable && Merchant.Type == "B")
            {
                shippingcost = Merchant.HomeCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }


            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");

            NBrightBuyController nbCtrl = new NBrightBuyController();
            NBrightInfo          nbInfo = nbCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (nbInfo == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }


            if (Merchant.IsEnable)
            {
                shippingcost = Merchant.UniMartCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }

            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
Beispiel #11
0
        private NBrightInfo ValidateCartItem(int portalId, int userId, NBrightInfo cartItemInfo, Boolean removeZeroQtyItems = false)
        {
            #region "get cart values"
            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemBefore, cartItemInfo);

            var modelid = cartItemInfo.GetXmlProperty("genxml/modelid");
            var prdid   = cartItemInfo.GetXmlPropertyInt("genxml/productid");
            var qty     = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
            var lang    = cartItemInfo.GetXmlProperty("genxml/lang");

            if (removeZeroQtyItems && qty == 0)
            {
                return(null);                                // Remove zero qty item
            }
            if (lang == "")
            {
                lang = Utils.GetCurrentCulture();
            }
            var prd = ProductUtils.GetProductData(prdid, lang);
            if (!prd.Exists || prd.Disabled)
            {
                return(null);                             //Invalid product remove from cart
            }
            // update product xml data on cart (product may have change via plugin so always replace)
            cartItemInfo.RemoveXmlNode("genxml/productxml");
            // add entitytype for validation methods
            prd.Info.SetXmlProperty("genxml/entitytypecode", prd.Info.TypeCode);
            cartItemInfo.AddSingleNode("productxml", prd.Info.XMLData, "genxml");

            var prdModel = prd.GetModel(modelid);
            if (prdModel == null)
            {
                return(null);                  // Invalid Model remove from cart
            }
            // check if dealer (for tax calc)
            if (NBrightBuyUtils.IsDealer())
            {
                cartItemInfo.SetXmlProperty("genxml/isdealer", "True");
            }
            else
            {
                cartItemInfo.SetXmlProperty("genxml/isdealer", "False");
            }

            // check for price change
            var unitcost       = prdModel.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
            var dealercost     = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
            var saleprice      = prdModel.GetXmlPropertyDouble("genxml/textbox/txtsaleprice");
            var dealersalecost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealersale");

            // always make sale price best price
            if (unitcost > 0 && (unitcost < saleprice || saleprice <= 0))
            {
                saleprice = unitcost;
            }
            // if we have a promoprice use it as saleprice (This is passed in via events provider like "Multi-Buy promotions")
            if (cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") > 0 && cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") < saleprice)
            {
                saleprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice");
            }

            // always assign the dealercost the best price.
            if (dealersalecost > 0 && dealersalecost < dealercost)
            {
                dealercost = dealersalecost;
            }
            if (saleprice > 0 && (saleprice < dealercost || dealercost <= 0))
            {
                dealercost = saleprice;
            }
            if (unitcost > 0 && (unitcost < dealercost || dealercost <= 0))
            {
                dealercost = unitcost;
            }



            // calc sell price
            // sellcost = the calculated cost of the item.
            var sellcost = unitcost;
            if (saleprice > 0 && saleprice < sellcost)
            {
                sellcost = saleprice;
            }
            if (NBrightBuyUtils.IsDealer())
            {
                if (dealercost > 0 && dealercost < sellcost)
                {
                    sellcost = dealercost;
                }
            }
            // --------------------------------------------
            #endregion

            if (prdModel != null)
            {
                #region "Stock Control"
                var stockon    = prdModel.GetXmlPropertyBool("genxml/checkbox/chkstockon");
                var stocklevel = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining");
                var minStock   = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyminstock");
                if (minStock == 0)
                {
                    minStock = StoreSettings.Current.GetInt("minimumstocklevel");
                }
                var maxStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtystockset");
                var weight   = prdModel.GetXmlPropertyDouble("genxml/textbox/weight");
                if (stockon)
                {
                    stocklevel = stocklevel - minStock;
                    stocklevel = stocklevel - prd.GetModelTransQty(modelid, _cartId);
                    if (stocklevel < qty)
                    {
                        qty = stocklevel;
                        if (qty <= 0)
                        {
                            qty = 0;
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "OUTOFSTOCK");
                        }
                        else
                        {
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "STOCKADJ");
                        }
                        base.SetValidated(false);
                        cartItemInfo.SetXmlPropertyDouble("genxml/qty", qty.ToString(""));
                    }
                }
                #endregion

                #region "Addtional options costs"
                Double additionalCosts = 0;
                var    optNods         = cartItemInfo.XMLDoc.SelectNodes("genxml/options/*");
                if (optNods != null)
                {
                    var lp = 1;
                    foreach (XmlNode nod in optNods)
                    {
                        var optid = nod.SelectSingleNode("optid");
                        if (optid != null)
                        {
                            var optvalueid = nod.SelectSingleNode("optvalueid");
                            if (optvalueid != null && optvalueid.InnerText != "False")
                            {
                                XmlNode optvalcostnod;
                                if (optvalueid.InnerText == "True")
                                {
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues[@optionid='" + optid.InnerText + "']/genxml/textbox/txtaddedcost");
                                }
                                else
                                {
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues/genxml[./hidden/optionvalueid='" + optvalueid.InnerText + "']/textbox/txtaddedcost");
                                }

                                if (optvalcostnod != null)
                                {
                                    var optvalcost = optvalcostnod.InnerText;
                                    if (Utils.IsNumeric(optvalcost))
                                    {
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", optvalcost);
                                        var optvaltotal = Convert.ToDouble(optvalcost, CultureInfo.GetCultureInfo("en-US")) * qty;
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", optvaltotal);
                                        additionalCosts += optvaltotal;
                                    }
                                }
                                else
                                {
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", "0");
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", "0");
                                }
                            }
                        }
                        lp += 1;
                    }
                }

                if (qty > 0)  // can't devide by zero
                {
                    unitcost += (additionalCosts / qty);
                    if (dealercost > 0)
                    {
                        dealercost += (additionalCosts / qty);                 // zero turns off
                    }
                    if (saleprice > 0)
                    {
                        saleprice += (additionalCosts / qty);                // zero turns off
                    }
                    sellcost += (additionalCosts / qty);
                }
                #endregion

                var totalcost     = qty * unitcost;
                var totalsellcost = qty * sellcost;
                var totalweight   = weight * qty;

                cartItemInfo.SetXmlPropertyDouble("genxml/unitcost", unitcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/dealercost", dealercost);
                cartItemInfo.SetXmlPropertyDouble("genxml/saleprice", saleprice);

                cartItemInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight.ToString(""));
                cartItemInfo.SetXmlPropertyDouble("genxml/totalcost", totalcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", (totalcost - (qty * dealercost)));

                Double salediscount    = 0;
                Double discountcodeamt = 0;
                Double totaldiscount   = 0;

                //add update genxml/discountcodeamt
                var discountcode = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
                if (discountcode != "")
                {
                    cartItemInfo    = DiscountCodeInterface.UpdateItemPercentDiscountCode(PortalId, UserId, cartItemInfo, discountcode);
                    discountcodeamt = cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt");
                    if (discountcodeamt > 0)
                    {
                        PurchaseInfo.SetXmlProperty("genxml/discountprocessed", "False");
                    }
                }

                if (NBrightBuyUtils.IsDealer())
                {
                    salediscount = (unitcost - dealercost);
                }
                else
                {
                    salediscount = (unitcost - saleprice);
                }
                totaldiscount = (salediscount * qty) + discountcodeamt; // add on any promo code amount
                if (totaldiscount < 0)
                {
                    totaldiscount = 0;
                }

                // if we have a promodiscount use it
                if (cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount") > 0)
                {
                    totaldiscount = cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount");
                    totalcost     = totalcost - totaldiscount;
                    if (totalcost < 0)
                    {
                        totalcost = 0;
                    }
                    cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalcost);
                }


                cartItemInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);

                // if product is on sale then we need to display the sale price in the cart, and any discount codes don;t show at this cart item level, only on the order total.
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalsellcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedcost", sellcost);


                // calc tax for item
                var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/hidden/taxproviderkey");
                var taxprov        = TaxInterface.Instance(taxproviderkey);
                if (taxprov != null)
                {
                    var nbi = (NBrightInfo)cartItemInfo.Clone();
                    cartItemInfo.SetXmlPropertyDouble("genxml/taxcost", taxprov.CalculateItemTax(nbi));
                }
            }


            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemAfter, cartItemInfo);

            return(cartItemInfo);
        }
Beispiel #12
0
        public String AddSingleItem(String strproductid, String strmodelId, String strqtyId, NBrightInfo objInfoIn, Boolean debugMode = false, int replaceIndex = -1)
        {
            if (!Utils.IsNumeric(strqtyId) || Convert.ToInt32(strqtyId) <= 0) return "";

            if (StoreSettings.Current.DebugModeFileOut) objInfoIn.XMLDoc.Save(PortalSettings.Current.HomeDirectoryMapPath + "debug_addtobasket.xml");

            var objInfo = new NBrightInfo();
            objInfo.XMLData = "<genxml></genxml>";

            // get productid
            if (Utils.IsNumeric(strproductid))
            {
                var itemcode = ""; // The itemcode var is used to decide if a cart item is new or already existing in the cart.
                var productData = ProductUtils.GetProductData(Convert.ToInt32(strproductid), Utils.GetCurrentCulture());

                if (productData.Info == null) return ""; // we may have a invalid productid that has been saved by a cookie, but since has been deleted.

                var modelInfo = productData.GetModel(strmodelId);
                if (modelInfo == null) return ""; // no valid model

                objInfo.AddSingleNode("productid", strproductid, "genxml");
                itemcode += strproductid + "-";

                objInfo.AddSingleNode("modelid", strmodelId, "genxml");
                itemcode += strmodelId + "-";

                // Get Qty
                objInfo.AddSingleNode("qty", strqtyId, "genxml");

                #region "Get model and product data"

                objInfo.AddSingleNode("productname", productData.Info.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtproductname"), "genxml");
                objInfo.AddSingleNode("summary", productData.Info.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtsummary"), "genxml");

                objInfo.AddSingleNode("modelref", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtmodelref"), "genxml");
                objInfo.AddSingleNode("modeldesc", modelInfo.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtmodelname"), "genxml");
                objInfo.AddSingleNode("modelextra", modelInfo.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtextra"), "genxml");
                objInfo.AddSingleNode("unitcost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtunitcost"), "genxml");
                objInfo.AddSingleNode("dealercost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtdealercost"), "genxml");
                objInfo.AddSingleNode("taxratecode", modelInfo.GetXmlPropertyRaw("genxml/dropdownlist/taxrate"), "genxml");
                objInfo.AddSingleNode("saleprice", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtsaleprice"), "genxml");
                objInfo.AddSingleNode("basecost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtunitcost"), "genxml");

                // flag if dealer
                var userInfo = UserController.Instance.GetCurrentUserInfo();
                if (userInfo != null && userInfo.IsInRole(StoreSettings.DealerRole) && StoreSettings.Current.Get("enabledealer") == "True")
                    objInfo.SetXmlProperty("genxml/isdealer", "True");
                else
                    objInfo.SetXmlProperty("genxml/isdealer", "False");

                //move all product and model data into cart item, so we can display bespoke fields.
                objInfo.AddSingleNode("productxml", productData.Info.XMLData, "genxml");

                #endregion

                #region "Get option Data"

                //build option data for cart
                Double additionalCosts = 0;
                var strXmlIn = "";
                var optionDataList = new Dictionary<String, String>();
                if (objInfoIn.XMLDoc != null)
                {
                    var nodList = objInfoIn.XMLDoc.SelectNodes("genxml/textbox/*[starts-with(name(), 'optiontxt')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                            strXmlIn = "<option>";
                            var idx = nod.Name.Replace("optiontxt", "");
                            var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                            var optionInfo = productData.GetOption(optionid);
                            var optvaltext = nod.InnerText;
                            strXmlIn += "<optid>" + optionid + "</optid>";
                            strXmlIn += "<optvaltext>" + optvaltext + "</optvaltext>";
                            itemcode += optionid + "-" + Utils.GetUniqueKey() + "-";
                            strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                            strXmlIn += "</option>";
                            if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                    nodList = objInfoIn.XMLDoc.SelectNodes("genxml/dropdownlist/*[starts-with(name(), 'optionddl')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                            strXmlIn = "<option>";
                            var idx = nod.Name.Replace("optionddl", "");
                            var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                            var optionvalueid = nod.InnerText;
                            var optionValueInfo = productData.GetOptionValue(optionid, optionvalueid);
                            var optionInfo = productData.GetOption(optionid);
                            strXmlIn += "<optid>" + optionid + "</optid>";
                            strXmlIn += "<optvalueid>" + optionvalueid + "</optvalueid>";
                            itemcode += optionid + ":" + optionvalueid + "-";
                            strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                            strXmlIn += "<optvalcost>" + optionValueInfo.GetXmlProperty("genxml/textbox/txtaddedcost") + "</optvalcost>";
                            strXmlIn += "<optvaltext>" + optionValueInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + "</optvaltext>";
                            strXmlIn += "</option>";
                            additionalCosts += optionValueInfo.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
                            if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                    nodList = objInfoIn.XMLDoc.SelectNodes("genxml/checkbox/*[starts-with(name(), 'optionchk')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                                strXmlIn = "<option>";
                                var idx = nod.Name.Replace("optionchk", "");
                                var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                                var optionvalueid = nod.InnerText;
                                var optionValueInfo = productData.GetOptionValue(optionid, ""); // checkbox does not have optionvalueid
                                var optionInfo = productData.GetOption(optionid);
                                strXmlIn += "<optid>" + optionid + "</optid>";
                                strXmlIn += "<optvalueid>" + optionvalueid + "</optvalueid>";
                                itemcode += optionid + ":" + optionvalueid + "-";
                                strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                                strXmlIn += "<optvalcost>" + optionValueInfo.GetXmlProperty("genxml/textbox/txtaddedcost") + "</optvalcost>";
                                strXmlIn += "<optvaltext>" + optionValueInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + "</optvaltext>";
                                strXmlIn += "</option>";
                                if (nod.InnerText.ToLower() == "true") additionalCosts += optionValueInfo.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
                                if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                }

                // we need to save the options in the same order as in product, so index works correct on the template tokens.
                var strXmlOpt = "<options>";
                for (int i = 1; i <= optionDataList.Count; i++)
                {
                    if (optionDataList.ContainsKey(i.ToString("")))
                    {
                        strXmlOpt += optionDataList[i.ToString("")];
                    }
                }
                strXmlOpt += "</options>";

                objInfo.AddXmlNode(strXmlOpt, "options", "genxml");

                #endregion

                //add additional costs from optionvalues (Add to both dealer and unit cost)
                if (additionalCosts > 0)
                {
                    objInfo.SetXmlPropertyDouble("genxml/additionalcosts", additionalCosts);
                    var uc = objInfo.GetXmlPropertyDouble("genxml/unitcost");
                    var dc = objInfo.GetXmlPropertyDouble("genxml/dealercost");
                    uc += additionalCosts;
                    if (dc > 0) dc += additionalCosts; // only calc dealer cost if it's > zero (active)
                    objInfo.SetXmlPropertyDouble("genxml/unitcost", uc);
                    objInfo.SetXmlPropertyDouble("genxml/dealercost", dc);
                }

                objInfo.AddSingleNode("itemcode", itemcode.TrimEnd('-'), "genxml");

                // check if we have a client file upload
                var clientfileuopload = objInfoIn.GetXmlProperty("genxml/textbox/optionfilelist") != "";

                //replace the item if it's already in the list.
                var nodItem = PurchaseInfo.XMLDoc.SelectSingleNode("genxml/items/genxml[itemcode='" + itemcode.TrimEnd('-') + "']");
                if (nodItem == null || clientfileuopload)
                {
                    #region "Client Files"

                    if (clientfileuopload)
                    {
                        // client has uploaded files, so save these to client upload folder and create link in cart data.
                        var flist = objInfoIn.GetXmlProperty("genxml/textbox/optionfilelist").TrimEnd(',');
                        var fprefix = objInfoIn.GetXmlProperty("genxml/hidden/optionfileprefix") + "_";
                        var fileXml = "<clientfiles>";
                        foreach (var f in flist.Split(','))
                        {
                            var fullName = StoreSettings.Current.FolderTempMapPath.TrimEnd(Convert.ToChar("\\")) + "\\" + fprefix + f;
                            var extension = Path.GetExtension(fullName);
                            if (File.Exists(fullName))
                            {
                                var newDocFileName = StoreSettings.Current.FolderClientUploadsMapPath.TrimEnd(Convert.ToChar("\\")) + "\\" + Guid.NewGuid() + extension;
                                File.Copy(fullName, newDocFileName, true);
                                File.Delete(fullName);
                                var docurl = StoreSettings.Current.FolderClientUploads.TrimEnd('/') + "/" + Path.GetFileName(newDocFileName);
                                fileXml += "<file>";
                                fileXml += "<mappath>" + newDocFileName + "</mappath>";
                                fileXml += "<url>" + docurl + "</url>";
                                fileXml += "<name>" + f + "</name>";
                                fileXml += "<prefix>" + fprefix + "</prefix>";
                                fileXml += "</file>";
                            }
                        }
                        fileXml += "</clientfiles>";
                        objInfo.AddXmlNode(fileXml, "clientfiles", "genxml");
                    }

                    #endregion

                    if (replaceIndex >= 0 && replaceIndex < _itemList.Count)
                        _itemList[replaceIndex] = objInfo; //replace
                    else
                        _itemList.Add(objInfo); //add as new item
                }
                else
                {
                    //replace item
                    var qty = nodItem.SelectSingleNode("qty");
                    if (qty != null && Utils.IsNumeric(qty.InnerText) && Utils.IsNumeric(strqtyId))
                    {
                        var userqtylimit = objInfoIn.GetXmlPropertyInt("genxml/hidden/userqtylimit");
                        if (userqtylimit > 0 && Convert.ToInt32(qty.InnerText) >= userqtylimit) return "";

                        //add new qty and replace item
                        PurchaseInfo.RemoveXmlNode("genxml/items/genxml[itemcode='" + itemcode.TrimEnd('-') + "']");
                        _itemList = GetCartItemList();
                        var newQty = Convert.ToString(Convert.ToInt32(qty.InnerText) + Convert.ToInt32(strqtyId));
                        objInfo.SetXmlProperty("genxml/qty", newQty, TypeCode.String, false);
                        _itemList.Add(objInfo);
                    }
                }

                //add nodes for any fields that might exist in cart template
                objInfo.AddSingleNode("textbox", "", "genxml");
                objInfo.AddSingleNode("dropdownlist", "", "genxml");
                objInfo.AddSingleNode("radiobuttonlist", "", "genxml");
                objInfo.AddSingleNode("checkbox", "", "genxml");

                SavePurchaseData(); // need to save after each add, so it exists in data when we check it already exists for updating.

                // return the message status code in textData, non-critical (usually empty)
                return objInfo.TextData;
            }
            return "";
        }
Beispiel #13
0
        public override NBrightInfo Calculate(NBrightInfo cartInfo)
        {
            var enableShippingTax = _info.GetXmlPropertyBool("genxml/checkbox/enableshippingtax");
            var shippingTaxRate   = _info.GetXmlPropertyDouble("genxml/textbox/shippingtaxrate");

            // return taxtype, 1 = included in cost, 2 = not included in cost, 3 = no tax, 4 = tax included in cost, but calculate to zero.
            cartInfo.SetXmlPropertyDouble("genxml/taxtype", _taxType);

            if (_taxType == "3" || _taxType == "4") // no tax calculation
            {
                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                return(cartInfo);
            }


            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(cartInfo);
            }

            // loop through each item and calc the tax for each.
            var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*");

            if (nodList != null)
            {
                Double taxtotal = 0;

                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    taxtotal   += CalculateItemTax(nbi, rateDic);
                }

                if (enableShippingTax && shippingTaxRate > 0)
                {
                    var isDealer = false; // default until dealer shipping cost implemented
                    taxtotal += CalculateShippingTax(cartInfo, shippingTaxRate, isDealer);
                }

                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal);
                if (_taxType == "1")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);                  // tax already in total, so don't apply any more tax.
                }
                if (_taxType == "2")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal);
                }


                var taxcountry            = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                var storecountry          = StoreSettings.Current.Get("storecountry");
                var valideutaxcountrycode = _info.GetXmlProperty("genxml/textbox/valideutaxcountrycode");
                var isvalidEU             = false;
                valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ",";
                if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ",")))
                {
                    isvalidEU = true;
                }

                // Check for EU tax number.
                var enabletaxnumber = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber");
                if (enabletaxnumber)
                {
                    var taxnumber = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/taxnumber").Trim();
                    if (storecountry != taxcountry && taxnumber != "")
                    {
                        // not matching merchant country, so remove tax
                        if (_taxType == "1")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                        }
                        if (_taxType == "2")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                        }
                    }
                }

                // Check for country.
                var enabletaxcountry = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry");
                if (enabletaxcountry)
                {
                    if (taxcountry != "")
                    {
                        if (taxcountry != storecountry && !isvalidEU)
                        {
                            // not matching merchant country, so remove tax
                            if (_taxType == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (_taxType == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

                // check for region exempt (in same country)
                var taxexemptregions = _info.GetXmlProperty("genxml/textbox/taxexemptregions");
                if (taxexemptregions != "" && taxcountry == storecountry)
                {
                    taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ", "") + ",";
                    var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region").Trim();
                    if (taxregioncode == "")
                    {
                        taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion").Trim();
                    }
                    if (taxregioncode != "")
                    {
                        if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ","))
                        {
                            // not matching merchant region, so remove tax
                            if (_taxType == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (_taxType == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }
            }


            return(cartInfo);
        }
Beispiel #14
0
        private int AddNew()
        {
            var nbi = new NBrightInfo(true);
            if (StoreSettings.Current.Get("shareproducts") == "True") // option in storesetting to share products created here across all portals.
                _portalId = -1;
            else
                _portalId = PortalSettings.Current.PortalId;
            nbi.PortalId = _portalId;
            nbi.TypeCode = "CATEGORY";
            nbi.ModuleId = -1;
            nbi.ItemID = -1;
            nbi.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
            nbi.SetXmlProperty("genxml/checkbox/chkishidden", "True");
            nbi.SetXmlPropertyDouble("genxml/hidden/recordsortorder", 99999);
            var objCtrl = new NBrightBuyController();
            var itemId = objCtrl.Update(nbi);

            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                nbi = new NBrightInfo(true);
                nbi.PortalId = _portalId;
                nbi.TypeCode = "CATEGORYLANG";
                nbi.ModuleId = -1;
                nbi.ItemID = -1;
                nbi.Lang = lang;
                nbi.ParentItemId = itemId;
                objCtrl.Update(nbi);
            }

            return itemId;
        }
        public static NBrightInfo CalcQtyPromoItem(NBrightInfo p, NBrightInfo cartItemInfo)
        {
            var objCtrl     = new NBrightBuyController();
            var typeselect  = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid  = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
            var promoname   = p.GetXmlProperty("genxml/textbox/name");
            var amounttype  = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
            var amount      = p.GetXmlPropertyDouble("genxml/textbox/amount");
            var overwrite   = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
            var disabled    = p.GetXmlPropertyBool("genxml/checkbox/disabled");
            var rangeList   = p.GetXmlProperty("genxml/textbox/range");

            if (!disabled)
            {
                var productid = cartItemInfo.GetXmlPropertyInt("genxml/productid");

                if (productid > 0)
                {
                    var prodData = new ProductData(productid, Utils.GetCurrentCulture());
                    if (prodData.Exists)
                    {
                        var groupid = catgroupid;
                        if (typeselect == "prop")
                        {
                            groupid = propgroupid;
                        }
                        var gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture());
                        if (gCat == null)
                        {
                            return(cartItemInfo);
                        }

                        if (prodData.HasProperty(gCat.CategoryRef) || prodData.IsInCategory(gCat.CategoryRef))
                        {
                            var runcalc = true;
                            // build range Data
                            var rangeData = new List <RangeItem>();
                            var rl        = rangeList.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var s in rl)
                            {
                                var ri = s.Split('=');
                                if (ri.Count() == 2 && Utils.IsNumeric(ri[1]))
                                {
                                    var riV = ri[0].Split('-');
                                    if (riV.Count() == 2 && Utils.IsNumeric(riV[0]) && Utils.IsNumeric(riV[1]))
                                    {
                                        var rItem = new RangeItem();
                                        rItem.RangeLow  = Convert.ToDouble(riV[0], CultureInfo.GetCultureInfo("en-US"));
                                        rItem.Cost      = Convert.ToDouble(ri[1], CultureInfo.GetCultureInfo("en-US"));
                                        rItem.RangeHigh = Convert.ToDouble(riV[1], CultureInfo.GetCultureInfo("en-US"));
                                        rangeData.Add(rItem);
                                    }
                                }
                            }

                            var unitcost   = cartItemInfo.GetXmlPropertyDouble("genxml/unitcost");
                            var promoprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice");
                            var rangeValue = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
                            var basecost   = unitcost;

                            foreach (var i in rangeData)
                            {
                                if (rangeValue >= i.RangeLow && rangeValue < i.RangeHigh)
                                {
                                    double newsaleprice = 0;

                                    if (amounttype == "1")
                                    {
                                        // percentage discount
                                        newsaleprice = Math.Round(basecost - ((basecost / 100) * i.Cost), 4);
                                    }
                                    else
                                    {
                                        // amount discount
                                        newsaleprice = basecost - i.Cost;
                                        if (newsaleprice < 0)
                                        {
                                            newsaleprice = 0;
                                        }
                                    }

                                    cartItemInfo.SetXmlPropertyDouble("genxml/promoprice", newsaleprice);
                                }
                            }
                        }
                    }
                }
            }
            return(cartItemInfo);
        }
Beispiel #16
0
        public override NBrightInfo CalculatePromotion(int portalId, NBrightInfo cartInfo)
        {
            // loop through cart items
            var rtncartInfo = (NBrightInfo)cartInfo.Clone();
            try
            {

                var cartData = new CartData(cartInfo.PortalId);
                var cartList = cartData.GetCartItemList();

                foreach (var cartItemInfo in cartList)
                {
                    cartInfo.SetXmlPropertyDouble("genxml/items/genxml[./itemcode = '" + cartItemInfo.GetXmlProperty("genxml/itemcode") + "']/promodiscount", 0); // remove any existing discount
                    if (cartItemInfo.GetXmlProperty("genxml/productxml/genxml/hidden/promotype") == "PROMOMULTIBUY")
                    {

                        var promoid = cartItemInfo.GetXmlPropertyInt("genxml/productxml/genxml/hidden/promoid");
                        var objCtrl = new NBrightBuyController();
                        var promoData = objCtrl.GetData(promoid);
                        if (promoData != null)
                        {
                            //NOTE: WE nedd to process disabld promotions so they can be removed from cart

                            var buyqty = promoData.GetXmlPropertyInt("genxml/textbox/buyqty");
                            var validfrom = promoData.GetXmlProperty("genxml/textbox/validfrom");
                            var validuntil = promoData.GetXmlProperty("genxml/textbox/validuntil");
                            var propbuygroupid = promoData.GetXmlProperty("genxml/dropdownlist/propbuy");
                            var propapplygroupid = promoData.GetXmlProperty("genxml/dropdownlist/propapply");
                            var amounttype = promoData.GetXmlProperty("genxml/radiobuttonlist/amounttype");
                            var amount = promoData.GetXmlPropertyDouble("genxml/textbox/amount");

                                // Applied discount to this single cart item
                            if (!promoData.GetXmlPropertyBool("genxml/checkbox/disabled") && cartItemInfo.GetXmlPropertyInt("genxml/qty") >= buyqty && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) // check we have correct qty to activate promo
                            {
                                var dteF = Convert.ToDateTime(validfrom).Date;
                                var dteU = Convert.ToDateTime(validuntil).Date;
                                if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                                {
                                    // calc discount amount

                                    var cartqty = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
                                    var qtycount = cartqty;
                                    var unitcost = cartItemInfo.GetXmlPropertyDouble("genxml/basecost");
                                    double discountamt = 0;
                                    while (qtycount > buyqty)
                                    {
                                        if (amounttype == "1")
                                        {
                                            discountamt += (unitcost - amount);
                                        }
                                        else
                                        {
                                            discountamt += ((unitcost/100)*amount);
                                        }
                                        if (discountamt < 0) discountamt = 0;

                                        qtycount = (qtycount - (buyqty + 1)); // +1 so we allow for discount 1 in basket.
                                    }

                                    cartInfo.SetXmlPropertyDouble("genxml/items/genxml[./itemcode = '" + cartItemInfo.GetXmlProperty("genxml/itemcode") + "']/promodiscount", discountamt);

                                }
                            }
                        }
                    }
                }

                return cartInfo;
            }
            catch (Exception ex)
            {
                var x = ex.ToString();
                return rtncartInfo;
            }
        }
Beispiel #17
0
        public override NBrightInfo Calculate(NBrightInfo cartInfo)
        {
            var info = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3") // no tax
            {
                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                return cartInfo;
            }

            var rateDic = GetRates();
            if (!rateDic.Any()) return cartInfo;

            // loop through each item and calc the tax for each.
            var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*");
            if (nodList != null)
            {
                Double taxtotal = 0;

                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    taxtotal += CalculateItemTax(nbi);
                }

                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal);
                if (taxtype == "1") cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); // tax already in total, so don't apply any more tax.
                if (taxtype == "2") cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal);

                var taxcountry = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                var storecountry = StoreSettings.Current.Get("storecountry");
                var valideutaxcountrycode = info.GetXmlProperty("genxml/textbox/valideutaxcountrycode");
                var isvalidEU = false;
                valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ",";
                if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ","))) isvalidEU = true;

                // Check for EU tax number.
                var enabletaxnumber = info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber");
                if (enabletaxnumber)
                {
                    var taxnumber = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/taxnumber");
                    var storetaxnumber = StoreSettings.Current.Get("storetaxnumber");
                    if (storetaxnumber.Length >= 2) storetaxnumber = storetaxnumber.Substring(0, 2).ToUpper();
                    if (taxnumber.Length >= 2) taxnumber = taxnumber.Substring(0, 2).ToUpper();
                    if (taxnumber != storetaxnumber && taxnumber != "")
                    {
                        // not matching merchant country, so remove tax
                        if (taxtype == "1")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal*-1);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal*-1);
                        }
                        if (taxtype == "2")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                        }
                    }
                }

                // Check for country.
                var enabletaxcountry = info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry");
                if (enabletaxcountry)
                {
                    if (taxcountry != "")
                    {
                        if (taxcountry != storecountry && !isvalidEU)
                        {
                            // not matching merchant country, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

                // check for region exempt (in same country)
                var taxexemptregions = info.GetXmlProperty("genxml/textbox/taxexemptregions");
                if (taxexemptregions != "" && taxcountry == storecountry)
                {
                    taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ","") + ",";
                    var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                    if (taxregioncode == "") taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion");
                    if (taxregioncode != "")
                    {
                        if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ","))
                        {
                            // not matching merchant region, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

            }

            return cartInfo;
        }
        public override NBrightInfo CalculateVoucherAmount(int portalId, int userId, NBrightInfo cartInfo, string discountcode)
        {
            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "");
            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", "0"); // reset discount amount
            Double discountcodeamt = 0;
            if (userId > 0)
            {
                var clientData = new ClientData(portalId, userId);
                if (clientData.DiscountCodes.Count > 0)
                {
                    var subtotal = cartInfo.GetXmlPropertyDouble("genxml/subtotal");
                    // do client voucher discount on total cart
                    foreach (var d in clientData.VoucherCodes)
                    {
                        var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                        var validutildate = DateTime.Today;
                        if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                        if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                        {
                            var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                            if (amount > 0)
                            {
                                if (subtotal >= amount)
                                    discountcodeamt = amount;
                                else
                                    discountcodeamt = subtotal;
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                            }
                            else
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                            }
                        }
                        if (discountcodeamt > 0) break;
                    }
                }
            }

            if (discountcodeamt == 0) // if no client level, calc any portal level percentage discount
            {
                var objCtrl = new NBrightBuyController();
                var d = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (d != null)
                {
                    var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                    var validutildate = DateTime.Today;
                    if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                    if (validutildate >= DateTime.Today && d.GetXmlProperty("genxml/radiobuttonlist/amounttype") == "1")
                    {
                        var minamountlimit = d.GetXmlPropertyDouble("genxml/textbox/minamountlimit");
                        var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                        var usage = d.GetXmlPropertyDouble("genxml/textbox/usage");
                        var usagelimit = d.GetXmlPropertyDouble("genxml/textbox/usagelimit");
                        var appliedsubtotal = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
                        if (amount > 0 && (usagelimit == 0 || usagelimit > usage) && (appliedsubtotal >= minamountlimit))
                        {
                            discountcodeamt = amount;
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                        }
                        else
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                        }
                    }
                }
            }

            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", discountcodeamt); // reset discount amount

            return cartInfo;
        }
Beispiel #19
0
        private List<NBrightInfo> BuildModelList(NBrightInfo dataItemObj,Boolean addSalePrices = false)
        {
            // see  if we have a cart record
            var xpathprefix = "";
            var cartrecord = dataItemObj.GetXmlProperty("genxml/productid") != ""; // if we have a productid node, then is datarecord is a cart item
            if (cartrecord) xpathprefix = "genxml/productxml/";

            //build models list
            var objL = new List<NBrightInfo>();
            var nodList = dataItemObj.XMLDoc.SelectNodes(xpathprefix + "genxml/models/*");
            if (nodList != null)
            {

                #region "Init"

                var isDealer = CmsProviderManager.Default.IsInRole(StoreSettings.DealerRole);

                #endregion

                var lp = 1;
                foreach (XmlNode nod in nodList)
                {
                    // check if Deleted
                    var selectDeletedFlag = nod.SelectSingleNode("checkbox/chkdeleted");
                    if ((selectDeletedFlag == null) || selectDeletedFlag.InnerText != "True")
                    {
                    // check if hidden
                        var selectHiddenFlag = nod.SelectSingleNode("checkbox/chkishidden");
                        if ((selectHiddenFlag == null) || selectHiddenFlag.InnerText != "True")
                        {
                            // check if dealer
                            var selectDealerFlag = nod.SelectSingleNode("checkbox/chkdealeronly");
                            if (((selectDealerFlag == null) || (!isDealer && (selectDealerFlag.InnerText != "True"))) | isDealer)
                            {
                                // get modelid
                                var nodModelId = nod.SelectSingleNode("hidden/modelid");
                                var modelId = "";
                                if (nodModelId != null) modelId = nodModelId.InnerText;

                                //Build NBrightInfo class for model
                                var o = new NBrightInfo();
                                o.XMLData = nod.OuterXml;

                                #region "Add Lanaguge Data"

                                var nodLang = dataItemObj.XMLDoc.SelectSingleNode(xpathprefix + "genxml/lang/genxml/models/genxml[" + lp.ToString("") + "]");
                                if (nodLang != null)
                                {
                                    o.AddSingleNode("lang", "", "genxml");
                                    o.AddXmlNode(nodLang.OuterXml, "genxml", "genxml/lang");
                                }

                                #endregion

                                #region "Prices"

                                if (addSalePrices)
                                {
                                    var uInfo = UserController.GetCurrentUserInfo();
                                    if (uInfo != null)
                                    {
                                        o.SetXmlPropertyDouble("genxml/hidden/saleprice", "-1"); // set to -1 so unitcost is displayed (turns off saleprice)
                                        //[TODO: convert to new promotion provider]
                                        //var objPromoCtrl = new PromoController();
                                        //var objPCtrl = new ProductController();
                                        //var objM = objPCtrl.GetModel(modelId, Utils.GetCurrentCulture());
                                        //var salePrice = objPromoCtrl.GetSalePrice(objM, uInfo);
                                        //o.AddSingleNode("saleprice", salePrice.ToString(CultureInfo.GetCultureInfo("en-US")), "genxml/hidden");
                                    }
                                }

                                #endregion

                                // product data for display in modellist
                                o.SetXmlProperty("genxml/lang/genxml/textbox/txtproductname", dataItemObj.GetXmlProperty(xpathprefix + "genxml/lang/genxml/textbox/txtproductname"));
                                o.SetXmlProperty("genxml/textbox/txtproductref", dataItemObj.GetXmlProperty(xpathprefix + "genxml/textbox/txtproductref"));

                                if (cartrecord)
                                    o.SetXmlProperty("genxml/hidden/productid", dataItemObj.GetXmlProperty("genxml/productid"));
                                else
                                o.SetXmlProperty("genxml/hidden/productid", dataItemObj.ItemID.ToString(""));

                                objL.Add(o);
                            }
                        }
                    }
                    lp += 1;
                }
            }
            return objL;
        }
Beispiel #20
0
        private NBrightInfo ValidateCartItem(int portalId, int userId, NBrightInfo cartItemInfo)
        {
            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemBefore, cartItemInfo);

            var modelid = cartItemInfo.GetXmlProperty("genxml/modelid");
            var prdid = cartItemInfo.GetXmlPropertyInt("genxml/productid");
            var qty = cartItemInfo.GetXmlPropertyDouble("genxml/qty");

            var prd = ProductUtils.GetProductData(prdid, Utils.GetCurrentCulture());
            if (!prd.Exists || prd.Disabled) return null; //Invalid product remove from cart
            var prdModel = prd.GetModel(modelid);
            if (prdModel == null) return null; // Invalid Model remove from cart
            // check if dealer (for tax calc)
            var userInfo = UserController.GetUserById(portalId, userId);
            if (userInfo != null && userInfo.IsInRole(StoreSettings.DealerRole) && StoreSettings.Current.Get("enabledealer") == "True")
                cartItemInfo.SetXmlProperty("genxml/isdealer", "True");
            else
                cartItemInfo.SetXmlProperty("genxml/isdealer", "False");

            // check for price change
            var unitcost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
            var dealercost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
            var saleprice = prdModel.GetXmlPropertyDouble("genxml/textbox/txtsaleprice");

            // calc sale price
            var sellcost = unitcost;
            if (saleprice > 0 && saleprice < sellcost) sellcost = saleprice;

            //stock control
            if (prdModel != null)
            {
                var stockon = prdModel.GetXmlPropertyBool("genxml/checkbox/chkstockon");
                var stocklevel = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining");
                var minStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyminstock");
                if (minStock == 0) minStock = StoreSettings.Current.GetInt("minimumstocklevel");
                var maxStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtystockset");
                var weight = prdModel.GetXmlPropertyDouble("genxml/textbox/weight");
                if (stockon)
                {
                    stocklevel = stocklevel - minStock;
                    stocklevel = stocklevel - prd.GetModelTransQty(modelid, _cartId);
                    if (stocklevel < qty)
                    {
                        qty = stocklevel;
                        if (qty <= 0)
                        {
                            qty = 0;
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "OUTOFSTOCK");
                        }
                        else
                        {
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "STOCKADJ");
                        }
                        base.SetValidated(false);
                        cartItemInfo.SetXmlPropertyDouble("genxml/qty", qty.ToString(""));
                    }
                }

                Double additionalCosts = 0;
                var optNods = cartItemInfo.XMLDoc.SelectNodes("genxml/options/*");
                if (optNods != null)
                {
                    var lp = 1;
                    foreach (XmlNode nod in optNods)
                    {
                        var optid = nod.SelectSingleNode("optid");
                        if (optid != null)
                        {
                            var optvalueid = nod.SelectSingleNode("optvalueid");
                            if (optvalueid != null && optvalueid.InnerText != "False")
                            {
                                XmlNode  optvalcostnod;
                                if (optvalueid.InnerText == "True")
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues[@optionid='" + optid.InnerText + "']/genxml/textbox/txtaddedcost");
                                else
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues/genxml[./hidden/optionvalueid='" + optvalueid.InnerText + "']/textbox/txtaddedcost");

                                if (optvalcostnod != null)
                                {
                                    var optvalcost = optvalcostnod.InnerText;
                                    if (Utils.IsNumeric(optvalcost))
                                    {
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", optvalcost);
                                        var optvaltotal = Convert.ToDouble(optvalcost, CultureInfo.GetCultureInfo("en-US"))*qty;
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", optvaltotal);
                                        additionalCosts += optvaltotal;
                                    }
                                }
                                else
                                {
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", "0");
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", "0");
                                }
                            }
                        }
                        lp += 1;
                    }
                }

                if (qty > 0)  // can't devide by zero
                {
                    unitcost += (additionalCosts / qty);
                    if (dealercost > 0) dealercost += (additionalCosts / qty); // zero turns off
                    if (saleprice > 0) saleprice += (additionalCosts / qty); // zero turns off
                    sellcost += (additionalCosts / qty);
                }

                var totalcost = qty * sellcost;
                var totaldealercost = qty * dealercost;
                var totalweight = weight * qty;

                if (unitcost != cartItemInfo.GetXmlPropertyDouble("genxml/unitcost") || dealercost != cartItemInfo.GetXmlPropertyDouble("genxml/dealercost") || saleprice != cartItemInfo.GetXmlPropertyDouble("genxml/saleprice"))
                {
                    cartItemInfo.SetXmlPropertyDouble("genxml/unitcost", unitcost);
                    cartItemInfo.SetXmlPropertyDouble("genxml/dealercost", dealercost);
                    cartItemInfo.SetXmlPropertyDouble("genxml/saleprice", saleprice);
                    cartItemInfo.RemoveXmlNode("genxml/productxml");
                    cartItemInfo.AddSingleNode("productxml", prd.Info.XMLData, "genxml");
                }

                cartItemInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight.ToString(""));
                cartItemInfo.SetXmlPropertyDouble("genxml/totalcost", totalcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealercost", totaldealercost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", (totalcost - totaldealercost));

                Double salediscount = 0;
                Double dealerdiscount = 0;
                Double discountcodeamt = 0;
                Double totaldiscount = 0;

                //add update genxml/discountcodeamt
                if (saleprice == 0) // discount codes are only valid for items not on sale
                {
                    var discountcode = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
                    cartItemInfo = DiscountCodeInterface.UpdateItemPercentDiscountCode(PortalId, UserId, cartItemInfo, discountcode);
                    discountcodeamt = cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt");
                    if (discountcodeamt > 0) PurchaseInfo.SetXmlProperty("genxml/discountprocessed", "False");
                    totaldiscount = discountcodeamt;
                }
                else
                {
                    salediscount = (unitcost - saleprice);
                    totaldiscount = salediscount * qty;
                }

                var totalsalediscount = salediscount * qty;
                var totaldealerdiscount = dealerdiscount * qty;
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);
                cartItemInfo.SetXmlPropertyDouble("genxml/salediscount", totalsalediscount);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerdiscount", totaldealerdiscount);

                cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", AppliedCost(portalId, userId, totalcost, totaldealercost));
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedcost", AppliedCost(portalId, userId, sellcost, dealercost));

                // calc tax for item
                var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/hidden/taxproviderkey");
                var taxprov = TaxInterface.Instance(taxproviderkey);
                if (taxprov != null)
                {
                    var nbi = (NBrightInfo)cartItemInfo.Clone();
                    cartItemInfo.SetXmlPropertyDouble("genxml/taxcost", taxprov.CalculateItemTax(nbi));
                }

            }

            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemAfter, cartItemInfo);

            return cartItemInfo;
        }
Beispiel #21
0
        public void Update(NBrightInfo info)
        {
            // build list of xpath fields that need processing.
            var updatefields = new List <String>();
            var fieldList    = NBrightBuyUtils.GetAllFieldxPaths(info);

            foreach (var xpath in fieldList)
            {
                if (info.GetXmlProperty(xpath + "/@update") == "lang")
                {
                    updatefields.Add(xpath);
                }
            }

            foreach (var f in updatefields)
            {
                if (f.EndsWith("/message"))
                {
                    // special processing for editor, to place code in standard place.
                    if (DataLangRecord.XMLDoc.SelectSingleNode("genxml/edt") == null)
                    {
                        DataLangRecord.AddSingleNode("edt", "", "genxml");
                    }
                    if (info.GetXmlProperty("genxml/textbox/message") == "")
                    {
                        DataLangRecord.SetXmlProperty("genxml/edt/message", info.GetXmlPropertyRaw("genxml/edt/message"));
                    }
                    else
                    {
                        DataLangRecord.SetXmlProperty("genxml/edt/message", info.GetXmlPropertyRaw("genxml/textbox/message")); // ajax on ckeditor (Ajax diesn't work for telrik)
                    }
                }
                else
                {
                    DataLangRecord.RemoveXmlNode(f);
                    var xpathDest = f.Split('/');
                    if (xpathDest.Count() >= 2)
                    {
                        DataLangRecord.AddXmlNode(info.XMLData, f, xpathDest[0] + "/" + xpathDest[1]);
                    }
                }

                var datatype = info.GetXmlProperty(f + "/@datatype");
                if (datatype == "date")
                {
                    DataLangRecord.SetXmlProperty(f, info.GetXmlProperty(f), TypeCode.DateTime);
                }
                else if (datatype == "double")
                {
                    DataLangRecord.SetXmlPropertyDouble(f, info.GetXmlProperty(f));
                }
                else if (datatype == "html")
                {
                    DataLangRecord.SetXmlProperty(f, info.GetXmlPropertyRaw(f));
                }
                else
                {
                    DataLangRecord.SetXmlProperty(f, info.GetXmlProperty(f).Trim());
                }


                DataRecord.RemoveXmlNode(f);
            }


            updatefields = new List <String>();
            fieldList    = NBrightBuyUtils.GetAllFieldxPaths(info);
            foreach (var xpath in fieldList)
            {
                var id = xpath.Split('/').Last();
                if (info.GetXmlProperty(xpath + "/@update") == "save")
                {
                    updatefields.Add(xpath);
                }
            }

            foreach (var f in updatefields)
            {
                var datatype = info.GetXmlProperty(f + "/@datatype");
                if (datatype == "date")
                {
                    DataRecord.SetXmlProperty(f, info.GetXmlProperty(f), TypeCode.DateTime);
                }
                else if (datatype == "double")
                {
                    DataRecord.SetXmlPropertyDouble(f, info.GetXmlProperty(f));
                }
                else if (datatype == "html")
                {
                    DataRecord.SetXmlProperty(f, info.GetXmlPropertyRaw(f));
                }
                else
                {
                    DataRecord.SetXmlProperty(f, info.GetXmlProperty(f));
                }

                // if we have a image field then we need to create the imageurl field
                if (info.GetXmlProperty(f.Replace("textbox/", "hidden/hidinfo")) == "Img=True")
                {
                    DataRecord.SetXmlProperty(f.Replace("textbox/", "hidden/") + "url", StoreSettings.Current.FolderImages + "/" + info.GetXmlProperty(f.Replace("textbox/", "hidden/hid")));
                    DataRecord.SetXmlProperty(f.Replace("textbox/", "hidden/") + "path", StoreSettings.Current.FolderImagesMapPath + "\\" + info.GetXmlProperty(f.Replace("textbox/", "hidden/hid")));
                }
                if (f == "genxml/dropdownlist/ddlparentcatid")
                {
                    var parentitemid = info.GetXmlProperty(f);
                    if (!Utils.IsNumeric(parentitemid))
                    {
                        parentitemid = "0";
                    }
                    if (DataRecord.ParentItemId != Convert.ToInt32(parentitemid))
                    {
                        _oldcatcascadeid        = DataRecord.ParentItemId;
                        _doCascadeIndex         = true;
                        DataRecord.ParentItemId = Convert.ToInt32(parentitemid);
                    }
                }
                DataLangRecord.RemoveXmlNode(f);
            }
        }
Beispiel #22
0
        public override NBrightInfo Calculate(NBrightInfo cartInfo)
        {
            var info    = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3") // no tax
            {
                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                return(cartInfo);
            }


            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(cartInfo);
            }

            // loop through each item and calc the tax for each.
            var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*");

            if (nodList != null)
            {
                Double taxtotal = 0;

                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    taxtotal   += CalculateItemTax(nbi);
                }

                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal);
                if (taxtype == "1")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);                 // tax already in total, so don't apply any more tax.
                }
                if (taxtype == "2")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal);
                }


                var taxcountry            = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                var storecountry          = StoreSettings.Current.Get("storecountry");
                var valideutaxcountrycode = info.GetXmlProperty("genxml/textbox/valideutaxcountrycode");
                var isvalidEU             = false;
                valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ",";
                if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ",")))
                {
                    isvalidEU = true;
                }

                // Check for EU tax number.
                var enabletaxnumber = info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber");
                if (enabletaxnumber)
                {
                    var taxnumber      = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/taxnumber");
                    var storetaxnumber = StoreSettings.Current.Get("storetaxnumber");
                    if (storetaxnumber.Length >= 2)
                    {
                        storetaxnumber = storetaxnumber.Substring(0, 2).ToUpper();
                    }
                    if (taxnumber.Length >= 2)
                    {
                        taxnumber = taxnumber.Substring(0, 2).ToUpper();
                    }
                    if (taxnumber != storetaxnumber && taxnumber != "")
                    {
                        // not matching merchant country, so remove tax
                        if (taxtype == "1")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                        }
                        if (taxtype == "2")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                        }
                    }
                }

                // Check for country.
                var enabletaxcountry = info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry");
                if (enabletaxcountry)
                {
                    if (taxcountry != "")
                    {
                        if (taxcountry != storecountry && !isvalidEU)
                        {
                            // not matching merchant country, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

                // check for region exempt (in same country)
                var taxexemptregions = info.GetXmlProperty("genxml/textbox/taxexemptregions");
                if (taxexemptregions != "" && taxcountry == storecountry)
                {
                    taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ", "") + ",";
                    var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                    if (taxregioncode == "")
                    {
                        taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion");
                    }
                    if (taxregioncode != "")
                    {
                        if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ","))
                        {
                            // not matching merchant region, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }
            }


            return(cartInfo);
        }
Beispiel #23
0
        public override NBrightInfo CalculatePromotion(int portalId, NBrightInfo cartInfo)
        {
            // loop through cart items
            var rtncartInfo = (NBrightInfo)cartInfo.Clone();

            try
            {
                var cartData = new CartData(cartInfo.PortalId);
                var cartList = cartData.GetCartItemList();

                foreach (var cartItemInfo in cartList)
                {
                    cartInfo.SetXmlPropertyDouble("genxml/items/genxml[./itemcode = '" + cartItemInfo.GetXmlProperty("genxml/itemcode") + "']/promodiscount", 0); // remove any existing discount
                    if (cartItemInfo.GetXmlProperty("genxml/productxml/genxml/hidden/promotype") == "PROMOMULTIBUY")
                    {
                        var promoid   = cartItemInfo.GetXmlPropertyInt("genxml/productxml/genxml/hidden/promoid");
                        var objCtrl   = new NBrightBuyController();
                        var promoData = objCtrl.GetData(promoid);
                        if (promoData != null)
                        {
                            //NOTE: WE nedd to process disabld promotions so they can be removed from cart

                            var buyqty           = promoData.GetXmlPropertyInt("genxml/textbox/buyqty");
                            var validfrom        = promoData.GetXmlProperty("genxml/textbox/validfrom");
                            var validuntil       = promoData.GetXmlProperty("genxml/textbox/validuntil");
                            var propbuygroupid   = promoData.GetXmlProperty("genxml/dropdownlist/propbuy");
                            var propapplygroupid = promoData.GetXmlProperty("genxml/dropdownlist/propapply");
                            var amounttype       = promoData.GetXmlProperty("genxml/radiobuttonlist/amounttype");
                            var amount           = promoData.GetXmlPropertyDouble("genxml/textbox/amount");


                            // Applied discount to this single cart item
                            if (!promoData.GetXmlPropertyBool("genxml/checkbox/disabled") && cartItemInfo.GetXmlPropertyInt("genxml/qty") >= buyqty && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) // check we have correct qty to activate promo
                            {
                                var dteF = Convert.ToDateTime(validfrom).Date;
                                var dteU = Convert.ToDateTime(validuntil).Date;
                                if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                                {
                                    // calc discount amount

                                    var    cartqty     = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
                                    var    qtycount    = cartqty;
                                    var    unitcost    = cartItemInfo.GetXmlPropertyDouble("genxml/basecost");
                                    double discountamt = 0;
                                    while (qtycount > buyqty)
                                    {
                                        if (amounttype == "1")
                                        {
                                            discountamt += (unitcost - amount);
                                        }
                                        else
                                        {
                                            discountamt += ((unitcost / 100) * amount);
                                        }
                                        if (discountamt < 0)
                                        {
                                            discountamt = 0;
                                        }

                                        qtycount = (qtycount - (buyqty + 1)); // +1 so we allow for discount 1 in basket.
                                    }

                                    cartInfo.SetXmlPropertyDouble("genxml/items/genxml[./itemcode = '" + cartItemInfo.GetXmlProperty("genxml/itemcode") + "']/promodiscount", discountamt);
                                }
                            }
                        }
                    }
                }

                return(cartInfo);
            }
            catch (Exception ex)
            {
                var x = ex.ToString();
                return(rtncartInfo);
            }
        }
        public override NBrightInfo CalculateVoucherAmount(int portalId, int userId, NBrightInfo cartInfo, string discountcode)
        {
            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "");
            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", "0"); // reset discount amount
            Double discountcodeamt = 0;

            if (userId > 0)
            {
                var clientData = new ClientData(portalId, userId);
                if (clientData.DiscountCodes.Count > 0)
                {
                    var subtotal = cartInfo.GetXmlPropertyDouble("genxml/subtotal");
                    // do client voucher discount on total cart
                    foreach (var d in clientData.VoucherCodes)
                    {
                        var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                        var validutildate = DateTime.Today;
                        if (Utils.IsDate(validutil))
                        {
                            validutildate = Convert.ToDateTime(validutil);
                        }
                        if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                        {
                            var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                            if (amount > 0)
                            {
                                if (subtotal >= amount)
                                {
                                    discountcodeamt = amount;
                                }
                                else
                                {
                                    discountcodeamt = subtotal;
                                }
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                            }
                            else
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                            }
                        }
                        if (discountcodeamt > 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (discountcodeamt == 0) // if no client level, calc any portal level percentage discount
            {
                var objCtrl = new NBrightBuyController();
                var d       = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (d != null)
                {
                    var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                    var validutildate = DateTime.Today;
                    if (Utils.IsDate(validutil))
                    {
                        validutildate = Convert.ToDateTime(validutil);
                    }
                    if (validutildate >= DateTime.Today && d.GetXmlProperty("genxml/radiobuttonlist/amounttype") == "1")
                    {
                        var minamountlimit  = d.GetXmlPropertyDouble("genxml/textbox/minamountlimit");
                        var amount          = d.GetXmlPropertyDouble("genxml/textbox/amount");
                        var usage           = d.GetXmlPropertyDouble("genxml/textbox/usage");
                        var usagelimit      = d.GetXmlPropertyDouble("genxml/textbox/usagelimit");
                        var appliedsubtotal = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
                        if (amount > 0 && (usagelimit == 0 || usagelimit > usage) && (appliedsubtotal >= minamountlimit))
                        {
                            discountcodeamt = amount;
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                        }
                        else
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                        }
                    }
                }
            }

            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", discountcodeamt); // reset discount amount

            return(cartInfo);
        }