Esempio n. 1
0
    /// <summary>
    /// Updates price of variants in asynchronous control.
    /// </summary>
    /// <param name="newPriceValue">New price of variant</param>
    protected void UpdatePrice(object newPriceValue)
    {
        try
        {
            double  newPrice    = (double)newPriceValue;
            SKUInfo variantInfo = null;

            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent            = false;
                eCommerceContext.SetLowestPriceToParent = false;

                // Update all variants
                if ((WhatEnum)ValidationHelper.GetInteger(drpWhat.SelectedIndex, -1) == WhatEnum.AllVariants)
                {
                    var variants = VariantHelper.GetVariants(ProductID);

                    foreach (var variant in variants)
                    {
                        variantInfo = variant;
                        UpdateVariant(variantInfo, newPrice);
                    }
                }
                // Update selected variants
                else
                {
                    var variantsToUpdate = ugVariants.SelectedItems;

                    foreach (var variantId in variantsToUpdate)
                    {
                        variantInfo = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(variantId, 0));

                        // Do not allow modify variants of other product
                        if ((variantInfo != null) && (variantInfo.SKUParentSKUID != ProductID))
                        {
                            variantInfo = null;
                        }

                        if (variantInfo != null)
                        {
                            UpdateVariant(variantInfo, newPrice);
                        }
                    }
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            if (variantInfo != null)
            {
                variantInfo.Generalized.SetObject();
            }
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.product.updatepriceerror");
            EventLogProvider.LogException("Update price bulk action", "UPDATEVARIANT", ex);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Deletes variants is asynchronous control.
    /// </summary>
    protected void Delete(object parameters)
    {
        bool variantWasDisabled = false;

        try
        {
            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent            = false;
                eCommerceContext.SetLowestPriceToParent = false;

                // Delete all variants
                if ((WhatEnum)ValidationHelper.GetInteger(drpWhat.SelectedIndex, -1) == WhatEnum.AllVariants)
                {
                    var variants = VariantHelper.GetVariants(ProductID);

                    foreach (SKUInfo variant in variants)
                    {
                        // Set flag when variant was disabled due to dependencies
                        variantWasDisabled |= !DeleteVariant(variant);
                    }
                }
                // Delete selected variants
                else
                {
                    List <string> variantsToDelete = ugVariants.SelectedItems;

                    foreach (string variantId in variantsToDelete)
                    {
                        var variantInfo = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(variantId, 0));

                        if ((variantInfo != null) && (variantInfo.SKUParentSKUID == ProductID))
                        {
                            // Set flag when variant was disabled due to dependencies
                            variantWasDisabled |= !DeleteVariant(variantInfo);
                        }
                    }
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            DataSet productVariants = VariantHelper.GetVariants(ProductID);
            if (!DataHelper.DataSourceIsEmpty(productVariants))
            {
                SKUInfo variantInfo = new SKUInfo(productVariants.Tables[0].Rows[0]);
                variantInfo.Generalized.SetObject();
            }
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.product.deleteerror");
            EventLogProvider.LogException("Variant listing", "DELETEVARIANT", ex);
        }

        ugVariants.ClearSelectedItems();

        if (variantWasDisabled)
        {
            CurrentWarning = GetString("com.product.edit.disablevariant");
        }
    }
    /// <summary>
    /// Updates price of variants in asynchronous control.
    /// </summary>
    /// <param name="newPriceValue">New price of variant</param>
    protected void UpdatePrice(object newPriceValue)
    {
        try
        {
            double newPrice = (double)newPriceValue;
            SKUInfo variantInfo = null;

            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent = false;
                eCommerceContext.SetLowestPriceToParent = false;

                // Update all variants
                if ((WhatEnum)ValidationHelper.GetInteger(drpWhat.SelectedIndex, -1) == WhatEnum.AllVariants)
                {
                    var variants = VariantHelper.GetVariants(ProductID);

                    foreach (var variant in variants)
                    {
                        variantInfo = variant;
                        UpdateVariant(variantInfo, newPrice);
                    }
                }
                // Update selected variants
                else
                {
                    var variantsToUpdate = ugVariants.SelectedItems;

                    foreach (var variantId in variantsToUpdate)
                    {
                        variantInfo = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(variantId, 0));

                        // Do not allow modify variants of other product
                        if ((variantInfo != null) && (variantInfo.SKUParentSKUID != ProductID))
                        {
                            variantInfo = null;
                        }

                        if (variantInfo != null)
                        {
                            UpdateVariant(variantInfo, newPrice);
                        }
                    }
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            if (variantInfo != null)
            {
                variantInfo.Generalized.SetObject();
            }
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.product.updatepriceerror");
            EventLogProvider.LogException("Update price bulk action", "UPDATEVARIANT", ex);
        }
    }
    /// <summary>
    /// Deletes variants is asynchronous control.
    /// </summary>
    protected void Delete(object parameters)
    {
        bool variantWasDisabled = false;

        try
        {
            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent = false;
                eCommerceContext.SetLowestPriceToParent = false;

                // Delete all variants
                if ((WhatEnum)ValidationHelper.GetInteger(drpWhat.SelectedIndex, -1) == WhatEnum.AllVariants)
                {
                    var variants = VariantHelper.GetVariants(ProductID);

                    foreach (SKUInfo variant in variants)
                    {
                        // Set flag when variant was disabled due to dependencies
                        variantWasDisabled |= !DeleteVariant(variant);
                    }
                }
                // Delete selected variants
                else
                {
                    List<string> variantsToDelete = ugVariants.SelectedItems;

                    foreach (string variantId in variantsToDelete)
                    {
                        var variantInfo = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(variantId, 0));

                        if ((variantInfo != null) && (variantInfo.SKUParentSKUID == ProductID))
                        {
                            // Set flag when variant was disabled due to dependencies
                            variantWasDisabled |= !DeleteVariant(variantInfo);
                        }
                    }
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            DataSet productVariants = VariantHelper.GetVariants(ProductID);
            if (!DataHelper.DataSourceIsEmpty(productVariants))
            {
                SKUInfo variantInfo = new SKUInfo(productVariants.Tables[0].Rows[0]);
                variantInfo.Generalized.SetObject();
            }
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.product.deleteerror");
            EventLogProvider.LogException("Variant listing", "DELETEVARIANT", ex);
        }

        ugVariants.ClearSelectedItems();

        if (variantWasDisabled)
        {
            CurrentWarning = GetString("com.product.edit.disablevariant");
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Generates variants asynchronous.
    /// </summary>
    /// <param name="parameter">AsyncControl parameters</param>
    private void GenerateAndSave(object parameter)
    {
        try
        {
            // Regenerate already existing variants
            if (mRegenerateVariants)
            {
                ProductAttributeSet   productAttributeSet = new ProductAttributeSet(CategorySelector.SelectedCategories.Values.Where(x => x > VariantOptionInfo.NewOption));
                List <ProductVariant> existingVariants    = VariantHelper.AddNewCategoriesToVariantsOfProduct(ProductID, productAttributeSet);

                // Use special action contexts to turn off unnecessary actions
                using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
                {
                    eCommerceContext.TouchParent            = false;
                    eCommerceContext.SetLowestPriceToParent = false;

                    existingVariants.ForEach(pVariant =>
                    {
                        AddLog(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(pVariant.Variant.SKUName)) + GetString("com.variants.isredefined"));
                        VariantHelper.SetProductVariant(pVariant);
                    });
                }

                // Save variant to update parent SKULastModified a SKUPrice properties
                var lastVariant = existingVariants.LastOrDefault();
                if (lastVariant != null)
                {
                    lastVariant.Variant.Generalized.SetObject();
                }
            }

            // Generate non-existing variants
            ProductVariant productVariant = null;

            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent            = false;
                eCommerceContext.SetLowestPriceToParent = false;

                foreach (DataRow row in mVariantsToGenerate)
                {
                    IEnumerable <int> options = GetAllOptions(row, NewCategories.Union(ExistingCategories));
                    productVariant = new ProductVariant(ProductID, new ProductAttributeSet(options));
                    AddLog(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(productVariant.Variant.SKUName)) + GetString("com.variants.isdefined"));
                    productVariant.Set();
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            if (productVariant != null)
            {
                productVariant.Variant.Generalized.SetObject();
            }
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.variant.definerror");
            EventLogProvider.LogException("Variant definition", "DEFINEVARIANT", ex);
        }
    }
    /// <summary>
    /// Generates variants asynchronous.
    /// </summary>
    /// <param name="parameter">AsyncControl parameters</param>
    private void GenerateAndSave(object parameter)
    {
        try
        {
            // Regenerate already existing variants
            if (mRegenerateVariants)
            {
                ProductAttributeSet productAttributeSet = new ProductAttributeSet(CategorySelector.SelectedCategories.Values.Where(x => x > VariantOptionInfo.NewOption));
                List<ProductVariant> existingVariants = VariantHelper.AddNewCategoriesToVariantsOfProduct(ProductID, productAttributeSet);

                // Use special action contexts to turn off unnecessary actions
                using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
                {
                    eCommerceContext.TouchParent = false;
                    eCommerceContext.SetLowestPriceToParent = false;
                    eCommerceContext.AssignDefaultTaxesToProducts = false;

                    existingVariants.ForEach(pVariant =>
                        {
                            AddLog(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(pVariant.Variant.SKUName)) + GetString("com.variants.isredefined"));
                            VariantHelper.SetProductVariant(pVariant);
                        });
                }

                // Save variant to update parent SKULastModified a SKUPrice properties
                var lastVariant = existingVariants.LastOrDefault();
                if (lastVariant != null)
                {
                    lastVariant.Variant.Generalized.SetObject();
                }
            }

            // Generate non-existing variants
            ProductVariant productVariant = null;

            // Use special action contexts to turn off unnecessary actions
            using (ECommerceActionContext eCommerceContext = new ECommerceActionContext())
            {
                eCommerceContext.TouchParent = false;
                eCommerceContext.SetLowestPriceToParent = false;
                eCommerceContext.AssignDefaultTaxesToProducts = false;

                foreach (DataRow row in mVariantsToGenerate)
                {
                    IEnumerable<int> options = GetAllOptions(row, NewCategories.Union(ExistingCategories));
                    productVariant = new ProductVariant(ProductID, new ProductAttributeSet(options));
                    AddLog(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(productVariant.Variant.SKUName)) + GetString("com.variants.isdefined"));
                    productVariant.Set();
                }
            }

            // Save variant to update parent SKULastModified a SKUPrice properties
            if (productVariant != null)
            {
                productVariant.Variant.Generalized.SetObject();
            }

        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.variant.definerror");
            EventLogProvider.LogException("Variant definition", "DEFINEVARIANT", ex);
        }
    }