Example #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);
        }
    }
    protected void btnRemove_Clicked(object sender, EventArgs e)
    {
        RaiseOnCheckPermissions(PERMISSION_MODIFY, this);

        IList <string> productVariantCategoryIds = null;

        // Variants of product
        DataSet variantCategories = VariantHelper.GetProductVariantsCategories(ProductID, false);

        if (!DataHelper.DataSourceIsEmpty(variantCategories))
        {
            // Category IDs used to generate variants of product
            productVariantCategoryIds = DataHelper.GetStringValues(variantCategories.Tables[0], "CategoryID");
        }

        bool displayWarning = false;

        // Remove option category if it was not used to generate variants
        foreach (string categoryId in categoryGrid.SelectedItems)
        {
            // Category is used in variant
            if ((productVariantCategoryIds != null) && (productVariantCategoryIds.Contains(categoryId)))
            {
                displayWarning = true;
            }
            else
            {
                // Unlink option category if it is not used
                ProductHelper.RemoveOptionCategory(ProductID, ValidationHelper.GetInteger(categoryId, 0));
            }
        }

        if (displayWarning)
        {
            ShowWarning(GetString("com.optioncategory.remove"));
        }

        categoryGrid.ReloadData();
        categoryGrid.ClearSelectedItems();
        ReloadUniSelectorData(true);
    }
Example #3
0
    /// <summary>
    /// Hide/rename columns in uniGrid before loading data.
    /// </summary>
    void grid_OnBeforeDataReload()
    {
        switch (categoryObj.CategoryType)
        {
        case OptionCategoryTypeEnum.Attribute:
        case OptionCategoryTypeEnum.Text:
            ugOptions.NamedColumns["SKUName"].HeaderText        = GetString("unigrid.productoptions.OptionName");
            ugOptions.NamedColumns["SKUNumber"].Visible         = false;
            ugOptions.NamedColumns["SKUDepartment"].Visible     = false;
            ugOptions.NamedColumns["SKUAvailableItems"].Visible = false;
            break;
        }

        // Hide price adjustment if category is used in product variants
        if (parentProductId > 0)
        {
            if (VariantHelper.AreCategoriesUsedInVariants(QueryHelper.GetInteger("productId", 0), new[] { categoryObj.CategoryID }))
            {
                ugOptions.NamedColumns["SKUPrice"].Visible = false;
            }
        }
    }
Example #4
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");
        }
    }