private string GetSavedItemIds()
    {
        DataSet items = BundleInfoProvider.GetBundles("BundleID = " + SKUID, "SKUID");

        if (!DataHelper.DataSourceIsEmpty(items))
        {
            return(TextHelper.Join(";", SystemDataHelper.GetStringValues(items.Tables[0], "SKUID")));
        }
        return(null);
    }
    /// <summary>
    /// Checks if user is able to generate variants. Returns warning message if validation failed, empty string if it passed.
    /// </summary>
    private string VariantsCanBeGenerated()
    {
        // Inform user about need to change product type to be able to generate variants, it is allowed only for a standard product
        if (Product.SKUProductType != SKUProductTypeEnum.Product)
        {
            return(String.Format(GetString("com.variant.notstandardproduct"), GetString("com.producttype.product")));
        }

        // Data set with option categories assigned to the product
        DataSet optionCategories = OptionCategoryInfoProvider.GetProductOptionCategories(ProductID, true, OptionCategoryTypeEnum.Attribute);
        // List of assigned Category IDs
        IList <int> categoryIDs = DataHelper.GetIntegerValues(optionCategories.Tables[0], "CategoryID");

        // Inform that attribute option category does not exist for this product
        if (DataHelper.DataSourceIsEmpty(optionCategories))
        {
            return(GetString("com.variant.nooptioncategorycreated"));
        }

        bool variantsCannotBeGenerated = true;

        foreach (int categoryId in categoryIDs)
        {
            var enabledAllowedOptions = SKUInfoProvider.GetSKUOptionsForProduct(Product.SKUID, categoryId, true).TopN(1);

            if (!DataHelper.DataSourceIsEmpty(enabledAllowedOptions))
            {
                variantsCannotBeGenerated = false;
                break;
            }
        }

        // Inform that any option is selected,created or enabled in assigned option category
        if (variantsCannotBeGenerated)
        {
            return(GetString("com.variant.nooptionselectedforproduct"));
        }

        var bundles = SKUInfoProvider.GetSKUs()
                      .Column("SKUName")
                      .WhereIn("SKUID", BundleInfoProvider.GetBundles()
                               .Column("BundleID")
                               .WhereEquals("SKUID", Product.SKUID)
                               )
                      .GetListResult <string>();

        if (bundles.Count > 0)
        {
            return(String.Format(GetString("com.variant.productusedinbundle"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(string.Join(", ", bundles)))));
        }

        return("");
    }
Exemple #3
0
    /// <summary>
    /// Saves currently selected products to bundle.
    /// </summary>
    public void SaveProductsSelectionChanges()
    {
        string newSelection        = ValidationHelper.GetString(this.productsUniSelector.Value, null);
        string selectionDifference = null;

        // Get deselected products
        selectionDifference = DataHelper.GetNewItemsInList(newSelection, this.selectedProducts);

        // Remove deselected products
        if (!String.IsNullOrEmpty(selectionDifference))
        {
            string[] items = selectionDifference.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (items != null)
            {
                // Remove products from bundle
                foreach (string item in items)
                {
                    int skuId = ValidationHelper.GetInteger(item, 0);
                    BundleInfoProvider.RemoveSKUFromBundle(this.BundleID, skuId);
                }
            }
        }

        // Get newly selected products
        selectionDifference = DataHelper.GetNewItemsInList(this.selectedProducts, newSelection);

        // Add newly selected products
        if (!String.IsNullOrEmpty(selectionDifference))
        {
            string[] items = selectionDifference.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (items != null)
            {
                // Add products to bundle
                foreach (string item in items)
                {
                    int skuId = ValidationHelper.GetInteger(item, 0);
                    BundleInfoProvider.AddSKUToBundle(this.BundleID, skuId);
                }
            }
        }

        if (this.OnProductsSelectionChangesSaved != null)
        {
            this.OnProductsSelectionChangesSaved(this, EventArgs.Empty);
        }
    }
    /// <summary>
    /// Saves the currently selected bundle items to the database.
    /// </summary>
    public void SaveSelectionChanges()
    {
        var savedItems = GetSavedItemIds();

        var addedItems = DiffItemIds(savedItems, Items);

        foreach (var id in addedItems)
        {
            BundleInfoProvider.AddSKUToBundle(SKUID, id);
        }

        var removedItems = DiffItemIds(Items, savedItems);

        foreach (var id in removedItems)
        {
            BundleInfoProvider.RemoveSKUFromBundle(SKUID, id);
        }
    }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // If bundle ID set
        if (this.BundleID != 0)
        {
            // Get selected products from database
            DataSet selectedProductsDataSet = BundleInfoProvider.GetBundles("BundleID = " + this.BundleID, "SKUID");

            if (!DataHelper.DataSourceIsEmpty(selectedProductsDataSet))
            {
                this.selectedProducts = TextHelper.Join(";", SqlHelperClass.GetStringValues(selectedProductsDataSet.Tables[0], "SKUID"));
            }
        }

        // If reload required
        if (this.ReloadRequired)
        {
            // Set selected products to selector
            this.productsUniSelector.Value = this.selectedProducts;
        }

        string where = null;

        // Exclude product options
        where = SqlHelperClass.AddWhereCondition(where, "SKUOptionCategoryID IS NULL");

        // Exclude bundle products
        where = SqlHelperClass.AddWhereCondition(where, String.Format("SKUProductType <> '{0}'", SKUInfoProvider.GetSKUProductTypeString(SKUProductTypeEnum.Bundle)));

        // Exclude donation products
        where = SqlHelperClass.AddWhereCondition(where, String.Format("SKUProductType <> '{0}'", SKUInfoProvider.GetSKUProductTypeString(SKUProductTypeEnum.Donation)));

        // Exclude edited product itself
        where = SqlHelperClass.AddWhereCondition(where, "SKUID <> " + this.BundleID);

        // If bundle is global
        if (this.SiteID == 0)
        {
            // Inlcude global products
            where = SqlHelperClass.AddWhereCondition(where, "SKUSiteID IS NULL");
        }
        else
        {
            // If global products are allowed on this site
            if (ECommerceSettings.AllowGlobalProducts(SiteInfoProvider.GetSiteName(this.SiteID)))
            {
                // Include global and site products
                where = SqlHelperClass.AddWhereCondition(where, String.Format("(SKUSiteID IS NULL) OR (SKUSiteID = {0})", this.SiteID));
            }
            else
            {
                // Include site products
                where = SqlHelperClass.AddWhereCondition(where, "SKUSiteID = " + this.SiteID);
            }
        }

        // Include only enabled products
        where = SqlHelperClass.AddWhereCondition(where, "SKUEnabled = 1");

        // Include only products from user's departments
        if (!ECommerceContext.IsUserAuthorizedForPermission("AccessAllDepartments"))
        {
            where = SqlHelperClass.AddWhereCondition(where, String.Format("(SKUDepartmentID IN (SELECT DepartmentID FROM COM_UserDepartment WHERE UserID = {0}) OR (SKUDepartmentID IS NULL))", CMSContext.CurrentUser.UserID));
        }

        // Include currently selected products
        if (!string.IsNullOrEmpty(this.selectedProducts))
        {
            where = SqlHelperClass.AddWhereCondition(where, String.Format("SKUID IN ({0})", this.selectedProducts.Replace(';', ',')), "OR");
        }

        this.productsUniSelector.WhereCondition      = where;
        this.productsUniSelector.SelectionMode       = SelectionModeEnum.Multiple;
        this.productsUniSelector.OnSelectionChanged += new EventHandler(productsUniSelector_OnSelectionChanged);
        this.productsUniSelector.StopProcessing      = this.StopProcessing;
    }
    /// <summary>
    /// Saves edited SKU and returns it's ID. In case of error 0 is returned. Does not fire product saved event.
    /// </summary>
    private int SaveInternal()
    {
        // Check permissions
        this.CheckModifyPermission();

        // If form is valid and enabled
        if (this.Validate() && this.FormEnabled)
        {
            bool newItem = false;

            // Get SKUInfo
            SKUInfo skuiObj = SKUInfoProvider.GetSKUInfo(mProductId);

            if (skuiObj == null)
            {
                newItem = true;

                // Create new item -> insert
                skuiObj           = new SKUInfo();
                skuiObj.SKUSiteID = editedSiteId;
            }
            else
            {
                SKUProductTypeEnum oldProductType = skuiObj.SKUProductType;
                SKUProductTypeEnum newProductType = SKUInfoProvider.GetSKUProductTypeEnum((string)this.selectProductTypeElem.Value);

                // Remove e-product dependencies if required
                if ((oldProductType == SKUProductTypeEnum.EProduct) && (newProductType != SKUProductTypeEnum.EProduct))
                {
                    // Delete meta files
                    MetaFileInfoProvider.DeleteFiles(skuiObj.SKUID, ECommerceObjectType.SKU, MetaFileInfoProvider.OBJECT_CATEGORY_EPRODUCT);

                    // Delete SKU files
                    DataSet skuFiles = SKUFileInfoProvider.GetSKUFiles("FileSKUID = " + skuiObj.SKUID, null);

                    foreach (DataRow skuFile in skuFiles.Tables[0].Rows)
                    {
                        SKUFileInfo skufi = new SKUFileInfo(skuFile);
                        SKUFileInfoProvider.DeleteSKUFileInfo(skufi);
                    }
                }

                // Remove bundle dependencies if required
                if ((oldProductType == SKUProductTypeEnum.Bundle) && (newProductType != SKUProductTypeEnum.Bundle))
                {
                    // Delete SKU to bundle mappings
                    DataSet bundles = BundleInfoProvider.GetBundles("BundleID = " + skuiObj.SKUID, null);

                    foreach (DataRow bundle in bundles.Tables[0].Rows)
                    {
                        BundleInfo bi = new BundleInfo(bundle);
                        BundleInfoProvider.DeleteBundleInfo(bi);
                    }
                }
            }

            skuiObj.SKUName              = this.txtSKUName.Text.Trim();
            skuiObj.SKUNumber            = this.txtSKUNumber.Text.Trim();
            skuiObj.SKUDescription       = this.htmlTemplateBody.ResolvedValue;
            skuiObj.SKUPrice             = this.txtSKUPrice.Value;
            skuiObj.SKUEnabled           = this.chkSKUEnabled.Checked;
            skuiObj.SKUInternalStatusID  = this.internalStatusElem.InternalStatusID;
            skuiObj.SKUDepartmentID      = this.departmentElem.DepartmentID;
            skuiObj.SKUManufacturerID    = this.manufacturerElem.ManufacturerID;
            skuiObj.SKUPublicStatusID    = this.publicStatusElem.PublicStatusID;
            skuiObj.SKUSupplierID        = this.supplierElem.SupplierID;
            skuiObj.SKUSellOnlyAvailable = this.chkSKUSellOnlyAvailable.Checked;
            skuiObj.SKUNeedsShipping     = this.chkNeedsShipping.Checked;
            skuiObj.SKUWeight            = ValidationHelper.GetDouble(this.txtSKUWeight.Text.Trim(), 0);
            skuiObj.SKUHeight            = ValidationHelper.GetDouble(this.txtSKUHeight.Text.Trim(), 0);
            skuiObj.SKUWidth             = ValidationHelper.GetDouble(this.txtSKUWidth.Text.Trim(), 0);
            skuiObj.SKUDepth             = ValidationHelper.GetDouble(this.txtSKUDepth.Text.Trim(), 0);
            skuiObj.SKUConversionName    = ValidationHelper.GetString(this.ucConversion.Value, String.Empty);
            skuiObj.SKUConversionValue   = this.txtConversionValue.Text.Trim();

            if (String.IsNullOrEmpty(this.txtSKUAvailableItems.Text.Trim()))
            {
                skuiObj.SetValue("SKUAvailableItems", null);
            }
            else
            {
                skuiObj.SKUAvailableItems = ValidationHelper.GetInteger(this.txtSKUAvailableItems.Text.Trim(), 0);
            }

            if (String.IsNullOrEmpty(this.txtSKUAvailableInDays.Text.Trim()))
            {
                skuiObj.SetValue("SKUAvailableInDays", null);
            }
            else
            {
                skuiObj.SKUAvailableInDays = ValidationHelper.GetInteger(this.txtSKUAvailableInDays.Text.Trim(), 0);
            }

            if (String.IsNullOrEmpty(this.txtMaxOrderItems.Text.Trim()))
            {
                skuiObj.SetValue("SKUMaxItemsInOrder", null);
            }
            else
            {
                skuiObj.SKUMaxItemsInOrder = ValidationHelper.GetInteger(this.txtMaxOrderItems.Text.Trim(), 0);
            }

            if (!ProductOrdered)
            {
                // Set product type
                skuiObj.SKUProductType = SKUInfoProvider.GetSKUProductTypeEnum((string)this.selectProductTypeElem.Value);
            }

            // Clear product type specific properties
            skuiObj.SetValue("SKUMembershipGUID", null);
            skuiObj.SetValue("SKUValidity", null);
            skuiObj.SetValue("SKUValidFor", null);
            skuiObj.SetValue("SKUValidUntil", null);
            skuiObj.SetValue("SKUMaxDownloads", null);
            skuiObj.SetValue("SKUBundleInventoryType", null);
            skuiObj.SetValue("SKUPrivateDonation", null);
            skuiObj.SetValue("SKUMinPrice", null);
            skuiObj.SetValue("SKUMaxPrice", null);

            // Set product type specific properties
            switch (skuiObj.SKUProductType)
            {
            // Set membership specific properties
            case SKUProductTypeEnum.Membership:
                skuiObj.SKUMembershipGUID = this.membershipElem.MembershipGUID;
                skuiObj.SKUValidity       = this.membershipElem.MembershipValidity;

                if (skuiObj.SKUValidity == ValidityEnum.Until)
                {
                    skuiObj.SKUValidUntil = this.membershipElem.MembershipValidUntil;
                }
                else
                {
                    skuiObj.SKUValidFor = this.membershipElem.MembershipValidFor;
                }
                break;

            // Set e-product specific properties
            case SKUProductTypeEnum.EProduct:
                skuiObj.SKUValidity = this.eProductElem.EProductValidity;

                if (skuiObj.SKUValidity == ValidityEnum.Until)
                {
                    skuiObj.SKUValidUntil = this.eProductElem.EProductValidUntil;
                }
                else
                {
                    skuiObj.SKUValidFor = this.eProductElem.EProductValidFor;
                }
                break;

            // Set donation specific properties
            case SKUProductTypeEnum.Donation:
                skuiObj.SKUPrivateDonation = this.donationElem.DonationIsPrivate;

                if (this.donationElem.MinimumDonationAmount == 0.0)
                {
                    skuiObj.SetValue("SKUMinPrice", null);
                }
                else
                {
                    skuiObj.SKUMinPrice = this.donationElem.MinimumDonationAmount;
                }

                if (this.donationElem.MaximumDonationAmount == 0.0)
                {
                    skuiObj.SetValue("SKUMaxPrice", null);
                }
                else
                {
                    skuiObj.SKUMaxPrice = this.donationElem.MaximumDonationAmount;
                }
                break;

            // Set bundle specific properties
            case SKUProductTypeEnum.Bundle:
                skuiObj.SKUBundleInventoryType = this.bundleElem.RemoveFromInventory;
                break;
            }

            // When creating new product option
            if ((this.ProductID == 0) && (this.OptionCategoryID > 0))
            {
                skuiObj.SKUOptionCategoryID = this.OptionCategoryID;
            }

            if ((newItem) && (!SKUInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert)))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ecommerceproduct.versioncheck");

                return(0);
            }

            SKUInfoProvider.SetSKUInfo(skuiObj);

            if (newItem)
            {
                if (ECommerceSettings.UseMetaFileForProductImage)
                {
                    // Get allowed extensions
                    string settingKey        = (skuiObj.IsGlobal) ? "CMSUploadExtensions" : (CMSContext.CurrentSiteName + ".CMSUploadExtensions");
                    string allowedExtensions = SettingsKeyProvider.GetStringValue(settingKey);

                    // Get posted file
                    HttpPostedFile file = this.ucMetaFile.PostedFile;

                    if ((file != null) && (file.ContentLength > 0))
                    {
                        // Get file extension
                        string extension = Path.GetExtension(file.FileName);

                        // Check if file is an image and its extension is allowed
                        if (ImageHelper.IsImage(extension) && (String.IsNullOrEmpty(allowedExtensions) || FileHelper.CheckExtension(extension, allowedExtensions)))
                        {
                            // Upload SKU image meta file
                            this.ucMetaFile.ObjectID = skuiObj.SKUID;
                            this.ucMetaFile.UploadFile();

                            // Update SKU image path
                            this.UpdateSKUImagePath(skuiObj);
                        }
                        else
                        {
                            // Set error message
                            string error = ValidationHelper.GetString(SessionHelper.GetValue("NewProductError"), null);
                            error += ";" + String.Format(this.GetString("com.productedit.invalidproductimage"), extension);
                            SessionHelper.SetValue("NewProductError", error);
                        }
                    }
                }
                else
                {
                    skuiObj.SKUImagePath = this.imgSelect.Value;
                }

                // Upload initial e-product file
                if (skuiObj.SKUProductType == SKUProductTypeEnum.EProduct)
                {
                    this.eProductElem.SKUID = skuiObj.SKUID;
                    this.eProductElem.UploadNewProductFile();
                }
            }
            else
            {
                // Update SKU image path
                UpdateSKUImagePath(skuiObj);
            }

            SKUInfoProvider.SetSKUInfo(skuiObj);

            if ((mNodeId > 0) && (mProductId == 0))
            {
                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                TreeNode     node = tree.SelectSingleNode(mNodeId, TreeProvider.ALL_CULTURES);
                node.NodeSKUID = skuiObj.SKUID;
                node.Update();

                // Update search index for node
                if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled))
                {
                    SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID());
                }

                // Log synchronization
                DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);

                // Ensure new SKU values
                SKUInfoProvider.SetSKUInfo(skuiObj);
            }

            // If SKU is of bundle product type and bundle does not exist yet
            if ((skuiObj.SKUProductType == SKUProductTypeEnum.Bundle) && (this.bundleElem.BundleID == 0))
            {
                // Set bundle ID
                this.bundleElem.BundleID = skuiObj.SKUID;

                // Save selected products
                this.bundleElem.SaveProductsSelectionChanges();
            }

            this.ProductID = skuiObj.SKUID;

            // Reload form
            this.LoadData(skuiObj);

            // Set changes saved message
            this.lblInfo.Text = this.GetString("general.changessaved");

            return(ValidationHelper.GetInteger(skuiObj.SKUID, 0));
        }
        else
        {
            return(0);
        }
    }