Exemplo n.º 1
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect(UIContextHelper.GetElementUrl(ModuleName.ECOMMERCE, "Edit.Configuration.ShippingOptionProperties", false, actionArgument.ToInteger(0)));
        }
        else if (actionName == "delete")
        {
            var shippingInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Nothing to delete
            if (shippingInfoObj == null)
            {
                return;
            }

            // Check permissions
            CheckConfigurationModification();

            // Check dependencies
            if (shippingInfoObj.Generalized.CheckDependencies())
            {
                // Show error message
                ShowError(ECommerceHelper.GetDependencyMessage(shippingInfoObj));

                return;
            }
            // Delete ShippingOptionInfo object from database
            ShippingOptionInfoProvider.DeleteShippingOptionInfo(shippingInfoObj);
        }
    }
    private void HandleAutomaticSelections(ShoppingCartInfo currentShoppingCart)
    {
        if ((currentShoppingCart.ShippingOption == null) && currentShoppingCart.IsShippingNeeded)
        {
            // Try to select shipping option if there is only one in system
            var query = ShippingOptionInfoProvider.GetShippingOptions(currentShoppingCart.ShoppingCartSiteID, true).Column("ShippingOptionID");
            if (query.Count == 1)
            {
                currentShoppingCart.ShoppingCartShippingOptionID = DataHelper.GetIntegerValues(query.Tables[0], "ShippingOptionID").FirstOrDefault();
            }
        }

        if (currentShoppingCart.PaymentOption == null)
        {
            // Try to select payment option if there is only one in system
            var query = PaymentOptionInfoProvider.GetPaymentOptions(currentShoppingCart.ShoppingCartSiteID, true).Column("PaymentOptionID");
            if (query.Count == 1)
            {
                int paymentOptionId = DataHelper.GetIntegerValues(query.Tables[0], "PaymentOptionID").FirstOrDefault();
                // Check if payment is allowed for shipping, or shipping is not set
                if (CheckPaymentIsAllowedForShipping(currentShoppingCart, paymentOptionId))
                {
                    currentShoppingCart.ShoppingCartPaymentOptionID = paymentOptionId;
                }
            }
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Ensures that only applicable shipping options are displayed in selector.
    /// </summary>
    /// <param name="ds">Dataset with shipping options.</param>
    protected override DataSet OnAfterRetrieveData(DataSet ds)
    {
        if (DataHelper.IsEmpty(ds) || (ShoppingCart == null))
        {
            return(ds);
        }

        foreach (DataRow shippingRow in ds.Tables[0].Select())
        {
            ShippingOptionInfo shippingOptionInfo;

            if (UseNameForSelection)
            {
                var shippingName = DataHelper.GetStringValue(shippingRow, "ShippingOptionName");
                shippingOptionInfo = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingName, ShoppingCart.SiteName);
            }
            else
            {
                var shippingID = DataHelper.GetIntValue(shippingRow, "ShippingOptionID");
                shippingOptionInfo = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingID);
            }

            // Do not remove already selected item even if the option is not applicable anymore
            // The user would see a different value in UI as is actually stored in the database
            var canBeRemoved = !EnsureSelectedItem || (ShoppingCart.ShoppingCartShippingOptionID != shippingOptionInfo.ShippingOptionID);
            if (canBeRemoved && !ShippingOptionInfoProvider.IsShippingOptionApplicable(ShoppingCart, shippingOptionInfo))
            {
                ds.Tables[0].Rows.Remove(shippingRow);
            }
        }

        return(ds);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        bool offerGlobalPaymentMethods = false;

        mShippingOptionId = QueryHelper.GetInteger("objectid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                int editedSiteId = mShippingOptionInfoObj.ShippingOptionSiteID;
                // Check object's site id
                CheckEditedObjectSiteID(editedSiteId);

                // Offer global payment methods when allowed
                offerGlobalPaymentMethods = ECommerceSettings.AllowGlobalPaymentMethods(editedSiteId);

                DataSet ds = PaymentOptionInfoProvider.GetPaymentOptionsForShipping(mShippingOptionId).OrderBy("PaymentOptionDisplayName");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "PaymentOptionID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.WhereCondition      = GetSelectorWhereCondition(offerGlobalPaymentMethods);
    }
Exemplo n.º 5
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect("ShippingOption_Edit_Frameset.aspx?shippingOptionID=" + Convert.ToString(actionArgument) + "&siteId=" + SelectSite.SiteID);
        }
        else if (actionName == "delete")
        {
            ShippingOptionInfo shippingInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Nothing to delete
            if (shippingInfoObj == null)
            {
                return;
            }

            // Check permissions
            CheckConfigurationModification(shippingInfoObj.ShippingOptionSiteID);

            // Check dependencies
            if (ShippingOptionInfoProvider.CheckDependencies(shippingInfoObj.ShippingOptionID))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("Ecommerce.DeleteDisabled");
                return;
            }
            // Delete ShippingOptionInfo object from database
            ShippingOptionInfoProvider.DeleteShippingOptionInfo(shippingInfoObj);
        }
    }
    /// <summary>
    /// Reloads the form data.
    /// </summary>
    protected void ReloadData()
    {
        rptCart.DataSource = ShoppingCart.ContentTable;

        // Hide coupon placeholder when no coupons are defined
        // ***  plcCoupon.Visible = AreDiscountCouponsAvailableOnSite();

        // Bind data
        rptCart.DataBind();
        ReloadBillingAdresses();
        ReloadShippingAdresses();

        if (!DataHelper.DataSourceIsEmpty(ShoppingCart.ContentTable))
        {
            // Display total price
            DisplayTotalPrice();

            // Display/hide discount column
            //gridData.Columns[9].Visible = ShoppingCart.IsDiscountApplied;
        }
        else
        {
            // Hide some items
            // ***  HideCartContentWhenEmpty();
        }

        if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart))
        {
            // ***  plcShippingPrice.Visible = false;
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Reloads the form data.
    /// </summary>
    protected void ReloadData()
    {
        //gridData.DataSource = ShoppingCartInfoObj.ShoppingCartContentTable;
        gridData.DataSource = ShoppingCartInfoObj.ContentTable;

        // Hide coupon placeholder when no coupons are defined
        plcCoupon.Visible = AreDiscountCouponsAvailableOnSite();

        // Bind data
        gridData.DataBind();

        if (!DataHelper.DataSourceIsEmpty(ShoppingCartInfoObj.ContentTable))
        {
            // Display total price
            DisplayTotalPrice();

            // Display/hide discount column
            gridData.Columns[8].Visible = this.ShoppingCartInfoObj.IsDiscountApplied;
        }
        else
        {
            // Hide some items
            HideCartContentWhenEmpty();
        }

        if (!ShippingOptionInfoProvider.IsShippingNeeded(this.ShoppingCartInfoObj))
        {
            this.plcShippingPrice.Visible = false;
        }
    }
    /// <summary>
    /// Validates shopping cart content.
    /// </summary>
    public override bool IsValid()
    {
        // Force loading current values
        ShoppingCart.Evaluate();

        // Check inventory
        var checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart);

        // Check if selected shipping option is applicable
        if (!ShippingOptionInfoProvider.IsShippingOptionApplicable(ShoppingCart, ShoppingCart.ShippingOption))
        {
            checkResult.ShippingOptionNotAvailable = true;
        }

        if (checkResult.CheckFailed)
        {
            lblError.Text = checkResult.GetHTMLFormattedMessage();

            return(false);
        }

        // Check if cart contains at least one product
        if (ShoppingCart.IsEmpty)
        {
            lblError.Text = GetString("com.checkout.cartisempty");

            return(false);
        }

        return(true);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            var editElementName = IsMultiStoreConfiguration ? "Edit.Ecommerce.GlobalShippingOptions.Properties" : "Edit.Configuration.ShippingOptionProperties";
            URLHelper.Redirect(UIContextHelper.GetElementUrl("CMS.Ecommerce", editElementName, false, actionArgument.ToInteger(0)));
        }
        else if (actionName == "delete")
        {
            var shippingInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Nothing to delete
            if (shippingInfoObj == null)
            {
                return;
            }

            // Check permissions
            CheckConfigurationModification(shippingInfoObj.ShippingOptionSiteID);

            // Check dependencies
            if (shippingInfoObj.Generalized.CheckDependencies())
            {
                // Show error message
                ShowError(GetString("Ecommerce.DeleteDisabled"));

                return;
            }
            // Delete ShippingOptionInfo object from database
            ShippingOptionInfoProvider.DeleteShippingOptionInfo(shippingInfoObj);
        }
    }
        //EndDocSection:CouponCodeRemove


        //DocSection:DisplayDelivery
        /// <summary>
        /// Displays the customer details checkout process step.
        /// </summary>
        public ActionResult DeliveryDetails()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, displays the shopping cart
            if (cart.IsEmpty)
            {
                return(RedirectToAction(nameof(CheckoutController.ShoppingCart)));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Creates a collection of shipping options enabled for the current site
            SelectList shippingOptions = CreateShippingOptionList(cart);

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), countries, null),
                ShippingOption = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions)
            };

            // Displays the customer details step
            return(View(model));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        mShippingOptionId = QueryHelper.GetInteger("objectid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                // Check object's site id
                CheckEditedObjectSiteID(mShippingOptionInfoObj.ShippingOptionSiteID);

                DataSet ds = ShippingOptionTaxClassInfoProvider.GetShippingOptionTaxClasses(mShippingOptionId);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "TaxClassID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.OrderBy             = "TaxClassDisplayName";
        uniSelector.WhereCondition      = GetSelectorWhereCondition();
    }
        // Prepares a shipping option select list together with calculated shipping prices
        private SelectList CreateShippingOptionList(ShoppingCartInfo cart)
        {
            // Gets the shipping options configured and enabled for the current site
            IEnumerable <ShippingOptionInfo> shippingOptions = ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true);

            // Creates a collection of SelectListItems
            IEnumerable <SelectListItem> selectList = shippingOptions.Select(shippingOption =>
            {
                // Calculates the shipping price for a given shipping option based on the contents of the current
                // shopping cart and currently running store promotions (e.g., free shipping offers)
                decimal shippingPrice = shoppingService.CalculateShippingOptionPrice(shippingOption);

                // Gets the currency information from the shopping cart
                CurrencyInfo currency = cart.Currency;

                // Creates a select list item with shipping option name and a calculate shipping price
                return(new SelectListItem
                {
                    Value = shippingOption.ShippingOptionID.ToString(),
                    Text = $"{shippingOption.ShippingOptionDisplayName} ({String.Format(currency.CurrencyFormatString, shippingPrice)})"
                });
            });

            // Returns a new SelectList instance
            return(new SelectList(selectList, "Value", "Text"));
        }
Exemplo n.º 13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        mShippingOptionId = QueryHelper.GetInteger("shippingoptionid", 0);

        mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
        EditedObject           = mShippingOptionInfoObj;

        if (mShippingOptionInfoObj != null)
        {
            CheckEditedObjectSiteID(mShippingOptionInfoObj.ShippingOptionSiteID);
            currency = CurrencyInfoProvider.GetMainCurrency(mShippingOptionInfoObj.ShippingOptionSiteID);
        }

        // Init unigrid
        gridElem.OnAction             += new OnActionEventHandler(gridElem_OnAction);
        gridElem.OnExternalDataBound  += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound);
        gridElem.OnAfterRetrieveData  += new OnAfterRetrieveData(gridElem_OnAfterRetrieveData);
        gridElem.WhereCondition        = "ShippingCostShippingOptionID = " + mShippingOptionId;
        gridElem.ZeroRowsText          = GetString("com.ui.shippingcost.edit_nodata");
        gridElem.GridView.AllowSorting = false;

        // Prepare the new shipping cost header action
        CurrentMaster.HeaderActions.AddAction(new HeaderAction()
        {
            Text        = GetString("com.ui.shippingcost.edit_new"),
            RedirectUrl = ResolveUrl("ShippingOption_Edit_ShippingCosts_Edit.aspx?shippingCostShippingOptionId=" + mShippingOptionId + "&siteId=" + SiteID),
            ImageUrl    = GetImageUrl("Objects/Ecommerce_ShippingOption/add.png"),
            ControlType = HeaderActionTypeEnum.Hyperlink
        });
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        mShippingOptionId = QueryHelper.GetInteger("shippingOptionID", 0);

        string             shippingOptionName = "";
        ShippingOptionInfo soi = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);

        if (soi != null)
        {
            editedSiteId = soi.ShippingOptionSiteID;

            // Check site ID
            CheckEditedObjectSiteID(editedSiteId);
            shippingOptionName = ResHelper.LocalizeString(soi.ShippingOptionDisplayName);
        }

        // Initializes page title and breadcrumbs
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("ShippingOption_EditHeader.ItemListLink");
        breadcrumbs[0, 1]     = "~/CMSModules/Ecommerce/Pages/Tools/Configuration/ShippingOptions/ShippingOption_List.aspx?siteId=" + SiteID;
        breadcrumbs[0, 2]     = "configEdit";
        breadcrumbs[1, 0]     = FormatBreadcrumbObjectName(shippingOptionName, editedSiteId);
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";

        CMSMasterPage master = (CMSMasterPage)CurrentMaster;

        master.Title.Breadcrumbs  = breadcrumbs;
        master.Tabs.OnTabCreated += Tabs_OnTabCreated;
    }
Exemplo n.º 15
0
    /// <summary>
    /// Adds price to individual shipping options when shopping cart object supplied.
    /// </summary>
    /// <param name="item">Shipping option item to add price to.</param>
    protected override void OnListItemCreated(ListItem item)
    {
        // Adding price to shipping option is not required
        if (!DisplayShippingOptionPrice)
        {
            return;
        }

        if ((item != null) && (ShoppingCart != null))
        {
            // Calculate hypothetical shipping cost for shipping option from supplied list item
            var optionID = ValidationHelper.GetInteger(item.Value, 0);
            var option   = ShippingOptionInfoProvider.GetShippingOptionInfo(optionID);

            var shippingPrice  = CalculateShipping(option);
            var formattedPrice = CurrencyInfoProvider.GetFormattedPrice(shippingPrice, ShoppingCart.Currency, false);

            if (shippingPrice > 0)
            {
                var detailInfo = $"({formattedPrice})";
                var rtl        = IsLiveSite ? CultureHelper.IsPreferredCultureRTL() : CultureHelper.IsUICultureRTL();

                if (rtl)
                {
                    item.Text = $"{detailInfo} {item.Text}";
                }
                else
                {
                    item.Text += $" {detailInfo}";
                }
            }
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Setups the control.
    /// </summary>
    public void SetupControl()
    {
        string type = ValidationHelper.GetString(GetValue("TotalToDisplay"), "TotalPriceOfProducts");

        // Display the correct value according to the TotalToDisplay property of the web part
        switch (type)
        {
        case "TotalPriceOfOrder":
        {
            var value = ShoppingCart.GrandTotal;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalPriceOfProducts":
        {
            var value = ShoppingCart.TotalItemsPrice;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalShipping":
        {
            var value = (ShoppingCart.ShippingOption != null) ? ShoppingCart.TotalShipping : 0;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalWeight":
        {
            var value        = ShoppingCart.TotalItemsWeight;
            var stringFormat = GetStringFormat();
            DisplayValue(stringFormat == "" ? ShippingOptionInfoProvider.GetFormattedWeight(value, CurrentSiteName) : String.Format(stringFormat, value));
            break;
        }

        case "TotalOrderTax":
        {
            var value = ShoppingCart.TotalTax;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "TotalOrderDiscount":
        {
            var value = ShoppingCart.OrderDiscount;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }

        case "OtherPaymentsTotal":
        {
            var value = ShoppingCart.OtherPayments;
            DisplayValue(GetFormattedPriceToDisplay(value));
            break;
        }
        }
    }
Exemplo n.º 17
0
        public DeliveryOption GetShippingOption(int id)
        {
            var service = ShippingOptionInfoProvider.GetShippingOptionInfo(id);
            var result  = mapper.Map <DeliveryOption>(service);
            var carrier = CarrierInfoProvider.GetCarrierInfo(service.ShippingOptionCarrierID);

            result.CarrierCode = carrier.CarrierName;
            return(result);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Required field validator error messages initialization
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvName.ErrorMessage        = GetString("COM_ShippingOption_Edit.NameError");
        txtShippingOptionCharge.EmptyErrorMessage      = GetString("COM_ShippingOption_Edit.ChargeError");
        txtShippingOptionCharge.ValidationErrorMessage = GetString("COM_ShippingOption_Edit.ChargePositive");

        // Control initializations
        lblShippingOptionCharge.Text = GetString("COM_ShippingOption_Edit.ShippingOptionChargeLabel");

        // Get shippingOption id from querystring
        mShippingOptionID = QueryHelper.GetInteger("shippingOptionID", 0);
        mEditedSiteId     = ConfiguredSiteID;
        // Edit shipping option
        if (mShippingOptionID > 0)
        {
            ShippingOptionInfo shippingOptionObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionID);
            EditedObject = shippingOptionObj;

            if (shippingOptionObj != null)
            {
                mEditedSiteId = shippingOptionObj.ShippingOptionSiteID;
                CheckEditedObjectSiteID(mEditedSiteId);

                // Init file uploader
                file.ObjectID   = mShippingOptionID;
                file.ObjectType = ECommerceObjectType.SHIPPINGOPTION;
                file.Category   = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL;
                file.SiteID     = mEditedSiteId;

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(shippingOptionObj);
                    // Show that the shippingOption was created or updated successfully
                    if (QueryHelper.GetString("saved", "") == "1")
                    {
                        // Show message
                        ShowChangesSaved();
                    }
                }
            }
        }

        // Ensure currency code after price value
        txtShippingOptionCharge.CurrencySiteID = mEditedSiteId;

        // Check presence of main currency
        string currencyWarning = CheckMainCurrency(mEditedSiteId);

        if (!string.IsNullOrEmpty(currencyWarning))
        {
            ShowWarning(currencyWarning, null, null);
        }
    }
        public ActionResult DeliveryDetails(DeliveryDetailsViewModel model)
        {
            // Gets the user's current shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true).ToList(),
                                                        "ShippingOptionID",
                                                        "ShippingOptionDisplayName");

            // If the ModelState is not valid, assembles the country list and the shipping option list and displays the step again
            if (!ModelState.IsValid)
            {
                model.BillingAddress.Countries       = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");
                model.ShippingOption.ShippingOptions = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions).ShippingOptions;
                return(View(model));
            }

            // Gets the shopping cart's customer and applies the customer details from the checkout process step
            var customer = shoppingService.GetCurrentCustomer();

            if (customer == null)
            {
                UserInfo userInfo = cart.User;
                if (userInfo != null)
                {
                    customer = CustomerHelper.MapToCustomer(cart.User);
                }
                else
                {
                    customer = new CustomerInfo();
                }
            }
            model.Customer.ApplyToCustomer(customer);

            // Sets the updated customer object to the current shopping cart
            shoppingService.SetCustomer(customer);

            // Gets the shopping cart's billing address and applies the billing address from the checkout process step
            var address = AddressInfoProvider.GetAddressInfo(model.BillingAddress.AddressID) ?? new AddressInfo();

            model.BillingAddress.ApplyTo(address);

            // Sets the address personal name
            address.AddressPersonalName = $"{customer.CustomerFirstName} {customer.CustomerLastName}";

            // Saves the billing address
            shoppingService.SetBillingAddress(address);

            // Sets the selected shipping option and evaluates the cart
            shoppingService.SetShippingOption(model.ShippingOption.ShippingOptionID);

            // Redirects to the next step of the checkout process
            return(RedirectToAction("PreviewAndPay"));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for CMS Desk -> Ecommerce
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "Configuration.ShippingOptions.PaymentMethods"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "Configuration.ShippingOptions.PaymentMethods");
        }

        bool offerGlobalPaymentMethods = false;

        lblAvialable.Text = GetString("com.shippingoption.payments");
        mShippingOptionId = QueryHelper.GetInteger("shippingoptionid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                int editedSiteId = mShippingOptionInfoObj.ShippingOptionSiteID;
                // Check object's site id
                CheckEditedObjectSiteID(editedSiteId);

                // Offer global payment methods when allowed or configuring global shipping option
                if (editedSiteId != 0)
                {
                    SiteInfo si = SiteInfoProvider.GetSiteInfo(editedSiteId);
                    if (si != null)
                    {
                        offerGlobalPaymentMethods = ECommerceSettings.AllowGlobalPaymentMethods(si.SiteName);
                    }
                }
                // Configuring global shipping option
                else
                {
                    offerGlobalPaymentMethods = true;
                }

                DataSet ds = PaymentOptionInfoProvider.GetPaymentOptionsForShipping(mShippingOptionId, false);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "PaymentOptionID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.IconPath            = GetObjectIconUrl("ecommerce.paymentoption", "object.png");
        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.WhereCondition      = GetSelectorWhereCondition(offerGlobalPaymentMethods);
    }
Exemplo n.º 21
0
        /// <summary>
        /// Returns a shipping option with the specified identifier.
        /// </summary>
        /// <param name="shippingOptionId">Shipping option's identifier.</param>
        /// <returns><see cref="ShippingOptionInfo"/> object representing a shipping option with the specified identifier. Returns <c>null</c> if not found.</returns>
        public ShippingOptionInfo GetById(int shippingOptionId)
        {
            var shippingInfo = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingOptionId);

            if (shippingInfo == null || shippingInfo.ShippingOptionSiteID != SiteID)
            {
                return(null);
            }

            return(shippingInfo);
        }
 /// <summary>
 /// Checks shipping methods.
 /// </summary>
 private void CheckShippingMethods()
 {
     if (ShippingMethodsCheck)
     {
         // Check if at least one shipping option exists
         DataSet ds = ShippingOptionInfoProvider.GetShippingOptions("ShippingOptionEnabled = 1", "ShippingOptionID", 1, "ShippingOptionID", CMSContext.CurrentSiteID);
         if (DataHelper.DataSourceIsEmpty(ds))
         {
             DisplayMessage("com.settingschecker.noshippingmethods");
         }
     }
 }
Exemplo n.º 23
0
        public DeliveryOption[] GetShippingOptions()
        {
            var services = ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID).Where(s => s.ShippingOptionEnabled).ToArray();
            var result   = mapper.Map <DeliveryOption[]>(services);

            foreach (var item in result)
            {
                item.Title = resources.ResolveMacroString(item.Title);
            }

            GetShippingPrice(result);
            return(result);
        }
Exemplo n.º 24
0
        public void ShoppingCart_ShippingIsSet()
        {
            var cart = CreateEmptyShoppingCart();

            cart.AddItem(Factory.SKUAvailable.SKUID);

            cart.ShippingOption = Factory.ShippingOptionDefault;

            var expectedShipping = ShippingOptionInfoProvider.CalculateShipping(cart.OriginalCart);

            CMSAssert.All(
                () => Assert.That(Factory.ShippingOptionDefault.ShippingOptionID == cart.ShippingOption.ShippingOptionID, "Shipping option is not set", null),
                () => Assert.AreEqual(expectedShipping, cart.Shipping, "Shipping value does not match", null)
                );
        }
Exemplo n.º 25
0
    /// <summary>
    /// Checks shipping methods.
    /// </summary>
    private void CheckShippingMethods()
    {
        if (ShippingMethodsCheck)
        {
            // Check if at least one shipping option exists
            DataSet ds = ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true)
                         .TopN(1)
                         .Column("ShippingOptionID")
                         .OrderBy("ShippingOptionID");

            if (DataHelper.DataSourceIsEmpty(ds))
            {
                DisplayMessage("com.settingschecker.noshippingmethods");
            }
        }
    }
    /// <summary>
    /// Reloads the form data.
    /// </summary>
    protected void ReloadData()
    {
        //gridData.DataSource = ShoppingCartInfoObj.ShoppingCartContentTable;
        gridData.DataSource = ShoppingCart.ContentTable;

        // Bind data
        gridData.DataBind();

        if (!DataHelper.DataSourceIsEmpty(ShoppingCart.ContentTable))
        {
            // Display total price
            DisplayTotalPrice();

            // Display/hide discount column
            gridData.Columns[9].Visible = ShoppingCart.IsItemDiscountApplied;
        }
        else
        {
            // Hide some items
            HideCartContent();
        }

        // Show order related discounts
        plcMultiBuyDiscountArea.Visible = ShoppingCart.OrderRelatedDiscountSummaryItems.Count > 0;
        ShoppingCart.OrderRelatedDiscountSummaryItems.ForEach(d =>
        {
            plcOrderRelatedDiscountNames.Controls.Add(new LocalizedLabel {
                Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(d.Name)) + ":", EnableViewState = false
            });
            plcOrderRelatedDiscountNames.Controls.Add(new Literal {
                Text = "<br />", EnableViewState = false
            });
            plcOrderRelatedDiscountValues.Controls.Add(new Label {
                Text = "- " + CurrencyInfoProvider.GetFormattedPrice(d.Value, ShoppingCart.Currency), EnableViewState = false
            });
            plcOrderRelatedDiscountValues.Controls.Add(new Literal {
                Text = "<br />", EnableViewState = false
            });
        });

        //lblMultiBuyDiscountName.Text
        if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart))
        {
            plcShippingPrice.Visible = false;
        }
    }
        //EndDocSection:DisplayDelivery


        //DocSection:DisplayDeliveryAddressSelector
        /// <summary>
        /// Displays the customer details checkout process step with an address selector for known customers.
        /// </summary>
        public ActionResult DeliveryDetailsAddressSelector()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, redirects to the shopping cart view
            if (cart.IsEmpty)
            {
                return(RedirectToAction("ShoppingCart"));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Gets the current customer
            CustomerInfo customer = shoppingService.GetCurrentCustomer();

            // Gets all customer billing addresses for the address selector
            IEnumerable <AddressInfo> customerAddresses = Enumerable.Empty <AddressInfo>();

            if (customer != null)
            {
                customerAddresses = AddressInfoProvider.GetAddresses(customer.CustomerID).ToList();
            }

            // Prepares address selector options
            SelectList addresses = new SelectList(customerAddresses, "AddressID", "AddressName");

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true).ToList(), "ShippingOptionID", "ShippingOptionDisplayName");

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), countries, addresses),
                ShippingOption = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions)
            };


            // Displays the customer details step
            return(View(model));
        }
 /// <summary>
 /// This will bind Shipping options to dropdown
 /// </summary>
 private void BindShippingOptions()
 {
     try
     {
         if (ShippingOptions == null)
         {
             ShippingOptions = ShippingOptionInfoProvider.GetShippingOptions()
                                         .OnSite(CurrentSite.SiteID).Where(x => x.ShippingOptionEnabled == true).ToList();
         }
         ddlShippingOption.DataSource = ShippingOptions;
         ddlShippingOption.DataValueField = "ShippingOptionID";
         ddlShippingOption.DataTextField = "ShippingOptionName";
         ddlShippingOption.DataBind();
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_DistributorCartDetails", "BindShippingOptions", ex.Message);
     }
 }
        /// <summary>
        /// Prepares a view model of the preview checkout process step including the shopping cart,
        /// the customer details, and the payment method.
        /// </summary>
        /// <returns>View model with information about the future order.</returns>
        private PreviewAndPayViewModel PreparePreviewViewModel()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // Prepares the customer details
            DeliveryDetailsViewModel deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), null, null),
                ShippingOption = new ShippingOptionViewModel()
                {
                    ShippingOptionID          = cart.ShippingOption.ShippingOptionID,
                    ShippingOptionDisplayName = ShippingOptionInfoProvider.GetShippingOptionInfo(cart.ShippingOption.ShippingOptionID).ShippingOptionDisplayName
                }
            };

            // Prepares the payment method
            PaymentMethodViewModel paymentViewModel = new PaymentMethodViewModel
            {
                PaymentMethods = new SelectList(GetApplicablePaymentMethods(cart), "PaymentOptionID", "PaymentOptionDisplayName")
            };

            // Gets the selected payment method
            PaymentOptionInfo paymentMethod = cart.PaymentOption;

            if (paymentMethod != null)
            {
                paymentViewModel.PaymentMethodID = paymentMethod.PaymentOptionID;
            }

            // Prepares a model from the preview step
            PreviewAndPayViewModel model = new PreviewAndPayViewModel
            {
                DeliveryDetails = deliveryDetailsModel,
                Cart            = new ShoppingCartViewModel(cart),
                PaymentMethod   = paymentViewModel
            };

            return(model);
        }
Exemplo n.º 30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsMultiStoreConfiguration)
        {
            CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, "Ecommerce.GlobalShippingOptions.TaxClasses");
        }
        else
        {
            CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, "Configuration.ShippingOptions.TaxClasses");
        }

        mShippingOptionId = QueryHelper.GetInteger("objectid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                // Check object's site id
                CheckEditedObjectSiteID(mShippingOptionInfoObj.ShippingOptionSiteID);

                DataSet ds = ShippingOptionTaxClassInfoProvider.GetShippingOptionTaxClasses(mShippingOptionId);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "TaxClassID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.OrderBy             = "TaxClassDisplayName";
        uniSelector.WhereCondition      = GetSelectorWhereCondition();
    }