Example #1
0
        private static void RecalculateSummary(HttpContext context)
        {
            var objCtrl = new NBrightBuyController();

            var currentcart = new CartData(PortalSettings.Current.PortalId);
            var ajaxInfo    = NBrightBuyUtils.GetAjaxInfo(context, true);
            var shipoption  = currentcart.GetShippingOption(); // ship option already set in address update.

            currentcart.AddExtraInfo(ajaxInfo);
            currentcart.SetShippingOption(shipoption);
            currentcart.PurchaseInfo.SetXmlProperty("genxml/currentcartstage", "cartsummary"); // (Legacy) we need to set this so the cart calcs shipping
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider"));

            var shipref     = ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider");
            var displayanme = "";
            var shipInfo    = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", shipref);

            if (shipInfo != null)
            {
                var shipprov = ShippingInterface.Instance(shipref);
                if (shipprov != null)
                {
                    displayanme = shipprov.Name();
                }
            }
            if (displayanme == "")
            {
                displayanme = shipref;
            }
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/hidden/shippingdisplayanme", displayanme);

            currentcart.Lang = ajaxInfo.Lang;  // set lang so we can send emails in same language the order was made in.

            currentcart.Save(StoreSettings.Current.DebugMode, true);
        }
Example #2
0
 public ShoppingCart()
 {
     products      = new LinkedList <UserCart>();
     usedCoupons   = new LinkedList <string>();
     paymentProxy  = new PaymentProxy();
     shippingProxy = new ShippingProxy();
 }
Example #3
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);
        }
Example #4
0
        private static string GetShippingProviderTemplates(HttpContext context)
        {
            var ajaxInfo       = NBrightBuyUtils.GetAjaxInfo(context);
            var activeprovider = ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/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.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)
                {
                    if (activeprovider == d.Key)
                    {
                        var p           = d.Value;
                        var shippingkey = p.GetXmlProperty("genxml/textbox/ctrl");
                        var shipprov    = ShippingInterface.Instance(shippingkey);
                        if (shipprov != null)
                        {
                            var razorTempl = shipprov.GetTemplate(currentcart.PurchaseInfo);
                            if (razorTempl != "")
                            {
                                var objList = new List <NBrightInfo>();
                                objList.Add(currentcart.PurchaseInfo);

                                var nbRazor = new NBrightRazor(objList.Cast <object>().ToList(), NBrightBuyUtils.GetPassSettings(ajaxInfo), HttpContext.Current.Request.QueryString);
                                nbRazor.ModuleId         = -1;
                                nbRazor.FullTemplateName = "";
                                nbRazor.TemplateName     = "";
                                nbRazor.ThemeFolder      = "";
                                nbRazor.Lang             = Utils.GetCurrentCulture();

                                strRtn += NBrightBuyUtils.RazorRender(nbRazor, razorTempl, shippingkey + "shippingtemplate", true);
                            }
                        }
                    }
                }
            }
            return(strRtn);
        }
        public void init()
        {
            WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB();
            cDB.emptyDB();
            configuration.DB_MODE = "Testing";
            ProductManager.restartInstance();
            SalesManager.restartInstance();
            StoreManagement.restartInstance();
            UserManager.restartInstance();
            UserCartsManager.restartInstance();
            BuyHistoryManager.restartInstance();
            CouponsManager.restartInstance();
            DiscountsManager.restartInstance();
            RaffleSalesManager.restartInstance();
            StorePremissionsArchive.restartInstance();

            shippingProxy = new ShippingProxy();

            us    = userServices.getInstance();
            ss    = storeServices.getInstance();
            sellS = sellServices.getInstance();

            admin = us.startSession();
            us.register(admin, "admin", "123456");
            us.login(admin, "admin", "123456");

            admin1 = us.startSession();
            us.register(admin1, "admin1", "123456");

            zahi = us.startSession();
            us.register(zahi, "zahi", "123456");

            itamar = us.startSession();
            us.register(itamar, "itamar", "123456");
            us.login(itamar, "itamar", "123456");
            int storeId = ss.createStore("Maria&Netta Inc.", itamar);

            store = StoreManagement.getInstance().getStore(storeId);

            niv = us.startSession();
            us.register(niv, "niv", "123456");
            us.login(niv, "niv", "123456");

            ss.addStoreManager(storeId, "niv", itamar);

            int colaId = ss.addProductInStore("cola", 3.2, 10, itamar, storeId, "Drinks");

            cola = ProductManager.getInstance().getProductInStore(colaId);
            int spriteId = ss.addProductInStore("sprite", 5.2, 100, itamar, storeId, "Drinks");

            sprite = ProductManager.getInstance().getProductInStore(spriteId);
            ss.addSaleToStore(itamar, storeId, cola.getProductInStoreId(), 1, 10, DateTime.Now.AddMonths(10).ToString());
        }
Example #6
0
        private void DisplayOrderData(int portalId, UserInfo userInfo, String entryId)
        {
            var strOut = "***ERROR***  Invalid Data";

            if (Utils.IsNumeric(entryId) && entryId != "0")
            {
                var orderData = new OrderData(portalId, Convert.ToInt32(entryId));
                if (orderData.PurchaseInfo.TypeCode == "ORDER")
                {
                    strOut = "***ERROR***  Invalid Security";
                    if (_scode == orderData.PurchaseInfo.GetXmlProperty("genxml/securitycode") || userInfo.UserID == orderData.UserId || userInfo.IsInRole(StoreSettings.ManagerRole) || userInfo.IsInRole(StoreSettings.EditorRole))
                    {
                        var doProv = false;
                        //check the payment provider for a print url
                        var shippingprovider = orderData.PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
                        if (shippingprovider != "")
                        {
                            var shipprov = ShippingInterface.Instance(shippingprovider);
                            if (shipprov != null)
                            {
                                if (_printtype == "shiplabel")
                                {
                                    var printurl = shipprov.GetDeliveryLabelUrl(orderData.PurchaseInfo);
                                    if (printurl != "")
                                    {
                                        doProv = true;
                                        Response.Redirect(printurl);
                                    }
                                }
                            }
                        }
                        if (!doProv)
                        {
                            var printtemplate = "printorder.cshtml";
                            var obj           = new NBrightInfo(true);
                            obj.PortalId = PortalSettings.Current.PortalId;
                            obj.ModuleId = 0;
                            obj.Lang     = Utils.GetCurrentCulture();
                            obj.GUIDKey  = _printtype;
                            obj.ItemID   = -1;

                            strOut = NBrightBuyUtils.RazorTemplRender(printtemplate, 0, "", obj, "/DesktopModules/NBright/NBrightBuy", _theme, Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
                        }
                    }
                }
            }
            var l = new Literal();

            l.Text = strOut;
            phData.Controls.Add(l);
        }
Example #7
0
        private void DisplayOrderData(int portalId, UserInfo userInfo, String entryId)
        {
            var strOut = "***ERROR***  Invalid Data";

            if (Utils.IsNumeric(entryId) && entryId != "0")
            {
                var orderData = new OrderData(portalId, Convert.ToInt32(entryId));
                if (orderData.PurchaseInfo.TypeCode == "ORDER")
                {
                    strOut = "***ERROR***  Invalid Security";
                    if (userInfo.UserID == orderData.UserId || userInfo.IsInRole(StoreSettings.ManagerRole) || userInfo.IsInRole(StoreSettings.EditorRole))
                    {
                        //check the payment provider for a print url
                        var shippingprovider = orderData.PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
                        if (shippingprovider != "")
                        {
                            var shipprov = ShippingInterface.Instance(shippingprovider);
                            if (shipprov != null)
                            {
                                if (_template == "printdeliverylabel.html")
                                {
                                    var printurl = shipprov.GetDeliveryLabelUrl(orderData.PurchaseInfo);
                                    if (printurl != "")
                                    {
                                        Response.Redirect(printurl);
                                    }
                                }
                            }
                        }

                        // not provider label, so print template
                        var templCtrl = NBrightBuyUtils.GetTemplateGetter(_theme);
                        var strTempl  = templCtrl.GetTemplateData(_template, Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());

                        strOut = GenXmlFunctions.RenderRepeater(orderData.PurchaseInfo, strTempl, "", "XMLData", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
                        if (_template.EndsWith(".xsl"))
                        {
                            strOut = XslUtils.XslTransInMemory(orderData.PurchaseInfo.XMLData, strOut);
                        }
                    }
                }
            }
            var l = new Literal();

            l.Text = strOut;
            phData.Controls.Add(l);
        }
        public IEncodedString ShippingProviderList(NBrightInfo info, String attributes = "")
        {
            var xpath = "genxml/extrainfo/genxml/radiobuttonlist/shippingprovider";

            var strOut = "";
            var upd    = getUpdateAttr(xpath, attributes);
            var id     = getIdFromXpath(xpath);

            strOut = "<div " + attributes + ">";
            var c     = 0;
            var s     = "";
            var value = info.GetXmlProperty(xpath);

            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)
                {
                    if (value == "")
                    {
                        value = d.Key;
                    }
                    s = "";
                    if (value == d.Key)
                    {
                        s = "checked";
                    }
                    strOut += "    <input id='" + id + "_" + c.ToString("") + "' " + upd + " name='" + id + "radio' type='radio' value='" + d.Key + "'  " + s + "/><label>" + p.GetXmlProperty("genxml/textbox/name") + "</label>";
                    c      += 1;
                }
            }
            strOut += "</div>";
            return(new RawString(strOut));
        }
Example #9
0
        public void ValidateCart(Boolean removeZeroQtyItems = false)
        {
            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartBefore, PurchaseInfo);

            var    itemList          = GetCartItemList();
            Double subtotalcost      = 0;
            Double totaldealerbonus  = 0;
            Double totaldiscount     = 0;
            Double totalsalediscount = 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)
            {
                var promol = PromoInterface.ProviderList;
                foreach (var p in promol)
                {
                    PurchaseInfo = PromoInterface.Instance(p.Key).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");
                    totaldealerbonus  += info.GetXmlPropertyDouble("genxml/totaldealerbonus");
                    totaldiscount     += info.GetXmlPropertyDouble("genxml/totaldiscount");
                    totalsalediscount += info.GetXmlPropertyDouble("genxml/salediscount");
                    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/subtotal", subtotalcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedsubtotal", (subtotalcost + 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;

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

            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;
                shipprov = ShippingInterface.Instance(shippingkey);
                if (shipprov != null)
                {
                    PurchaseInfo       = shipprov.CalculateShipping(PurchaseInfo);
                    shippingcost       = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingcost");
                    shippingdealercost = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingdealercost");
                }
                PurchaseInfo.SetXmlPropertyDouble("genxml/appliedshipping", AppliedCost(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 total = (subtotalcost + shippingcost + appliedtax) - promototaldiscount;

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

            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();
        }
Example #10
0
 public ShippingProxy()
 {
     impl = ShippingSystem.getInstance();
 }