using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Data; using CMS.Ecommerce; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.SiteProvider; namespace CMS.Controls { /// /// SKU transformation methods /// public partial class CMSTransformation { #region "Variables" SKUInfo mSKU = null; #endregion #region "Properties" /// /// SKU data loaded from the current data row /// public SKUInfo SKU { get { if (mSKU == null) { // Get SKU object DataRow row = (DataRowView != null) ? DataRowView.Row : null; if (row != null) { #region "Smart search data row" // Try get data row value from search result DataColumnCollection col = row.Table.Columns; if (col.Contains("id") && (col.Contains("score"))) { // try get value string id = ValidationHelper.GetString(Eval("id"), String.Empty); if (!String.IsNullOrEmpty(id)) { // Try get data row Hashtable resultRows = RequestStockHelper.GetItem(SearchHelper.RESULTS_KEY) as Hashtable; if (resultRows != null) { row = resultRows[id] as DataRow; } } } #endregion mSKU = new SKUInfo(row); } } return mSKU; } } /// /// Indicates if product prices are displayed including discounts /// public bool PriceIncludingDiscounts { get { return ECommerceSettings.DisplayPriceIncludingDiscounts(CMSContext.CurrentSiteName); } } /// /// Indicates if product prices are displayed including taxes /// public bool PriceIncludingTaxes { get { return ECommerceSettings.DisplayPriceIncludingTaxes(CMSContext.CurrentSiteName); } } #endregion #region "SKU price" /// /// Returns SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included optionally. /// /// True - catalogue discounts are applied to the price /// True - catalogue taxes are applied to the discounted price /// SKU column from which the price should be returned. If empty, SKUPrice column is used. public double GetSKUPrice(bool discounts, bool taxes, string column) { return ApplyExchangeRate(SKUInfoProvider.GetSKUPrice(SKU, null, discounts, taxes, false, column)); } /// /// Returns SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included optionally. /// /// True - catalogue discounts are applied to the price /// True - catalogue taxes are applied to the discounted price public double GetSKUPrice(bool discounts, bool taxes) { return GetSKUPrice(discounts, taxes, null); } /// /// Returns SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included based on the site settings. /// /// SKU column from which the price should be returned. If empty, SKUPrice column is used. public double GetSKUPrice(string column) { return GetSKUPrice(PriceIncludingDiscounts, PriceIncludingTaxes, column); } /// /// Returns SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included based on the site settings. /// public double GetSKUPrice() { return GetSKUPrice(PriceIncludingDiscounts, PriceIncludingTaxes, null); } /// /// Returns formatted SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included optionally. /// /// True - catalogue discounts are applied to the price /// True - catalogue taxes are applied to the discounted price /// SKU column from which the price should be returned. If empty, SKUPrice column is used. public string GetSKUFormattedPrice(bool discounts, bool taxes, string column) { return SKUInfoProvider.GetSKUFormattedPrice(SKU, null, discounts, taxes, column); } /// /// Returns formatted SKU catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included optionally. /// /// True - catalogue discounts are applied to the price /// True - catalogue taxes are applied to the discounted price public string GetSKUFormattedPrice(bool discounts, bool taxes) { return GetSKUFormattedPrice(discounts, taxes, null); } /// /// Returns formatted product catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included based on the site settings. /// /// SKU column from which the price should be returned. If empty, SKUPrice column is used. public string GetSKUFormattedPrice(string column) { return GetSKUFormattedPrice(PriceIncludingDiscounts, PriceIncludingTaxes, column); } /// /// Returns formatted product catalogue price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts and/or taxes are included based on the site settings. /// public string GetSKUFormattedPrice() { return GetSKUFormattedPrice(null); } #endregion #region "SKU list price" /// /// Returns SKU list price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts are not included, taxes are included based on the site settings. /// public double GetSKUListPrice() { return GetSKUListPrice(PriceIncludingTaxes); } /// /// Returns SKU list price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts are not included, taxes are included optionally. /// public double GetSKUListPrice(bool taxes) { return GetSKUPrice(false, taxes, "SKURetailPrice"); } /// /// Returns formatted SKU list price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts are not included, taxes are included based on the site settings. /// public string GetSKUFormattedListPrice() { return GetSKUFormattedListPrice(PriceIncludingTaxes); } /// /// Returns formatted SKU list price based on the SKU data and the data of the current shopping cart. /// Catalogue discounts are not included, taxes are included optionally. /// /// True - catalogue taxes are applied to the list price public string GetSKUFormattedListPrice(bool taxes) { return GetSKUFormattedPrice(false, taxes, "SKURetailPrice"); } #endregion #region "SKU price saving" /// /// Returns amount of saved money based on the difference between product seller price and product list price. /// /// Indicates if discounts should be applied to the seller price before the saved amount is calculated /// Indicates if taxes should be applied to both list price and seller price before the saved amount is calculated /// Name of the column from which the seller price is retrieved, if empty SKUPrice column is used /// Name of the column from which the list price is retrieved, if empty SKURetailPrice column is used /// True - result is percentage, False - result is in the current currency public double GetSKUPriceSaving(bool discounts, bool taxes, string column1, string column2, bool percentage) { return EcommerceFunctions.GetSKUPriceSaving(SKU, discounts, taxes, column1, column2, percentage); } /// /// Returns amount of saved money based on the difference between product seller price and product list price. /// /// Indicates if discounts should be applied to the seller price before the saved amount is calculated /// Indicates if taxes should be applied to both list price and seller price before the saved amount is calculated /// True - result is percentage, False - result is in the current currency public double GetSKUPriceSaving(bool discounts, bool taxes, bool percentage) { return GetSKUPriceSaving(discounts, taxes, null, null, percentage); } /// /// Returns amount of saved money based on the difference between product seller price and product list price. /// Catalogue discounts and/or taxes are included based on the site settings. /// /// Name of the column from which the seller price is retrieved, if empty SKUPrice column is used /// Name of the column from which the list price is retrieved, if empty SKURetailPrice column is used /// True - result is percentage, False - result is in the current currency public double GetSKUPriceSaving(string column1, string column2, bool percentage) { return GetSKUPriceSaving(PriceIncludingDiscounts, PriceIncludingTaxes, column1, column2, percentage); } /// /// Returns amount of saved money based on the difference between product seller price and product list price. /// Catalogue discounts and/or taxes are included based on the site settings. /// /// True - result is percentage, False - result is in the current currency public double GetSKUPriceSaving(bool percentage) { return GetSKUPriceSaving(null, null, percentage); } /// /// Returns formatted string representing amount of saved money based on the difference between product seller price and product list price. /// /// Indicates if discounts should be applied to the seller price before the saved amount is calculated /// Indicates if taxes should be applied to both list price and seller price before the saved amount is calculated /// Name of the column from which the seller price is retrieved, if empty SKUPrice column is used /// Name of the column from which the list price is retrieved, if empty SKURetailPrice column is used public string GetSKUFormattedPriceSaving(bool discounts, bool taxes, string column1, string column2) { return FormatPrice(GetSKUPriceSaving(discounts, taxes, column1, column2, false)); } /// /// Returns formatted string representing amount of saved money based on the difference between product seller price and product list price. /// /// Indicates if discounts should be applied to the seller price before the saved amount is calculated /// Indicates if taxes should be applied to both list price and seller price before the saved amount is calculated public string GetSKUFormattedPriceSaving(bool discounts, bool taxes) { return GetSKUFormattedPriceSaving(discounts, taxes, null, null); } /// /// Returns formatted string representing amount of saved money based on the difference between product seller price and product list price. /// Catalogue discounts and/or taxes are included based on the site settings. /// /// Name of the column from which the seller price is retrieved, if empty SKUPrice column is used /// Name of the column from which the list price is retrieved, if empty SKURetailPrice column is used public string GetSKUFormattedPriceSaving(string column1, string column2) { return GetSKUFormattedPriceSaving(PriceIncludingDiscounts, PriceIncludingTaxes, column1, column2); } /// /// Returns formatted string representing amount of saved money based on the difference between product seller price and product list price. /// Catalogue discounts and/or taxes are included based on the site settings. /// public string GetSKUFormattedPriceSaving() { return GetSKUFormattedPriceSaving(null, null); } #endregion #region "SKU price formatting" /// /// Applies current exchange rate to the given price and returns the result. /// /// Price in site main currency the current exchange rate should be applied to public double ApplyExchangeRate(double price) { return ECommerceContext.CurrentShoppingCart.ApplyExchangeRate(price); } /// /// Returns price rounded and formatted according to the current currency properties. /// /// Price to be formatted /// True - price is rounded according to the current currency settings before formatting public string FormatPrice(double price, bool round) { return ECommerceContext.CurrentShoppingCart.GetFormattedPrice(price, round); } /// /// Returns price rounded and formatted according to the current currency properties. /// /// Price to be formatted public string FormatPrice(double price) { return FormatPrice(price, true); } #endregion #region "SKU properties" /// /// Returns value of the specified product public status column. /// If the product is evaluated as a new product in the store, public status set by 'CMSStoreNewProductStatus' setting is used, otherwise product public status is used. /// /// Name of the product public status column the value should be retrieved from public object GetSKUIndicatorProperty(string column) { return EcommerceFunctions.GetSKUIndicatorProperty(SKU, column); } /// /// Indicates if the given SKU can be bought by the customer based on the SKU inventory properties. /// public bool IsSKUAvailableForSale() { return SKUInfoProvider.IsSKUAvailableForSale(SKU); } #endregion #region "SKU URLs" /// /// Returns SKU permanent URL. /// public string GetSKUUrl() { return EcommerceFunctions.GetProductUrl(Eval("SKUGuid"), EvalText("SKUName", true)); } /// /// Returns SKU image URL including dimension's modifiers (width, height) and site name parameter if product is from different site than current. /// If image URL is not specified, SKU default image URL is used. /// /// Image requested width /// Image requested height public string GetSKUImageUrl(int width, int height) { return EcommerceFunctions.GetSKUImageUrl(Eval("SKUImagePath"), width, height, 0, Eval("SKUSiteID")); } /// /// Returns SKU image URL including dimension's modifiers (width, height) and site name parameter if product is from different site than current. /// If image URL is not specified, SKU default image URL is used. /// /// Image requested maximum side size public string GetSKUImageUrl(int maxSideSize) { return EcommerceFunctions.GetSKUImageUrl(Eval("SKUImagePath"), 0, 0, maxSideSize, Eval("SKUSiteID")); } #endregion } }