예제 #1
0
        private void ShippingProviderDataBind(object sender, EventArgs e)
        {
            var rbl = (RadioButtonList)sender;
            var container = (IDataItemContainer)rbl.NamingContainer;
            try
            {
                rbl.Visible = visibleStatus.DefaultIfEmpty(true).First();
                if (rbl.Visible)
                {
                    var strXML = Convert.ToString(DataBinder.Eval(container.DataItem, "XMLData"));
                    var nbInfo = new NBrightInfo();
                    nbInfo.XMLData = strXML;
                    var selectval = nbInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider");

                    // get country code, to CheckBox if provider is valid.
                    var cartData = new CartData(PortalSettings.Current.PortalId);

                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList = pluginData.GetShippingProviders();
                        foreach (var d in provList)
                        {
                            var isValid = true;
                            var shipprov = ShippingInterface.Instance(d.Key);
                            if (shipprov != null) isValid = shipprov.IsValid(cartData.PurchaseInfo);
                            var p = d.Value;
                            if (isValid)
                            {
                                var li = new ListItem();
                                li.Text = p.GetXmlProperty("genxml/textbox/name");
                                li.Value = p.GetXmlProperty("genxml/textbox/ctrl");
                                if (li.Value == selectval) li.Selected = true;
                                rbl.Items.Add(li);
                            }
                        }
                        if (rbl.SelectedValue == "" && rbl.Items.Count > 0) rbl.SelectedIndex = 0;

                }

            }
            catch (Exception)
            {
                rbl.Visible = false;
            }
        }
예제 #2
0
        public override TestOfData TestOfDataBinding(object sender, EventArgs e)
        {
            var rtnData = new TestOfData();
            rtnData.DataValue = null;
            rtnData.TestValue = null;
            var lc = (Literal)sender;
            var container = (IDataItemContainer)lc.NamingContainer;
            try
            {
                NBrightInfo info;

                ProductData prodData;
                CatProdXref xrefData;

                var xmlDoc = new XmlDocument();
                CartData currentcart;

                xmlDoc.LoadXml("<root>" + lc.Text + "</root>");
                var xmlNod = xmlDoc.SelectSingleNode("root/tag");

                if (container.DataItem != null && xmlNod != null && (xmlNod.Attributes != null && xmlNod.Attributes["function"] != null))
                {
                    rtnData.DataValue = "FALSE";

                    XmlNode nod;
                    var testValue = "";
                    if ((xmlNod.Attributes["testvalue"] != null)) testValue = xmlNod.Attributes["testvalue"].Value;

                    // check for setting key
                    var settingkey = "";
                    if ((xmlNod.Attributes["key"] != null)) settingkey = xmlNod.Attributes["key"].Value;

                    var role = "";
                    if ((xmlNod.Attributes["role"] != null)) role = xmlNod.Attributes["role"].Value;

                    var index = "";
                    if ((xmlNod.Attributes["index"] != null)) index = xmlNod.Attributes["index"].Value;

                    var modulekey = "";
                    if ((xmlNod.Attributes["modulekey"] != null)) modulekey = xmlNod.Attributes["modulekey"].Value;

                    var targetmodulekey = "";
                    if ((xmlNod.Attributes["targetmodulekey"] != null)) targetmodulekey = xmlNod.Attributes["targetmodulekey"].Value;

                    // do special tests for named fucntions
                    switch (xmlNod.Attributes["function"].Value.ToLower())
                    {
                        case "searchactive":
                            var navdata2 = new NavigationData(PortalSettings.Current.PortalId, targetmodulekey);
                            if (navdata2.Criteria == "") rtnData.DataValue = "FALSE";
                            else rtnData.DataValue = "TRUE";
                            break;
                        case "productcount":
                            var navdata = new NavigationData(PortalSettings.Current.PortalId, modulekey);
                            rtnData.DataValue = navdata.RecordCount;
                            break;
                        case "price":
                            rtnData.DataValue = GetFromPrice((NBrightInfo) container.DataItem);
                            break;
                        case "dealerprice":
                            rtnData.DataValue = GetDealerPrice((NBrightInfo) container.DataItem);
                            break;
                        case "saleprice":
                            rtnData.DataValue = GetSalePrice((NBrightInfo) container.DataItem);
                            break;
                        case "imgexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/imgs/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "modelexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/models/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "optionexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/options/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "isinstock":
                            if (IsInStock((NBrightInfo) container.DataItem))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "ismodelinstock":
                            if (IsModelInStock((NBrightInfo) container.DataItem))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "inwishlist":
                            var productid = DataBinder.Eval(container.DataItem, "ItemId").ToString();
                            if (Utils.IsNumeric(productid))
                            {
                                var listname = "ItemList";
                                if ((xmlNod.Attributes["listname"] != null)) listname = xmlNod.Attributes["listname"].Value;

                                var wl = new ItemListData(listname);
                                if (wl.IsInList(productid))
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isonsale":
                            var saleprice = GetSalePriceDouble((NBrightInfo) container.DataItem);
                            if (saleprice > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasrelateditems":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.GetRelatedProducts().Count > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasdocuments":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.Docs.Count > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "haspurchasedocuments":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.Docs.Select(i => i.GetXmlProperty("genxml/checkbox/chkpurchase") == "True").Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasproperty":
                            info = (NBrightInfo) container.DataItem;
                            xrefData = new CatProdXref();
                            if (xrefData.IsProductInCategory(info.ItemID,testValue))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isincategory":
                            info = (NBrightInfo) container.DataItem;
                            xrefData = new CatProdXref();
                            if (xrefData.IsProductInCategory(info.ItemID,testValue))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isdocpurchasable":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/docs/genxml[" + index + "]/hidden/docid");
                            if (nod != null)
                            {
                                info = (NBrightInfo) container.DataItem;
                                prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                                if (prodData.Docs.Select(i => i.GetXmlProperty("genxml/checkbox/chkpurchase") == "True" && i.GetXmlProperty("genxml/hidden/docid") == nod.InnerText).Any())
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isdocpurchased":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/docs/genxml[" + index + "]/hidden/docid");
                            if (nod != null && Utils.IsNumeric(nod.InnerText))
                            {
                                var uInfo = UserController.GetCurrentUserInfo();
                                //[TODO: work out method of finding if user purchased document.]
                                //if (NBrightBuyV2Utils.DocHasBeenPurchasedByDocId(uInfo.UserID, Convert.ToInt32(nod.InnerText)))
                                //{
                                //    rtnData.DataValue = "TRUE";
                                //    rtnData.TestValue = "TRUE";
                                //}
                            }
                            break;
                        case "hasmodelsoroptions":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/models/genxml[2]/hidden/modelid");
                            if (nod != null && nod.InnerText != "")
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            if (rtnData.DataValue == "FALSE")
                            {
                                nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/options/genxml[1]/hidden/optionid");
                                if (nod != null && nod.InnerText != "")
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isproductincart":
                            var cartData = new CartData(PortalSettings.Current.PortalId);
                            info = (NBrightInfo) container.DataItem;
                            if (cartData.GetCartItemList().Select(i => i.GetXmlProperty("genxml/productid") == info.ItemID.ToString("")).Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "settings":
                            if (_settings != null && _settings.ContainsKey(settingkey) && _settings[settingkey] == testValue)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "debugmode":
                            if (StoreSettings.Current.DebugMode)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isinrole":
                            if (CmsProviderManager.Default.IsInRole(role))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "issuperuser":
                            if (UserController.GetCurrentUserInfo().IsSuperUser)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isuser":
                            if (UserController.GetCurrentUserInfo().UserID >= 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isclientordermode":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            if (currentcart.IsClientOrderMode())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "carteditmode":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            var editmode = currentcart.GetInfo().GetXmlProperty("genxml/carteditmode");
                            if (editmode == testValue)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "iscartempty":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            var l = currentcart.GetCartItemList();
                            if (!l.Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasshippingproviders":
                            var pluginData = new PluginData(PortalSettings.Current.PortalId);
                            var provList = pluginData.GetShippingProviders();
                            if (provList.Count > 1)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "profile":
                            var userInfo = UserController.GetCurrentUserInfo();
                            if (userInfo.UserID >= 0) rtnData.DataValue = userInfo.Profile.GetPropertyValue(settingkey);
                            break;
                        case "static":
                            break;
                        default:
                            rtnData.DataValue = null;
                            break;
                    }
                }
            }
            catch (Exception)
            {
                lc.Text = "";
            }
            return rtnData;
        }
예제 #3
0
        public void ValidateCart()
        {
            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartBefore, PurchaseInfo);

            var itemList = GetCartItemList();
            Double subtotalcost = 0;
            Double subtotaldealercost = 0;
            Double totaldealerbonus = 0;
            Double totaldiscount = 0;
            Double totaldealerdiscount = 0;
            Double totalqty = 0;
            Double totalweight = 0;
            Double totalunitcost = 0;

            var strXml = "<items>";
            foreach (var info in itemList)
            {
                // check product still exists and remove if deleted, altered or disabled.

                var cartItem = ValidateCartItem(PortalId, UserId, info);
                if (cartItem != null)
                {
                    strXml += cartItem.XMLData;
                    totalunitcost += info.GetXmlPropertyDouble("genxml/unitcost");
                    subtotalcost += info.GetXmlPropertyDouble("genxml/totalcost");
                    subtotaldealercost += info.GetXmlPropertyDouble("genxml/totaldealercost");
                    totaldealerbonus += info.GetXmlPropertyDouble("genxml/totaldealerbonus");
                    totaldiscount += info.GetXmlPropertyDouble("genxml/totaldiscount");
                    totaldealerdiscount += info.GetXmlPropertyDouble("genxml/totaldealerdiscount");
                    totalqty += info.GetXmlPropertyDouble("genxml/qty");
                    totalweight += info.GetXmlPropertyDouble("genxml/totalweight");
                }
            }
            strXml += "</items>";
            PurchaseInfo.RemoveXmlNode("genxml/items");
            PurchaseInfo.AddXmlNode(strXml, "items", "genxml");
            PopulateItemList();

            // calculate totals
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalqty", totalqty);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalunitcost", totalunitcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotalcost", subtotalcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotaldealercost", subtotaldealercost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedsubtotal", AppliedCost(PortalId, UserId, subtotalcost, subtotaldealercost));

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldealerdiscount", totaldealerdiscount);
            var applieddiscount = AppliedCost(PortalId, UserId, totaldiscount, totaldealerdiscount);
            PurchaseInfo.SetXmlPropertyDouble("genxml/applieddiscount", applieddiscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", totaldealerbonus);

            //add shipping
            Double shippingcost = 0;
            Double shippingdealercost = 0;
            var shippingkey = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
            var currentcartstage = PurchaseInfo.GetXmlProperty("genxml/currentcartstage");
            if (currentcartstage == "cartaddress" || currentcartstage == "cartsummary") // can only calc shipping on this stage.
            {
                ShippingInterface shipprov = null;
                if (shippingkey == "")
                {
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList = pluginData.GetShippingProviders();
                    foreach (var d in provList)
                    {
                        var isValid = true;
                        var shipprov1 = ShippingInterface.Instance(d.Key);
                        if (shipprov1 != null) isValid = shipprov1.IsValid(PurchaseInfo);
                        if (isValid)
                        {
                            shipprov = shipprov1;
                            if (shipprov != null) PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", shipprov.Shippingkey);
                            break;
                        }
                    }
                }
                else
                    shipprov = ShippingInterface.Instance(shippingkey);

                if (shipprov != null && !shipprov.IsValid(PurchaseInfo)) // Check we have a valid one!! if not the get another!!
                {
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList = pluginData.GetShippingProviders();
                    foreach (var d in provList)
                    {
                        var isValid = true;
                        var shipprov1 = ShippingInterface.Instance(d.Key);
                        if (shipprov1 != null) isValid = shipprov1.IsValid(PurchaseInfo);
                        if (isValid)
                        {
                            shipprov = shipprov1;
                            if (shipprov != null) PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", shipprov.Shippingkey);
                            break;
                        }
                    }
                }

                if (shipprov != null)
                {
                    PurchaseInfo = shipprov.CalculateShipping(PurchaseInfo);
                    shippingcost = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingcost");
                    shippingdealercost = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingdealercost");
                }
                PurchaseInfo.SetXmlPropertyDouble("genxml/appliedshipping", AppliedCost(PortalId, UserId, shippingcost, shippingdealercost));
            }
            else
            {
                // clear the provider if not cartshipping stage
                PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", "");
            }

            //add tax
            Double appliedtax = 0;
            var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/hidden/taxproviderkey");
            var taxprov = TaxInterface.Instance(taxproviderkey);
            if (taxprov != null)
            {
                PurchaseInfo = taxprov.Calculate(PurchaseInfo);
                appliedtax = PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtax");
            }

            //cart full total
            var dealertotal = (subtotaldealercost + shippingdealercost + appliedtax);
            var total = (subtotalcost + shippingcost + appliedtax);
            PurchaseInfo.SetXmlPropertyDouble("genxml/dealertotal", dealertotal);
            PurchaseInfo.SetXmlPropertyDouble("genxml/total", total);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedtotal", AppliedCost(PortalId, UserId, total, dealertotal));

            if (PurchaseInfo.GetXmlProperty("genxml/clientmode") == "True")
            {
                // user not editor, so stop edit mode.
                if (!UserController.GetCurrentUserInfo().IsInRole("Administrators") && !UserController.GetCurrentUserInfo().IsInRole(StoreSettings.ManagerRole) && !UserController.GetCurrentUserInfo().IsInRole(StoreSettings.EditorRole)) PurchaseInfo.SetXmlProperty("genxml/clientmode", "False");
            }

            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartAfter, PurchaseInfo);

            SavePurchaseData();
        }
예제 #4
0
 private String GetShippingProviderTemplates()
 {
     var strRtn = "";
     var pluginData = new PluginData(PortalSettings.Current.PortalId);
     var provList = pluginData.GetShippingProviders();
     foreach (var d in provList)
     {
         var p = d.Value;
         var shippingkey = p.GetXmlProperty("genxml/textbox/ctrl");
         var shipprov = ShippingInterface.Instance(shippingkey);
         if (shipprov != null)
         {
             var activeprovider = _cartInfo.GetInfo().GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
             // no shipping provider selected, so get the default one.
             if (activeprovider == "") activeprovider = provList.First().Key;
             if (activeprovider == d.Key) strRtn += shipprov.GetTemplate(_cartInfo.PurchaseInfo);
         }
     }
     return strRtn;
 }
예제 #5
0
        public void ValidateCart(Boolean removeZeroQtyItems = false)
        {
            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartBefore, PurchaseInfo);

            var    itemList            = GetCartItemList();
            Double subtotalcost        = 0;
            Double subtotaldealercost  = 0;
            Double totaldealerbonus    = 0;
            Double totaldiscount       = 0;
            Double totalsalediscount   = 0;
            Double totaldealerdiscount = 0;
            Double totalqty            = 0;
            Double totalweight         = 0;
            Double totalunitcost       = 0;

            // Calculate Promotions
            // Calculate first, so if we add items the price is calculated
            if (PromoInterface.Instance() != null)
            {
                PurchaseInfo = PromoInterface.Instance().CalculatePromotion(PortalId, PurchaseInfo);
                itemList     = GetCartItemList(); // get any new items
            }

            var strXml = "<items>";

            foreach (var info in itemList)
            {
                // check product still exists and remove if deleted, altered or disabled.

                var cartItem = ValidateCartItem(PortalId, UserId, info, removeZeroQtyItems);
                if (cartItem != null)
                {
                    strXml              += cartItem.XMLData;
                    totalunitcost       += info.GetXmlPropertyDouble("genxml/unitcost");
                    subtotalcost        += info.GetXmlPropertyDouble("genxml/totalcost");
                    subtotaldealercost  += info.GetXmlPropertyDouble("genxml/totaldealercost");
                    totaldealerbonus    += info.GetXmlPropertyDouble("genxml/totaldealerbonus");
                    totaldiscount       += info.GetXmlPropertyDouble("genxml/totaldiscount");
                    totalsalediscount   += info.GetXmlPropertyDouble("genxml/salediscount");
                    totaldealerdiscount += info.GetXmlPropertyDouble("genxml/totaldealerdiscount");
                    totalqty            += info.GetXmlPropertyDouble("genxml/qty");
                    totalweight         += info.GetXmlPropertyDouble("genxml/totalweight");
                }
            }
            strXml += "</items>";
            PurchaseInfo.RemoveXmlNode("genxml/items");
            PurchaseInfo.AddXmlNode(strXml, "items", "genxml");
            PopulateItemList(); // put changed items and prices back into base class for saving to DB

            // calculate totals

            var promototaldiscount = (totaldiscount - totalsalediscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totalqty", totalqty);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalunitcost", totalunitcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotalcost", subtotalcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotaldealercost", subtotaldealercost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotal", AppliedCost(PortalId, UserId, subtotalcost, subtotaldealercost));
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedsubtotal", AppliedCost(PortalId, UserId, (subtotalcost + totalsalediscount), (subtotaldealercost + totalsalediscount)));


            // calc any voucher amounts
            var    discountcode    = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
            Double voucherDiscount = 0;

            if (DiscountCodeInterface.Instance() != null)
            {
                PurchaseInfo    = DiscountCodeInterface.Instance().CalculateVoucherAmount(PortalId, UserId, PurchaseInfo, discountcode);
                voucherDiscount = PurchaseInfo.GetXmlPropertyDouble("genxml/voucherdiscount");
            }
            promototaldiscount  += voucherDiscount;
            totaldiscount       += voucherDiscount;
            totaldealerdiscount += voucherDiscount;

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldealerdiscount", totaldealerdiscount);
            var applieddiscount = AppliedCost(PortalId, UserId, totaldiscount, totaldealerdiscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/applieddiscount", applieddiscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", totaldealerbonus);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalsalediscount", totalsalediscount);


            //add shipping
            Double shippingcost       = 0;
            Double shippingdealercost = 0;
            var    shippingkey        = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
            var    currentcartstage   = PurchaseInfo.GetXmlProperty("genxml/currentcartstage");

            if (currentcartstage == "cartaddress" || currentcartstage == "cartsummary") // can only calc shipping on this stage.
            {
                ShippingInterface shipprov = null;
                if (shippingkey == "")
                {
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList   = pluginData.GetShippingProviders();
                    foreach (var d in provList)
                    {
                        var isValid   = true;
                        var shipprov1 = ShippingInterface.Instance(d.Key);
                        if (shipprov1 != null)
                        {
                            isValid = shipprov1.IsValid(PurchaseInfo);
                        }
                        if (isValid)
                        {
                            shipprov = shipprov1;
                            if (shipprov != null)
                            {
                                PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", shipprov.Shippingkey);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    shipprov = ShippingInterface.Instance(shippingkey);
                }

                if (shipprov != null && !shipprov.IsValid(PurchaseInfo)) // Check we have a valid one!! if not the get another!!
                {
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList   = pluginData.GetShippingProviders();
                    foreach (var d in provList)
                    {
                        var isValid   = true;
                        var shipprov1 = ShippingInterface.Instance(d.Key);
                        if (shipprov1 != null)
                        {
                            isValid = shipprov1.IsValid(PurchaseInfo);
                        }
                        if (isValid)
                        {
                            shipprov = shipprov1;
                            if (shipprov != null)
                            {
                                PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", shipprov.Shippingkey);
                            }
                            break;
                        }
                    }
                }


                if (shipprov != null)
                {
                    PurchaseInfo       = shipprov.CalculateShipping(PurchaseInfo);
                    shippingcost       = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingcost");
                    shippingdealercost = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingdealercost");
                }
                PurchaseInfo.SetXmlPropertyDouble("genxml/appliedshipping", AppliedCost(PortalId, UserId, shippingcost, shippingdealercost));
            }
            else
            {
                // clear the provider if not cartshipping stage
                PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", "");
            }


            //add tax
            Double appliedtax     = 0;
            var    taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/hidden/taxproviderkey");
            var    taxprov        = TaxInterface.Instance(taxproviderkey);

            if (taxprov != null)
            {
                PurchaseInfo = taxprov.Calculate(PurchaseInfo);
                appliedtax   = PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtax");
            }

            //cart full total
            var dealertotal = (subtotaldealercost + shippingdealercost + appliedtax) - promototaldiscount;

            if (dealertotal < 0)
            {
                dealertotal = 0;
            }
            var total = (subtotalcost + shippingcost + appliedtax) - promototaldiscount;

            if (total < 0)
            {
                total = 0;
            }
            PurchaseInfo.SetXmlPropertyDouble("genxml/dealertotal", dealertotal);
            PurchaseInfo.SetXmlPropertyDouble("genxml/total", total);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedtotal", AppliedCost(PortalId, UserId, total, dealertotal));

            if (PurchaseInfo.GetXmlProperty("genxml/clientmode") == "True")
            {
                // user not editor, so stop edit mode.
                if (!UserController.Instance.GetCurrentUserInfo().IsInRole("Administrators") && !UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.ManagerRole) && !UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.EditorRole))
                {
                    PurchaseInfo.SetXmlProperty("genxml/clientmode", "False");
                }
            }

            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartAfter, PurchaseInfo);

            SavePurchaseData();
        }
예제 #6
0
        private String GetShippingProviderTemplates(HttpContext context)
        {
            var ajaxInfo = GetAjaxInfo(context);
            var activeprovider = ajaxInfo.GetXmlProperty("genxml/hidden/shippingprovider");
            var currentcart = new CartData(PortalSettings.Current.PortalId);

            var shipoption = currentcart.GetShippingOption(); // we don't want to overwrite the selected shipping option.
            currentcart.AddExtraInfo(ajaxInfo);
            currentcart.SetShippingOption(shipoption);
            currentcart.PurchaseInfo.SetXmlProperty("genxml/currentcartstage", "cartsummary"); // (Legacy) we need to set this so the cart calcs shipping
            currentcart.Save();

            if (activeprovider == "") activeprovider = currentcart.PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");

            var strRtn = "";
            var pluginData = new PluginData(PortalSettings.Current.PortalId);
            var provList = pluginData.GetShippingProviders();
            if (provList != null && provList.Count > 0)
            {
                if (activeprovider == "") activeprovider = provList.First().Key;
                foreach (var d in provList)
                {
                    var p = d.Value;
                    var shippingkey = p.GetXmlProperty("genxml/textbox/ctrl");
                    var shipprov = ShippingInterface.Instance(shippingkey);
                    if (shipprov != null)
                    {
                        if (activeprovider == d.Key)
                        {
                            var razorTempl = shipprov.GetTemplate(currentcart.PurchaseInfo);
                            var objList = new List<NBrightInfo>();
                            objList.Add(currentcart.PurchaseInfo);
                            if (razorTempl.StartsWith("@"))
                            {
                                strRtn += NBrightBuyUtils.RazorRender(objList, razorTempl, shippingkey + "shippingtemplate", StoreSettings.Current.DebugMode);
                            }
                            else
                            {
                                strRtn += GenXmlFunctions.RenderRepeater(objList[0], razorTempl, "", "XMLData", "", StoreSettings.Current.Settings(), null);
                            }
                        }
                    }
                }
            }
            return strRtn;
        }