/// <summary>
    /// Returns formatted and localized SKU name.
    /// </summary>
    /// <param name="skuId">SKU ID</param>
    /// <param name="skuSiteId">SKU site ID</param>
    /// <param name="value">SKU name</param>
    /// <param name="isProductOption">Indicates if cart item is product option</param>
    /// <param name="isBundleItem">Indicates if cart item is bundle item</param>
    protected string GetSKUName(object skuId, object skuSiteId, object value, object isProductOption, object isBundleItem, object cartItemIsPrivate, object itemText, object productType)
    {
        string             name      = ResHelper.LocalizeString((string)value);
        bool               isPrivate = ValidationHelper.GetBoolean(cartItemIsPrivate, false);
        string             text      = itemText as string;
        StringBuilder      skuName   = new StringBuilder();
        SKUProductTypeEnum type      = SKUInfoProvider.GetSKUProductTypeEnum(productType as string);

        // If it is a product option or bundle item
        if (ValidationHelper.GetBoolean(isProductOption, false) || ValidationHelper.GetBoolean(isBundleItem, false))
        {
            skuName.Append("<span style=\"font-size:90%\"> - ");
            skuName.Append(HTMLHelper.HTMLEncode(name));

            if (!string.IsNullOrEmpty(text))
            {
                skuName.Append(" '" + HTMLHelper.HTMLEncode(text) + "'");
            }

            skuName.Append("</span>");
        }
        // If it is a parent product
        else
        {
            // Add private donation suffix
            if ((type == SKUProductTypeEnum.Donation) && (isPrivate))
            {
                name += String.Format(" ({0})", this.GetString("com.shoppingcartcontent.privatedonation"));
            }

            // In CMS Desk
            if (this.ShoppingCartControl.IsInternalOrder)
            {
                // Display link to SKU edit in dialog
                string url = this.ResolveUrl("~/CMSModules/Ecommerce/Pages/Tools/Products/Product_Edit_Frameset.aspx");
                url = URLHelper.AddParameterToUrl(url, "productid", skuId.ToString());
                url = URLHelper.AddParameterToUrl(url, "siteid", skuSiteId.ToString());
                url = URLHelper.AddParameterToUrl(url, "dialogmode", "1");
                skuName.Append(String.Format("<a href=\"#\" onclick=\"modalDialog('{0}', 'SKUEdit', 950, 700); return false;\">{1}</a>", url, HTMLHelper.HTMLEncode(name)));
            }
            // On live site
            else
            {
                if (type == SKUProductTypeEnum.Donation)
                {
                    // Display donation name without link
                    skuName.Append(HTMLHelper.HTMLEncode(name));
                }
                else
                {
                    // Display link to product page
                    skuName.Append(String.Format("<a href=\"{0}?productid={1}\" class=\"CartProductDetailLink\">{2}</a>", ResolveUrl("~/CMSPages/GetProduct.aspx"), skuId.ToString(), HTMLHelper.HTMLEncode(name)));
                }
            }
        }

        return(skuName.ToString());
    }
    /// <summary>
    /// Returns formatted and localized SKU name.
    /// </summary>
    /// <param name="skuId">SKU ID</param>
    /// <param name="skuSiteId">SKU site ID</param>
    /// <param name="cartItemIsPrivate">SKU name</param>
    /// <param name="itemText">Indicates if cart item is product option</param>
    /// <param name="productType">Indicates if cart item is bundle item</param>
    protected string GetSKUName(object skuId, object skuSiteId, object value, object isProductOption, object isBundleItem, object cartItemIsPrivate, object itemText, object productType)
    {
        string             name      = ResHelper.LocalizeString((string)value);
        bool               isPrivate = ValidationHelper.GetBoolean(cartItemIsPrivate, false);
        string             text      = itemText as string;
        StringBuilder      skuName   = new StringBuilder();
        SKUProductTypeEnum type      = ValidationHelper.GetString(productType, "").ToEnum <SKUProductTypeEnum>();

        // If it is a product option or bundle item
        if (ValidationHelper.GetBoolean(isProductOption, false) || ValidationHelper.GetBoolean(isBundleItem, false))
        {
            skuName.Append("<span style=\"font-size: 90%\"> - ");
            skuName.Append(HTMLHelper.HTMLEncode(name));

            if (!string.IsNullOrEmpty(text))
            {
                skuName.Append(" '" + HTMLHelper.HTMLEncode(text) + "'");
            }

            skuName.Append("</span>");
        }
        // If it is a parent product
        else
        {
            // Add private donation suffix
            if ((type == SKUProductTypeEnum.Donation) && (isPrivate))
            {
                name += string.Format(" ({0})", GetString("com.shoppingcartcontent.privatedonation"));
            }

            // In CMS Desk
            if (ShoppingCartControl.IsInternalOrder)
            {
                // Display SKU name
                skuName.Append(HTMLHelper.HTMLEncode(name));
            }
            // On live site
            else
            {
                if (type == SKUProductTypeEnum.Donation)
                {
                    // Display donation name without link
                    skuName.Append(HTMLHelper.HTMLEncode(name));
                }
                else
                {
                    // Display link to product page
                    skuName.AppendFormat("<a href=\"{0}?productid={1}\" class=\"CartProductDetailLink\">{2}</a>", ResolveUrl("~/CMSPages/Ecommerce/GetProduct.aspx"), skuId, HTMLHelper.HTMLEncode(name));
                }
            }
        }

        return(skuName.ToString());
    }
 private void AddProductTypeOption(SKUProductTypeEnum value)
 {
     AddStringOption(value.ToLocalizedString("com.producttype"), value.ToStringRepresentation());
 }
Exemple #4
0
 /// <summary>
 /// Adds item to product type dropdown list.
 /// </summary>
 /// <param name="productTypeName">Product type name resource string</param>
 /// <param name="productType">Product type</param>
 private void AddProductType(string productTypeName, SKUProductTypeEnum productType)
 {
     this.drpProductType.Items.Add(new ListItem(this.GetString(productTypeName), SKUInfoProvider.GetSKUProductTypeString(productType)));
 }
 private void AddProductTypeOption(string text, SKUProductTypeEnum value)
 {
     AddStringOption(text, SKUInfoProvider.GetSKUProductTypeString(value));
 }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private string GetWhereCondition()
    {
        string where = null;

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(CMSContext.CurrentSiteName))
        {
            where = "(SKUSiteID = " + CMSContext.CurrentSiteID + ") OR (SKUSiteID IS NULL)";
        }
        else
        {
            where = "SKUSiteID = " + CMSContext.CurrentSiteID;
        }

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUOptionCategoryID IS NULL");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUOptionCategoryID IS NOT NULL");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = SKUInfoProvider.GetSKUProductTypeEnum(Representing);
            string             productTypeString = SKUInfoProvider.GetSKUProductTypeString(productTypeEnum);

            where = SqlHelperClass.AddWhereCondition(where, "SKUProductType = N'" + productTypeString + "'");
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            string safeProductNumber = SqlHelperClass.GetSafeQueryString(ProductNumber, true);
            where = SqlHelperClass.AddWhereCondition(where, "SKUNumber LIKE N'%" + safeProductNumber + "%'");
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        if (di != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUDepartmentID = " + di.DepartmentID);
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        if (mi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUManufacturerID = " + mi.ManufacturerID);
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        if (si != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUSupplierID = " + si.SupplierID);
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUNeedsShipping = 1");
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where = SqlHelperClass.AddWhereCondition(where, "(SKUNeedsShipping = 0) OR (SKUNeedsShipping IS NULL)");
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPrice >= " + PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPrice <= " + PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPublicStatusID = " + psi.PublicStatusID);
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUInternalStatusID = " + isi.InternalStatusID);
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUEnabled = 1");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where = SqlHelperClass.AddWhereCondition(where, "(SKUEnabled = 0) OR (SKUEnabled IS NULL)");
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where = SqlHelperClass.AddWhereCondition(where, "SKUAvailableItems <= " + value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where = SqlHelperClass.AddWhereCondition(where, "((SKUReorderAt IS NULL) AND (SKUAvailableItems <= 0)) OR ((SKUReorderAt IS NOT NULL) AND (SKUAvailableItems <= SKUReorderAt))");
        }

        return(where);
    }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        var where = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))
        {
            where.Where(w => w.WhereEquals("SKUSiteID", SiteContext.CurrentSiteID).Or().WhereNull("SKUSiteID"));
        }

        // Show/hide product variants - it is based on type of inventory tracking for parent product
        string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation();

        where.Where(v => v.Where(w => w.WhereNull("SKUParentSKUID").And().WhereNotEquals("SKUTrackInventory", trackByVariants))
                    .Or()
                    .Where(GetParentProductWhereCondition(new WhereCondition().WhereEquals("SKUTrackInventory", trackByVariants))));

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where.WhereNull("SKUOptionCategoryID");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where.WhereNotNull("SKUOptionCategoryID");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = Representing.ToEnum <SKUProductTypeEnum>();
            string             productTypeString = productTypeEnum.ToStringRepresentation();

            where.WhereEquals("SKUProductType", productTypeString);
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            where.WhereContains("SKUNumber", ProductNumber);
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null);

        if (di != null)
        {
            where.Where(GetColumnWhereCondition("SKUDepartmentID", new WhereCondition().WhereEquals("SKUDepartmentID", di.DepartmentID)));
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null);
        if (mi != null)
        {
            where.Where(GetColumnWhereCondition("SKUManufacturerID", new WhereCondition().WhereEquals("SKUManufacturerID", mi.ManufacturerID)));
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null);
        if (si != null)
        {
            where.Where(GetColumnWhereCondition("SKUSupplierID", new WhereCondition().WhereEquals("SKUSupplierID", si.SupplierID)));
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereTrue("SKUNeedsShipping")));
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereFalse("SKUNeedsShipping").Or().WhereNull("SKUNeedsShipping")));
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where.WhereGreaterOrEquals("SKUPrice", PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where.WhereLessOrEquals("SKUPrice", PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where.Where(GetColumnWhereCondition("SKUPublicStatusID", new WhereCondition().WhereEquals("SKUPublicStatusID", psi.PublicStatusID)));
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where.Where(GetColumnWhereCondition("SKUInternalStatusID", new WhereCondition().WhereEquals("SKUInternalStatusID", isi.InternalStatusID)));
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where.WhereTrue("SKUEnabled");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where.WhereEqualsOrNull("SKUEnabled", false);
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where.WhereLessOrEquals("SKUAvailableItems", value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where.Where(w => w.Where(v => v.WhereNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems", 0))
                        .Or()
                        .Where(z => z.WhereNotNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems".AsColumn(), "SKUReorderAt".AsColumn())));
        }

        return(where);
    }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private string GetWhereCondition()
    {
        string where = "SKUSiteID = " + SiteContext.CurrentSiteID;

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))
        {
            where = "(SKUSiteID = " + SiteContext.CurrentSiteID + ") OR (SKUSiteID IS NULL)";
        }

        // Show/hide product variants - it is based on type of inventory tracking for parent product
        string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation();
        string parentSkuWhere  = "(SKUParentSKUID IS NULL) AND (SKUTrackInventory != '" + trackByVariants + "')";
        string variantWhere    = GetParentProductWhereCondition("SKUTrackInventory = '" + trackByVariants + "'");

        where = SqlHelper.AddWhereCondition(where, string.Format("({0}) OR ({1})", parentSkuWhere, variantWhere));

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUOptionCategoryID IS NULL");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUOptionCategoryID IS NOT NULL");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = Representing.ToEnum <SKUProductTypeEnum>();
            string             productTypeString = productTypeEnum.ToStringRepresentation();

            where = SqlHelper.AddWhereCondition(where, "SKUProductType = N'" + productTypeString + "'");
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            string safeProductNumber = SqlHelper.GetSafeQueryString(ProductNumber, true);
            where = SqlHelper.AddWhereCondition(where, "SKUNumber LIKE N'%" + safeProductNumber + "%'");
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null);

        if (di != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUDepartmentID", "SKUDepartmentID = " + di.DepartmentID));
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null);
        if (mi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUManufacturerID", "SKUManufacturerID = " + mi.ManufacturerID));
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null);
        if (si != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUSupplierID", "SKUSupplierID = " + si.SupplierID));
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUNeedsShipping", "SKUNeedsShipping = 1"));
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUNeedsShipping", "(SKUNeedsShipping = 0) OR (SKUNeedsShipping IS NULL)"));
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "SKUPrice >= " + PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "SKUPrice <= " + PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUPublicStatusID", "SKUPublicStatusID = " + psi.PublicStatusID));
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUInternalStatusID", "SKUInternalStatusID = " + isi.InternalStatusID));
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUEnabled = 1");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where = SqlHelper.AddWhereCondition(where, "(SKUEnabled = 0) OR (SKUEnabled IS NULL)");
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where = SqlHelper.AddWhereCondition(where, "SKUAvailableItems <= " + value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where = SqlHelper.AddWhereCondition(where, "((SKUReorderAt IS NULL) AND (SKUAvailableItems <= 0)) OR ((SKUReorderAt IS NOT NULL) AND (SKUAvailableItems <= SKUReorderAt))");
        }

        return(where);
    }
Exemple #9
0
 private void AddProductTypeOption(string text, SKUProductTypeEnum value)
 {
     AddStringOption(text, SKUInfoProvider.GetSKUProductTypeString(value));
 }
 /// <summary>
 /// Adds item to product type dropdown list.
 /// </summary>
 /// <param name="productTypeName">Product type name resource string</param>
 /// <param name="productType">Product type</param>
 private void AddProductType(string productTypeName, SKUProductTypeEnum productType)
 {
     this.drpProductType.Items.Add(new ListItem(this.GetString(productTypeName), SKUInfoProvider.GetSKUProductTypeString(productType)));
 }
 private void AddProductTypeOption(SKUProductTypeEnum value)
 {
     AddStringOption(value.ToLocalizedString("com.producttype"), value.ToStringRepresentation());
 }
Exemple #12
0
    /// <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);
        }
    }
Exemple #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        editedSiteId = ProductSiteID;

        manufacturerElem.SiteID    = editedSiteId;
        departmentElem.SiteID      = editedSiteId;
        supplierElem.SiteID        = editedSiteId;
        publicStatusElem.SiteID    = editedSiteId;
        internalStatusElem.SiteID  = editedSiteId;
        txtSKUPrice.CurrencySiteID = editedSiteId;

        htmlTemplateBody.AutoDetectLanguage = false;
        htmlTemplateBody.DefaultLanguage    = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlTemplateBody.EditorAreaCSS      = FormHelper.GetHtmlEditorAreaCss(CMSContext.CurrentSiteName);
        htmlTemplateBody.ToolbarSet         = "Basic";

        // Set form groups texts
        this.pnlGeneral.GroupingText    = this.GetString("com.productedit.general");
        this.pnlMembership.GroupingText = this.GetString("com.producttype.membership");
        this.pnlEProduct.GroupingText   = this.GetString("com.producttype.eproduct");
        this.pnlDonation.GroupingText   = this.GetString("com.producttype.donation");
        this.pnlBundle.GroupingText     = this.GetString("com.producttype.bundle");
        this.pnlStatus.GroupingText     = this.GetString("com.productedit.status");
        this.pnlShipping.GroupingText   = this.GetString("com.productedit.shipping");
        this.pnlInventory.GroupingText  = this.GetString("com.productedit.inventory");

        // Set validation messages
        this.txtSKUPrice.ValidationErrorMessage = this.GetString("com.productedit.priceinvalid");
        this.txtSKUPrice.EmptyErrorMessage      = this.GetString("com.productedit.priceinvalid");
        this.txtSKUPrice.ValidatorOnNewLine     = true;
        this.rfvSKUName.ErrorMessage            = this.GetString("com.productedit.nameinvalid");
        this.rvSKUDepth.ErrorMessage            = this.GetString("com.productedit.packagedepthinvalid");
        this.rvSKUHeight.ErrorMessage           = this.GetString("com.productedit.packageheightinvalid");
        this.rvSKUWeight.ErrorMessage           = this.GetString("com.productedit.packageweightinvalid");
        this.rvSKUWidth.ErrorMessage            = this.GetString("com.productedit.packagewidthinvalid");
        this.rvSKUAvailableItems.ErrorMessage   = this.GetString("com.productedit.availableitemsinvalid");
        this.rvSKUAvailableInDays.ErrorMessage  = this.GetString("com.productedit.availabilityinvalid");
        this.rvMaxOrderItems.ErrorMessage       = this.GetString("com.productedit.maxorderitemsinvalid");
        this.pnlConversion.GroupingText         = this.GetString("conversion.conversion.list");

        // Conversion's logging avaible only for site objects
        if (ProductSiteID == 0)
        {
            this.pnlConversion.Visible = false;
        }

        // Get current product info
        SKUInfo skuObj = SKUInfoProvider.GetSKUInfo(mProductId);

        // If product exists
        if (skuObj != null)
        {
            this.editedSiteId = skuObj.SKUSiteID;
            string imagePath = skuObj.SKUImagePath;

            if (String.IsNullOrEmpty(imagePath) || imagePath.ToLower().StartsWith("~/getmetafile/"))
            {
                this.hasAttachmentImagePath = false;
            }

            if (this.OptionCategoryID == 0)
            {
                this.OptionCategoryID = skuObj.SKUOptionCategoryID;
            }

            if (this.OptionCategoryID > 0)
            {
                OptionCategoryInfo optionCat = OptionCategoryInfoProvider.GetOptionCategoryInfo(this.OptionCategoryID);
                if ((optionCat != null) &&
                    ((optionCat.CategorySelectionType == OptionCategorySelectionTypeEnum.TextBox) ||
                     (optionCat.CategorySelectionType == OptionCategorySelectionTypeEnum.TextArea)))
                {
                    this.selectProductTypeElem.AllowBundle          = false;
                    this.selectProductTypeElem.AllowDonation        = false;
                    this.selectProductTypeElem.AllowEproduct        = false;
                    this.selectProductTypeElem.AllowMembership      = false;
                    this.selectProductTypeElem.AllowStandardProduct = false;

                    this.selectProductTypeElem.AllowText = true;
                }
            }

            // Set site IDs
            this.membershipElem.SiteID = skuObj.SKUSiteID;
            this.eProductElem.SiteID   = skuObj.SKUSiteID;
            this.eProductElem.SKUID    = skuObj.SKUID;
            this.donationElem.SiteID   = skuObj.SKUSiteID;
            this.bundleElem.SiteID     = skuObj.SKUSiteID;
            this.bundleElem.BundleID   = skuObj.SKUID;

            if (!RequestHelper.IsPostBack())
            {
                this.LoadData(skuObj);
            }
        }
        else
        {
            if (!RequestHelper.IsPostBack())
            {
                // If creating a product option
                if (this.OptionCategoryID > 0)
                {
                    // Disable specific product type options
                    this.selectProductTypeElem.AllowBundle   = false;
                    this.selectProductTypeElem.AllowDonation = false;
                    this.selectProductTypeElem.Initialize();
                }
            }

            this.hasAttachmentImagePath = false;

            this.membershipElem.SiteID = this.ProductSiteID;
            this.eProductElem.SiteID   = this.ProductSiteID;
            this.eProductElem.SKUID    = this.ProductID;
            this.donationElem.SiteID   = this.ProductSiteID;
            this.bundleElem.SiteID     = this.ProductSiteID;
            this.bundleElem.BundleID   = this.ProductID;
        }

        // Get currently selected product type
        SKUProductTypeEnum selectedProductType = SKUInfoProvider.GetSKUProductTypeEnum((string)this.selectProductTypeElem.Value);

        // Stop processing of e-product properties element if selected product type is not e-product
        this.eProductElem.StopProcessing = (selectedProductType != SKUProductTypeEnum.EProduct);

        // Stop processing of bundle properties element if selected product type is not bundle
        this.bundleElem.StopProcessing = (selectedProductType != SKUProductTypeEnum.Bundle);

        // Enable uploaders if sufficient SKU modify permissions
        if (ECommerceContext.IsUserAuthorizedToModifySKU(editedSiteId == 0))
        {
            this.imgSelect.Enabled  = this.FormEnabled;
            this.ucMetaFile.Enabled = this.FormEnabled;
        }

        CurrentUserInfo cui = CMSContext.CurrentUser;

        if ((cui != null) && (!cui.IsGlobalAdministrator))
        {
            departmentElem.UserID = cui.UserID;
        }

        if (ECommerceSettings.UseMetaFileForProductImage && !hasAttachmentImagePath)
        {
            // Display image uploader for existing product
            this.plcExistingProductImage.Visible = true;
            this.ucMetaFile.ObjectID             = mProductId;
            this.ucMetaFile.ObjectType           = ECommerceObjectType.SKU;
            this.ucMetaFile.Category             = MetaFileInfoProvider.OBJECT_CATEGORY_IMAGE;
            this.ucMetaFile.SiteID         = editedSiteId;
            this.ucMetaFile.OnAfterDelete += new EventHandler(ucMetaFile_OnAfterDelete);
        }
        else
        {
            // Display image uploader for new product
            this.plcNewProductImage.Visible = true;
        }

        // Check presence of main currency
        if (CurrencyInfoProvider.GetMainCurrency(editedSiteId) == null)
        {
            bool usingGlobal = ECommerceSettings.UseGlobalCurrencies(SiteInfoProvider.GetSiteName(editedSiteId));

            if (usingGlobal)
            {
                lblError.Text = GetString("com.noglobalmaincurrency");
            }
            else
            {
                lblError.Text = GetString("com.nomaincurrency");
            }

            lblError.Visible = true;
        }
    }