public void RemoveCartItem(int id)
        {
            // Method approach inspired by \CMS\CMSModules\Ecommerce\Controls\Checkout\CartItemRemove.ascx.cs

            var cart = ECommerceContext.CurrentShoppingCart;
            var item = cart.CartItems.FirstOrDefault(i => i.CartItemID == id);

            if (item == null)
            {
                return;
            }

            // Delete all the children from the database if available
            foreach (ShoppingCartItemInfo scii in cart.CartItems)
            {
                if ((scii.CartItemBundleGUID == item.CartItemGUID) || (scii.CartItemParentGUID == item.CartItemGUID))
                {
                    ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii);
                }
            }

            // Deletes the CartItem from the database
            ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(item.CartItemGUID);
            // Delete the CartItem form the shopping cart object (session)
            ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, item.CartItemGUID);

            // Recalculate shopping cart
            ShoppingCartInfoProvider.EvaluateShoppingCart(cart);
        }
Esempio n. 2
0
    /// <summary>
    /// Validates shopping cart content.
    /// </summary>
    public override bool IsValid()
    {
        var cart = ShoppingCart;

        // Force loading current values
        ShoppingCartInfoProvider.EvaluateShoppingCart(cart);

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

        // Check if selected shipping option is applicable
        if (!ShippingOptionInfoProvider.IsShippingOptionApplicable(cart, cart.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>
    /// Validates shopping cart content.
    /// </summary>
    public override bool IsValid()
    {
        // Force loading current values
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

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

        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>
 /// Removes the current cart item and the associated product options from the shopping cart.
 /// </summary>
 protected void Remove(object sender, EventArgs e)
 {
     try
     {
         cart = ShoppingCartInfoProvider.GetShoppingCartInfo(CartID);
         foreach (ShoppingCartItemInfo scii in cart.CartItems)
         {
             if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) ||
                 (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID))
             {
                 ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii);
             }
         }
         ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID);
         ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, ShoppingCartItemInfoObject.CartItemGUID);
         if (cart.CartItems.Count == 0)
         {
             ShoppingCartInfoProvider.DeleteShoppingCartInfo(cart.ShoppingCartID);
         }
         mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU,
                                                                   ShoppingCartItemInfoObject.CartItemUnits, ContactID);
         ShoppingCartInfoProvider.EvaluateShoppingCart(cart);
         ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
         URLHelper.Redirect($"{Request.RawUrl}?status={QueryStringStatus.Deleted}");
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message);
     }
 }
    /// <summary>
    /// Removes the current cart item and the associated product options from the shopping cart.
    /// </summary>
    protected void Remove(object sender, EventArgs e)
    {
        // Delete all the children from the database if available
        foreach (ShoppingCartItemInfo scii in ShoppingCart.CartItems)
        {
            if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID))
            {
                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii);
            }
        }

        // Deletes the CartItem from the database
        ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID);
        // Delete the CartItem form the shopping cart object (session)
        ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID);
        // Log remove item activity
        Activity activity = new ActivityProductRemovedFromShoppingCart(ShoppingCartItemInfoObject, ResHelper.LocalizeString(ShoppingCartItemInfoObject.SKU.SKUName), ContactID, AnalyticsContext.ActivityEnvironmentVariables);

        activity.Log();

        // Recalculate shopping cart
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Raise the change event for all subscribed web parts
        ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
    }
    protected void ReloadData()
    {
        // Recalculate shopping cart
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        gridData.DataSource = ShoppingCart.ContentTable;
        gridData.DataBind();

        gridTaxSummary.DataSource = ShoppingCart.ContentTaxesTable;
        gridTaxSummary.DataBind();

        gridShippingTaxSummary.DataSource = ShoppingCart.ShippingTaxesTable;
        gridShippingTaxSummary.DataBind();

        // 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
            });
        });

        // shipping option, payment method initialization
        InitPaymentShipping();
    }
Esempio n. 7
0
    /// <summary>
    /// Saving billing requires recalculation of order. Save action is executed by this custom code.
    /// </summary>
    protected void editOrderBilling_OnBeforeSave(object sender, EventArgs e)
    {
        // Load the shopping cart to process the data
        ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID);

        // Update data only if shopping cart data were changed
        int paymentID  = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderPaymentOptionID"].DataValue, 0);
        int currencyID = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderCurrencyID"].DataValue, 0);

        // Recalculate order
        if ((sci != null) && ((sci.ShoppingCartPaymentOptionID != paymentID) || (sci.ShoppingCartCurrencyID != currencyID)))
        {
            // Set order new properties
            sci.ShoppingCartPaymentOptionID = paymentID;
            sci.ShoppingCartCurrencyID      = currencyID;

            // Evaluate order data
            ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

            // Update order data
            ShoppingCartInfoProvider.SetOrder(sci, true);
        }

        // Update only one order property
        if (Order.OrderIsPaid != OrderIsPaid)
        {
            Order.OrderIsPaid = OrderIsPaid;
            OrderInfoProvider.SetOrderInfo(Order);
        }

        ShowChangesSaved();

        // Stop automatic saving action
        editOrderBilling.StopProcessing = true;
    }
Esempio n. 8
0
 void editOrderBilling_OnAfterSave(object sender, EventArgs e)
 {
     if (recalculateOrder)
     {
         ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID);
         // Evaluate order data
         ShoppingCartInfoProvider.EvaluateShoppingCart(sci);
         // Update order data
         ShoppingCartInfoProvider.SetOrder(sci, true);
     }
 }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Check whether some address is selected
        int addressId = addressElem.AddressID;

        if (addressId <= 0)
        {
            // Show error message
            ShowError(GetString("Order_Edit_Billing.NoAddress"));

            return;
        }

        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        EditedObject = oi;

        if (oi != null)
        {
            // Check if paid status was changed
            orderIsPaidChanged = (oi.OrderIsPaid != chkOrderIsPaid.Checked);

            // Load the shopping cart to process the data
            ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
            if (sci != null)
            {
                // Set order new properties
                sci.ShoppingCartBillingAddressID = addressId;
                sci.ShoppingCartPaymentOptionID  = drpPayment.PaymentID;
                sci.ShoppingCartCurrencyID       = drpCurrency.CurrencyID;

                // Evaluate order data
                ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                // Update order data
                ShoppingCartInfoProvider.SetOrder(sci, false);
            }

            // Mark order as paid
            oi.OrderIsPaid = chkOrderIsPaid.Checked;
            OrderInfoProvider.SetOrderInfo(oi);

            // Show message
            ShowChangesSaved();
        }
    }
Esempio n. 10
0
    /// <summary>
    /// Updates the unit count for the current cart item and it's children.
    /// </summary>
    public void Update(object sender, EventArgs e)
    {
        // Disable update operation for ReadOnly mode
        if (ReadOnly)
        {
            return;
        }

        if ((ShoppingCartItemInfoObject != null) && !ShoppingCartItemInfoObject.IsProductOption)
        {
            var count = ValidationHelper.GetInteger(unitCountFormControl.Value, -1);
            // Do nothing (leave old value) for invalid/same input
            if ((count < 0) || (count == ShoppingCartItemInfoObject.CartItemUnits))
            {
                return;
            }

            if (count == 0)
            {
                // Delete all item options if available
                foreach (var option in ShoppingCart.CartItems.Where(scii => scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID))
                {
                    ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(option);
                }

                // Delete all bundle items if available
                foreach (var bundleItem in ShoppingCartItemInfoObject.BundleItems)
                {
                    ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(bundleItem);
                }

                // Deletes the CartItem from the database
                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID);
                // Delete the CartItem form the shopping cart object (session)
                ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID);
            }
            else
            {
                ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(ShoppingCartItemInfoObject, count);
            }

            // Invalidate the shopping cart so it is recalculated with the correct values
            ShoppingCart.InvalidateCalculations();
            ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);
        }

        // Raise the change event for all subscribed web parts
        ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
    }
    /// <summary>
    /// Validates shopping cart content.
    /// </summary>
    public override bool IsValid()
    {
        // Force loading current values
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

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

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

            return(false);
        }

        return(true);
    }
        private void UpdateCartItemQuantity(ShoppingCartItemInfo item, int quantity)
        {
            var cart = ECommerceContext.CurrentShoppingCart;

            var productType = item.GetStringValue("ProductType", string.Empty);

            if (!productType.Contains(ProductTypes.InventoryProduct) && !productType.Contains(ProductTypes.POD) && !productType.Contains(ProductTypes.StaticProduct))
            {
                throw new Exception(ResHelper.GetString("Kadena.Product.QuantityForTypeError", LocalizationContext.CurrentCulture.CultureCode));
            }

            if (productType.Contains(ProductTypes.InventoryProduct) && quantity > item.SKU.SKUAvailableItems)
            {
                throw new ArgumentOutOfRangeException(string.Format(
                                                          ResHelper.GetString("Kadena.Product.SetQuantityForItemError", LocalizationContext.CurrentCulture.CultureCode), quantity, item.CartItemID));
            }

            var documentId = item.GetIntegerValue("ProductPageID", 0);
            var ranges     = dynamicPrices.GetDynamicPricingRanges(documentId);

            if ((ranges?.Count() ?? 0) > 0)
            {
                var price = dynamicPrices.GetDynamicPrice(quantity, ranges);

                if (price != 0.0m)
                {
                    item.CartItemPrice = (double)price;
                    ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item, quantity);
                }
                else
                {
                    throw new Exception(ResHelper.GetString("Kadena.Product.QuantityOutOfRange", LocalizationContext.CurrentCulture.CultureCode));
                }
            }
            else
            {
                ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item, quantity);
            }

            cart.InvalidateCalculations();
            ShoppingCartInfoProvider.EvaluateShoppingCart(cart);
        }
 /// <summary>
 /// Removes the current cart item and the associated product options from the shopping cart.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void linkRemoveItem_Click(object sender, EventArgs e)
 {
     try
     {
         RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;
         int cartItemID = int.Parse((item.FindControl("lblCartItemID") as Label).Text);
         ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItemID);
         ShoppingCartInfoProvider.RemoveShoppingCartItem(Cart, cartItemID);
         if (Cart.CartItems.Count == 0)
         {
             ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart.ShoppingCartID);
         }
         ShoppingCartInfoProvider.EvaluateShoppingCart(Cart);
         ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
         Response.Cookies["status"].Value = QueryStringStatus.Deleted;
         Response.Cookies["status"].HttpOnly = false;
         URLHelper.Redirect(Request.RawUrl);
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message);
     }
 }
Esempio n. 14
0
    /// <summary>
    /// Removes the current cart item and the associated product options from the shopping cart.
    /// </summary>
    protected void Remove(object sender, EventArgs e)
    {
        // Delete all the children from the database if available
        foreach (ShoppingCartItemInfo scii in ShoppingCart.CartItems)
        {
            if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID))
            {
                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii);
            }
        }

        // Deletes the CartItem from the database
        ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID);
        // Delete the CartItem form the shopping cart object (session)
        ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID);
        // Log remove item activity
        mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU, ShoppingCartItemInfoObject.CartItemUnits, ContactID);

        // Recalculate shopping cart
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Raise the change event for all subscribed web parts
        ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
    }
Esempio n. 15
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Check if order item modification is allowed
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders") || !ECommerceSettings.EnableOrderItemEditing)
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Reset auto added units (already auto added units in the shopping cart will not removed)
        ShoppingCartItem.CartItemAutoAddedUnits = 0;

        // Get new price
        double rate     = (SKU.IsGlobal) ? ShoppingCart.ExchangeRateForGlobalItems : ShoppingCart.ExchangeRate;
        double newPrice = ExchangeRateInfoProvider.ApplyExchangeRate(ValidationHelper.GetDouble(EditForm.FieldControls["CartItemUnitPrice"].Value, 0.0), 1 / rate);

        // Update price
        if ((SKU.SKUProductType == SKUProductTypeEnum.Donation) ||
            (SKU.SKUProductType == SKUProductTypeEnum.Text))
        {
            // Donation product type stores value in CartItemPrice
            ShoppingCartItem.CartItemPrice = newPrice;
        }
        else
        {
            SKU.SKUPrice = newPrice;
        }

        // Update SKUName
        SKU.SKUName = ValidationHelper.GetString(EditForm.FieldControls["CartItemName"].Value, "");

        // Update units
        ShoppingCartItem.CartItemUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        // Update is private information
        if (SKU.SKUProductType == SKUProductTypeEnum.Donation)
        {
            ShoppingCartItem.CartItemIsPrivate = ValidationHelper.GetBoolean(EditForm.FieldControls["CartItemIsPrivate"].Value, false);
        }

        // Update product text
        if (SKU.IsProductOption && (SKU.SKUOptionCategory.CategoryType == OptionCategoryTypeEnum.Text))
        {
            var controlName = (SKU.SKUOptionCategory.CategorySelectionType == OptionCategorySelectionTypeEnum.TextArea) ? "CartItemTextArea" : "CartItemTextBox";
            ShoppingCartItem.CartItemText = ValidationHelper.GetString(EditForm.FieldControls[controlName].Value, String.Empty);
        }

        // Update units of the product options
        int skuUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        foreach (ShoppingCartItemInfo option in ShoppingCartItem.ProductOptions)
        {
            option.CartItemUnits = skuUnits;
        }

        // Evaluate shopping cart content
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Close dialog window and refresh parent window
        CloseDialogWindow();

        // Do not save ShoppingCartItem to the database
        EditForm.StopProcessing = true;
    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check 'ModifyOrders' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToCMSDeskAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            ShoppingCartItem.SKU.SKUName = txtSKUName.Text;

            // Get new price
            double rate     = (ShoppingCartItem.SKU.IsGlobal) ? ShoppingCart.ExchangeRateForGlobalItems : ShoppingCart.ExchangeRate;
            double newPrice = ExchangeRateInfoProvider.ApplyExchangeRate(txtSKUPrice.Price, 1 / rate);

            // Update price
            if (ShoppingCartItem.SKU.SKUProductType == SKUProductTypeEnum.Donation ||
                ShoppingCartItem.SKU.SKUProductType == SKUProductTypeEnum.Text)
            {
                ShoppingCartItem.CartItemPrice = newPrice;
            }
            else
            {
                ShoppingCartItem.SKU.SKUPrice = newPrice;
            }

            // Update units
            ShoppingCartItem.CartItemUnits = ValidationHelper.GetInteger(txtSKUUnits.Text, 0);

            // Update is private information
            if (plcIsPrivate.Visible)
            {
                ShoppingCartItem.CartItemIsPrivate = chkIsPrivate.Checked;
            }

            // Update product text when visible
            if (plcItemText.Visible == true)
            {
                ShoppingCartItem.CartItemText = txtItemText.Visible ? txtItemText.Text : txtItemMultiText.Text;
            }

            // Update units of the product options
            foreach (ShoppingCartItemInfo option in ShoppingCartItem.ProductOptions)
            {
                option.CartItemUnits = ShoppingCartItem.CartItemUnits;
            }

            // Evaluate shopping cart content
            ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

            // Close dialog window and refresh parent window
            string url = "~/CMSModules/Ecommerce/Pages/Tools/Orders/Order_Edit_OrderItems.aspx?orderid=" + ShoppingCart.OrderId + "&cartexist=1";
            ltlScript.Text = ScriptHelper.GetScript("CloseAndRefresh('" + ResolveUrl(url) + "')");
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }
Esempio n. 17
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Check if order item modification is allowed
        if (!Order.CheckPermissions(PermissionsEnum.Modify, CurrentSiteName, CurrentUser))
        {
            RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyOrders");
        }

        // Reset auto added units (already auto added units in the shopping cart will not removed)
        ShoppingCartItem.CartItemAutoAddedUnits = 0;

        // Get new price
        var rate     = (SKU.IsGlobal) ? ShoppingCart.ExchangeRateForGlobalItems : ShoppingCart.ExchangeRate;
        var newPrice = (double)CurrencyConverter.ApplyExchangeRate(ValidationHelper.GetDecimal(EditForm.FieldControls["CartItemUnitPrice"].Value, 0m), (decimal)(1 / rate));

        // Update direct price (donation or product with attribute or text options)
        if (!Double.IsNaN(ShoppingCartItem.CartItemPrice))
        {
            if (ShoppingCartItem.ProductOptions.Count > 0)
            {
                // Set price without product options to SKU
                ShoppingCartItem.SKU.SKUPrice += newPrice - ShoppingCartItem.CartItemPrice;
            }

            ShoppingCartItem.CartItemPrice = newPrice;
        }
        else
        {
            SKU.SKUPrice = newPrice;
        }

        // Update SKUName
        SKU.SKUName = ValidationHelper.GetString(EditForm.FieldControls["CartItemName"].Value, "");

        // Update units
        ShoppingCartItem.CartItemUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        // Update is private information
        if (SKU.SKUProductType == SKUProductTypeEnum.Donation)
        {
            ShoppingCartItem.CartItemIsPrivate = ValidationHelper.GetBoolean(EditForm.FieldControls["CartItemIsPrivate"].Value, false);
        }

        // Update product text
        if (SKU.IsTextAttribute)
        {
            var controlName = (SKU.SKUOptionCategory.CategorySelectionType == OptionCategorySelectionTypeEnum.TextArea) ? "CartItemTextArea" : "CartItemTextBox";
            ShoppingCartItem.CartItemText = ValidationHelper.GetString(EditForm.FieldControls[controlName].Value, String.Empty);
        }

        // Update units of the product options
        int skuUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        foreach (var option in ShoppingCartItem.ProductOptions)
        {
            option.CartItemUnits = skuUnits;
        }

        // Evaluate shopping cart content
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Close dialog window and refresh parent window
        CloseDialogWindow();

        // Do not save ShoppingCartItem to the database
        EditForm.StopProcessing = true;
    }
    protected void OnBeforeSave(object sender, EventArgs e)
    {
        if ((Order == null) || (ShippingAddressSelector == null) || (ShippingOptionSelector == null))
        {
            return;
        }

        // Get current values
        int addressID        = ValidationHelper.GetInteger(ShippingAddressSelector.Value, 0);
        int shippingOptionID = ValidationHelper.GetInteger(ShippingOptionSelector.Value, 0);

        // Is shipping needed?
        bool isShippingNeeded = ((ShoppingCartFromOrder != null) && ShoppingCartFromOrder.IsShippingNeeded);

        // If shipping address is required
        if (isShippingNeeded || IsTaxBasedOnShippingAddress)
        {
            // If shipping address is not set
            if (addressID <= 0)
            {
                // Show error message
                ShowError(GetString("Order_Edit_Shipping.NoAddress"));
                return;
            }
        }

        try
        {
            // Shipping option changed
            if ((ShoppingCartFromOrder != null) && (Order.OrderShippingOptionID != shippingOptionID))
            {
                // Shipping option and payment method combination is not allowed
                if (PaymentShippingInfoProvider.GetPaymentShippingInfo(Order.OrderPaymentOptionID, shippingOptionID) == null)
                {
                    PaymentOptionInfo payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(Order.OrderPaymentOptionID);

                    // Check if payment is allowed with no shipping
                    if ((payment != null) && !(payment.PaymentOptionAllowIfNoShipping && shippingOptionID == 0))
                    {
                        // Set payment method to none and display warning
                        ShoppingCartFromOrder.ShoppingCartPaymentOptionID = 0;

                        string paymentMethodName  = ResHelper.LocalizeString(payment.PaymentOptionDisplayName, null, true);
                        string shippingOptionName = HTMLHelper.HTMLEncode(ShippingOptionSelector.ValueDisplayName);

                        ShowWarning(String.Format(ResHelper.GetString("com.shippingoption.paymentsetnone"), paymentMethodName, shippingOptionName));
                    }
                }

                // Set order new properties
                ShoppingCartFromOrder.ShoppingCartShippingOptionID = shippingOptionID;

                // Evaluate order data
                ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCartFromOrder);

                // Update order data
                ShoppingCartInfoProvider.SetOrder(ShoppingCartFromOrder, true);
            }

            // Update tracking number
            Order.OrderTrackingNumber = ValidationHelper.GetString(orderShippingForm.FieldEditingControls["OrderTrackingNumber"].DataValue, String.Empty).Trim();
            OrderInfoProvider.SetOrderInfo(Order);

            // Show message
            ShowChangesSaved();

            // Stop automatic saving action
            orderShippingForm.StopProcessing = true;
        }
        catch (Exception ex)
        {
            // Show error message
            ShowError(ex.Message);
        }
    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Get order
        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        if (oi != null)
        {
            // Are taxes based on shipping address?
            bool     taxesBasedOnShipping = false;
            SiteInfo si = SiteInfoProvider.GetSiteInfo(oi.OrderSiteID);
            if (si != null)
            {
                taxesBasedOnShipping = (ECommerceSettings.ApplyTaxesBasedOn(si.SiteName) == ApplyTaxBasedOnEnum.ShippingAddress);
            }

            // Is shipping needed?
            bool isShippingNeeded = ((ShoppingCartInfoObj != null) && (ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCartInfoObj)));

            // If shipping address is required
            if (isShippingNeeded || taxesBasedOnShipping)
            {
                // If shipping address is not set
                if (addressElem.AddressID <= 0)
                {
                    // Show error message
                    ShowError(GetString("Order_Edit_Shipping.NoAddress"));

                    return;
                }
            }

            try
            {
                // Load the shopping cart to process the data
                ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
                if (sci != null)
                {
                    // Set order new properties
                    sci.ShoppingCartShippingOptionID  = drpShippingOption.ShippingID;
                    sci.ShoppingCartShippingAddressID = addressElem.AddressID;

                    // Evaluate order data
                    ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                    // Update order data
                    ShoppingCartInfoProvider.SetOrder(sci, false);
                }

                // Update tracking number
                oi.OrderTrackingNumber = txtTrackingNumber.Text.Trim();
                OrderInfoProvider.SetOrderInfo(oi);

                // Show message
                ShowChangesSaved();

                // Update shipping charge in selector
                if (taxesBasedOnShipping)
                {
                    drpShippingOption.ShoppingCart = sci;
                    drpShippingOption.Reload(false);
                }
            }
            catch (Exception ex)
            {
                // Show error message
                ShowError(ex.Message);
            }
        }
    }
Esempio n. 20
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Get order
        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        if (oi != null)
        {
            // Get order site
            SiteInfo si = SiteInfoProvider.GetSiteInfo(oi.OrderSiteID);

            // If shipping address is required
            if (((this.ShoppingCartInfoObj != null) && (ShippingOptionInfoProvider.IsShippingNeeded(this.ShoppingCartInfoObj))) ||
                ((si != null) && (ECommerceSettings.ApplyTaxesBasedOn(si.SiteName) == ApplyTaxBasedOnEnum.ShippingAddress)))
            {
                // If shipping address is not set
                if (this.addressElem.AddressID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Order_Edit_Shipping.NoAddress");

                    return;
                }
            }

            try
            {
                // Load the shopping cart to process the data
                ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
                if (sci != null)
                {
                    // Set order new properties
                    sci.ShoppingCartShippingOptionID  = drpShippingOption.ShippingID;
                    sci.ShoppingCartShippingAddressID = this.addressElem.AddressID;

                    // Evaulate order data
                    ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                    // Update order data
                    ShoppingCartInfoProvider.SetOrder(sci, false);
                }

                // Update tracking number
                oi.OrderTrackingNumber = txtTrackingNumber.Text.Trim();
                OrderInfoProvider.SetOrderInfo(oi);

                lblInfo.Visible = true;
                lblInfo.Text    = GetString("General.ChangesSaved");
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
    }
    protected void btnUpdate_Click1(object sender, EventArgs e)
    {
        if (ShoppingCart != null)
        {
            // Do not update order if it is already paid
            if (OrderIsPaid)
            {
                return;
            }

            ShoppingCart.ShoppingCartCurrencyID = ValidationHelper.GetInteger(selectCurrency.SelectedID, 0);

            // Skip if method was called by btnAddProduct
            if (sender != btnAddProduct)
            {
                foreach (GridViewRow row in gridData.Rows)
                {
                    // Get shopping cart item Guid
                    Guid cartItemGuid = ValidationHelper.GetGuid(((Label)row.Cells[1].Controls[1]).Text, Guid.Empty);

                    // Try to find shopping cart item in the list
                    ShoppingCartItemInfo cartItem = ShoppingCart.GetShoppingCartItem(cartItemGuid);
                    if (cartItem != null)
                    {
                        // If product and its product options should be removed
                        if (((CMSCheckBox)row.Cells[4].Controls[1]).Checked && (sender != null))
                        {
                            // Remove product and its product option from list
                            ShoppingCart.RemoveShoppingCartItem(cartItemGuid);

                            if (!ShoppingCartControl.IsInternalOrder)
                            {
                                // Log activity
                                if (!cartItem.IsProductOption && !cartItem.IsBundleItem)
                                {
                                    mActivityLogger.LogProductRemovedFromShoppingCartActivity(cartItem.SKU, cartItem.CartItemUnits, ContactID);
                                }

                                // Delete product from database
                                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItem);
                            }
                        }
                        // If product units has changed
                        else if (!cartItem.IsProductOption)
                        {
                            // Get number of units
                            int itemUnits = ValidationHelper.GetInteger(((TextBox)(row.Cells[7].Controls[1])).Text.Trim(), 0);
                            if ((itemUnits > 0) && (cartItem.CartItemUnits != itemUnits))
                            {
                                // Update units of the parent product
                                ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(cartItem, itemUnits);
                            }
                        }
                    }
                }
            }

            CheckDiscountCoupon();

            // Recalculate shopping cart
            ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

            ReloadData();

            if ((ShoppingCart.ShoppingCartDiscountCouponID > 0) && (!ShoppingCart.IsDiscountCouponApplied))
            {
                // Discount coupon code is valid but not applied to any product of the shopping cart
                lblError.Text = GetString("shoppingcart.discountcouponnotapplied");
            }

            // Inventory should be checked
            checkInventory = true;
        }
    }