Esempio n. 1
0
        public HttpResponseMessage IsInCart(int productID)
        {
            try
            {
                int       portalID      = PortalController.Instance.GetCurrentPortalSettings().PortalId;
                StoreInfo storeSettings = StoreController.GetStoreInfo(portalID);
                bool      isInCart      = CurrentCart.ProductIsInCart(portalID, storeSettings.SecureCookie, productID);

                return(Request.CreateResponse(HttpStatusCode.OK, isInCart));
            }
            catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("Unexpected.Error")));
            }
        }
Esempio n. 2
0
        private Control ProcessToken(string tokenName)
        {
            switch (tokenName.ToUpper())
            {
            case "DETAILTITLE":
                if (!_inList)
                {
                    Label lblTitle = new Label
                    {
                        CssClass = "StoreDetailTitle",
                        Text     = Localization.GetString("DetailTitle", LocalResourceFile)
                    };
                    return(lblTitle);
                }

                return(null);

            case "CARTWARNING":
                if (!_inList && _cartWarning && CurrentCart.ProductIsInCart(PortalId, StoreSettings.SecureCookie, _product.ProductID))
                {
                    Label lblWarningMessage = new Label
                    {
                        CssClass = "StoreDetailWarningMessage",
                        Text     = Localization.GetString("WarningMessage", LocalResourceFile)
                    };
                    return(lblWarningMessage);
                }

                return(null);

            case "IMAGE":
                // No control in this case
                if (!_showThumbnail || string.IsNullOrEmpty(_product.ProductImage))
                {
                    return(null);
                }

                Image imgProduct = new Image
                {
                    ImageUrl      = GetImageUrl(_product.ProductImage),
                    AlternateText = Localization.GetString("ImageAlt.Text", LocalResourceFile),
                    CssClass      = "StoreProductImage"
                };

                if (_inList & _showDetail)
                {
                    StringDictionary rplcImage = new StringDictionary
                    {
                        { "ProductID", _product.ProductID.ToString() }
                    };
                    if (StoreSettings.SEOFeature == true)
                    {
                        rplcImage.Add("Product", _product.SEOName);
                    }

                    HyperLink lnkImage = new HyperLink
                    {
                        NavigateUrl = _catalogNav.GetNavigationUrl(_detailID, rplcImage),
                        ToolTip     = SEO(Localization.GetString("LinkDetail", LocalResourceFile), MetaTags.Title),
                        CssClass    = "StoreProductLinkImage"
                    };
                    lnkImage.Controls.Add(imgProduct);
                    return(lnkImage);
                }

                imgProduct.ToolTip = SEO(Localization.GetString("ImageTitle.Text", LocalResourceFile), MetaTags.Title);
                return(imgProduct);

            case "IMAGEURL":
                // No control in this case
                if (string.IsNullOrEmpty(_product.ProductImage))
                {
                    return(null);
                }

                return(new LiteralControl(GetImageUrl(_product.ProductImage)));

            case "IMAGERAWURL":
                // No control in this case
                if (string.IsNullOrEmpty(_product.ProductImage))
                {
                    return(null);
                }

                return(new LiteralControl(_product.ProductImage));

            case "EDIT":
                if (IsEditable)
                {
                    ImageButton imgEdit = new ImageButton
                    {
                        CssClass        = "StoreButtonEdit",
                        CommandArgument = _product.ProductID.ToString()
                    };
                    imgEdit.Click        += btnEdit_Click;
                    imgEdit.ImageUrl      = "~/images/Edit.gif";
                    imgEdit.AlternateText = Localization.GetString("Edit.Text", LocalResourceFile);
                    return(imgEdit);
                }

                return(null);

            case "CATEGORYNAME":
                Label lblProductCategory = new Label
                {
                    Text     = string.Format(Localization.GetString("CategoryName.Text", LocalResourceFile), _category.Name),
                    CssClass = "StoreCategoryName"
                };
                return(lblProductCategory);

            case "MANUFACTURER":
                Label lblManufacturer = new Label
                {
                    Text     = string.Format(Localization.GetString("Manufacturer.Text", LocalResourceFile), _product.Manufacturer),
                    CssClass = "StoreProductManufacturer"
                };
                return(lblManufacturer);

            case "MODELNUMBER":
                Label lblModelNumber = new Label
                {
                    Text     = string.Format(Localization.GetString("ModelNumber.Text", LocalResourceFile), _product.ModelNumber),
                    CssClass = "StoreProductModelNumber"
                };
                return(lblModelNumber);

            case "MODELNAME":
                Label lblModelName = new Label
                {
                    Text     = string.Format(Localization.GetString("ModelName.Text", LocalResourceFile), _product.ModelName),
                    CssClass = "StoreProductModelName"
                };
                return(lblModelName);

            case "TITLE":
                if (_inList & _showDetail)
                {
                    StringDictionary rplcTitle = new StringDictionary
                    {
                        { "ProductID", _product.ProductID.ToString() }
                    };
                    if (StoreSettings.SEOFeature)
                    {
                        rplcTitle.Add("Product", _product.SEOName);
                    }

                    HyperLink lnkTitle = new HyperLink
                    {
                        Text        = _product.ProductTitle,
                        NavigateUrl = _catalogNav.GetNavigationUrl(_detailID, rplcTitle),
                        CssClass    = "CommandButton StoreProductLinkTitle"
                    };
                    return(lnkTitle);
                }

                Label lblProductTitle = new Label
                {
                    Text     = _product.ProductTitle,
                    CssClass = "StoreProductTitle"
                };
                return(lblProductTitle);

            case "LINKDETAIL":
                if (_inList & _showDetail)
                {
                    StringDictionary rplcLink = new StringDictionary
                    {
                        { "ProductID", _product.ProductID.ToString() }
                    };
                    if (StoreSettings.SEOFeature)
                    {
                        rplcLink.Add("Product", _product.SEOName);
                    }

                    HyperLink lnkDetail = new HyperLink
                    {
                        Text        = Localization.GetString("LinkDetail", LocalResourceFile),
                        NavigateUrl = _catalogNav.GetNavigationUrl(_detailID, rplcLink),
                        CssClass    = "CommandButton StoreLinkDetail"
                    };
                    return(lnkDetail);
                }

                return(null);

            case "PRINTDETAIL":
                if (!_inList)
                {
                    string url = _catalogNav.GetNavigationUrl() + "&mid=" + ModuleId + "&SkinSrc=" + Globals.QueryStringEncode("[G]" + SkinController.RootSkin + "/" + Globals.glbHostSkinFolder + "/" + "No Skin") + "&ContainerSrc=" + Globals.QueryStringEncode("[G]" + SkinController.RootContainer + "/" + Globals.glbHostSkinFolder + "/" + "No Container");

                    HyperLink lnkPrintDetail = new HyperLink
                    {
                        Text        = Localization.GetString("PrintDetail", LocalResourceFile),
                        NavigateUrl = url,
                        Target      = "_blank",
                        CssClass    = "CommandButton StorePrintDetail"
                    };
                    return(lnkPrintDetail);
                }

                return(null);

            case "LINKDETAILIMG":
                if (_inList & _showDetail)
                {
                    ImageButton btnLinkDetailImg = new ImageButton
                    {
                        ImageUrl        = GetImagePath("LinkDetailImg"),
                        ToolTip         = Localization.GetString("LinkDetail", LocalResourceFile),
                        CommandArgument = _product.ProductID.ToString()
                    };
                    btnLinkDetailImg.Click   += btnLinkDetailImg_Click;
                    btnLinkDetailImg.CssClass = "StoreLinkDetailImg";
                    return(btnLinkDetailImg);
                }

                return(null);

            case "SUMMARY":
                Label lblSummary = new Label
                {
                    Text     = string.Format(Localization.GetString("Summary.Text", LocalResourceFile), _product.Summary),
                    CssClass = "StoreProductSummary"
                };
                return(lblSummary);

            case "WEIGHT":
                Label lblWeight = new Label
                {
                    Text     = string.Format(Localization.GetString("WeightText", LocalResourceFile), _product.ProductWeight.ToString(Localization.GetString("WeightFormat", LocalResourceFile), _localFormat)),
                    CssClass = "StoreProductWeight"
                };
                return(lblWeight);

            case "HEIGHT":
                Label lblHeight = new Label
                {
                    Text     = string.Format(Localization.GetString("HeightText", LocalResourceFile), _product.ProductHeight.ToString(Localization.GetString("HeightFormat", LocalResourceFile), _localFormat)),
                    CssClass = "StoreProductHeight"
                };
                return(lblHeight);

            case "LENGTH":
                Label lblLength = new Label
                {
                    Text     = string.Format(Localization.GetString("LengthText", LocalResourceFile), _product.ProductLength.ToString(Localization.GetString("LengthFormat", LocalResourceFile), _localFormat)),
                    CssClass = "StoreProductLength"
                };
                return(lblLength);

            case "WIDTH":
                Label lblWidth = new Label
                {
                    Text     = string.Format(Localization.GetString("WidthText", LocalResourceFile), _product.ProductWidth.ToString(Localization.GetString("WidthFormat", LocalResourceFile), _localFormat)),
                    CssClass = "StoreProductWidth"
                };
                return(lblWidth);

            case "SURFACE":
                Label   lblSurface = new Label();
                decimal dblSurface = _product.ProductLength * _product.ProductWidth;
                lblSurface.Text     = string.Format(Localization.GetString("SurfaceText", LocalResourceFile), dblSurface.ToString(Localization.GetString("SurfaceFormat", LocalResourceFile), _localFormat));
                lblSurface.CssClass = "StoreProductSurface";
                return(lblSurface);

            case "VOLUME":
                Label   lblVolume = new Label();
                decimal dblVolume = _product.ProductHeight * _product.ProductLength * _product.ProductWidth;
                lblVolume.Text     = string.Format(Localization.GetString("VolumeText", LocalResourceFile), dblVolume.ToString(Localization.GetString("VolumeFormat", LocalResourceFile), _localFormat));
                lblVolume.CssClass = "StoreProductVolume";
                return(lblVolume);

            case "DIMENSIONS":
                Label  lblDimensions = new Label();
                string strHeight     = _product.ProductHeight.ToString(Localization.GetString("HeightFormat", LocalResourceFile), _localFormat);
                string strLength     = _product.ProductLength.ToString(Localization.GetString("LengthFormat", LocalResourceFile), _localFormat);
                string strWidth      = _product.ProductWidth.ToString(Localization.GetString("WidthFormat", LocalResourceFile), _localFormat);
                lblDimensions.Text     = string.Format(Localization.GetString("DimensionsText", LocalResourceFile), strHeight, strLength, strWidth);
                lblDimensions.CssClass = "StoreProductDimensions";
                return(lblDimensions);

            case "PRICE":
                Label  lblPrice      = new Label();
                string formatedPrice = string.Format(Localization.GetString("Price", LocalResourceFile), _product.UnitCost.ToString("C", _localFormat));
                if (_product.Featured && DateTime.Now > _product.SaleStartDate && DateTime.Now < _product.SaleEndDate)
                {
                    //Product is on sale...
                    string formatedSalePrice = string.Format(Localization.GetString("Price", LocalResourceFile), _product.SalePrice.ToString("C", _localFormat));
                    lblPrice.Text     = string.Format(Localization.GetString("SpecialOffer", LocalResourceFile), formatedPrice, formatedSalePrice);
                    lblPrice.CssClass = "StoreProductPrice StoreProductSpecialOffer";
                }
                else
                {
                    lblPrice.Text     = formatedPrice;
                    lblPrice.CssClass = "StoreProductPrice";
                }
                return(lblPrice);

            case "VATPRICE":
                if (_showTax)
                {
                    Label   lblVATPrice      = new Label();
                    decimal dblVATPrice      = (_product.UnitCost + (_product.UnitCost * (_defaultTaxRate / 100)));
                    string  formatedVATPrice = string.Format(Localization.GetString("VATPrice", LocalResourceFile), dblVATPrice.ToString("C", _localFormat));
                    if (_product.Featured && DateTime.Now > _product.SaleStartDate && DateTime.Now < _product.SaleEndDate)
                    {
                        //Product is on sale...
                        decimal dblVATSalePrice      = (_product.SalePrice + (_product.SalePrice * (_defaultTaxRate / 100)));
                        string  formatedVATSalePrice = string.Format(Localization.GetString("VATPrice", LocalResourceFile), dblVATSalePrice.ToString("C", _localFormat));
                        lblVATPrice.Text     = string.Format(Localization.GetString("SpecialOffer", LocalResourceFile), formatedVATPrice, formatedVATSalePrice);
                        lblVATPrice.CssClass = "StoreProductVATPrice StoreProductSpecialOffer";
                    }
                    else
                    {
                        lblVATPrice.Text     = formatedVATPrice;
                        lblVATPrice.CssClass = "StoreProductVATPrice";
                    }
                    lblVATPrice.CssClass = "StoreProductVATPrice";
                    return(lblVATPrice);
                }

                return(null);

            case "REGULARPRICE":
                Label lblRegularPrice = new Label
                {
                    Text     = string.Format(Localization.GetString("RegularPrice", LocalResourceFile), _product.RegularPrice.ToString("C", _localFormat)),
                    CssClass = "StoreProductRegularPrice"
                };
                return(lblRegularPrice);

            case "REGULARVATPRICE":
                if (_showTax)
                {
                    Label   lblRegularVATPrice = new Label();
                    decimal dblRegularVATPrice = (_product.RegularPrice + (_product.RegularPrice * (_defaultTaxRate / 100)));
                    lblRegularVATPrice.Text     = string.Format(Localization.GetString("RegularVATPrice", LocalResourceFile), dblRegularVATPrice.ToString("C", _localFormat));
                    lblRegularVATPrice.CssClass = "StoreProductRegularVATPrice";
                    return(lblRegularVATPrice);
                }

                return(null);

            case "PURCHASE":
                // Hide control in this case
                if (StoreSettings.InventoryManagement && StoreSettings.ProductsBehavior == (int)Behavior.HideControls && _product.StockQuantity < 1)
                {
                    return(null);
                }

                LinkButton btnPurchase = new LinkButton
                {
                    Text            = Localization.GetString("Purchase", LocalResourceFile),
                    CommandArgument = _product.ProductID.ToString()
                };
                btnPurchase.Click   += btnPurchase_Click;
                btnPurchase.CssClass = "CommandButton StoreButtonPurchase";
                return(btnPurchase);

            case "PURCHASEIMG":
                // Hide control in this case
                if (StoreSettings.InventoryManagement && StoreSettings.ProductsBehavior == (int)Behavior.HideControls & _product.StockQuantity < 1)
                {
                    return(null);
                }

                ImageButton btnPurchaseImg = new ImageButton
                {
                    ImageUrl        = GetImagePath("PurchaseImg"),
                    ToolTip         = Localization.GetString("Purchase", LocalResourceFile),
                    CommandArgument = _product.ProductID.ToString()
                };
                btnPurchaseImg.Click   += btnPurchaseImg_Click;
                btnPurchaseImg.CssClass = "StoreButtonPurchaseImg";
                return(btnPurchaseImg);

            case "ADDTOCART":
                // Hide control in this case
                if (StoreSettings.InventoryManagement && StoreSettings.ProductsBehavior == (int)Behavior.HideControls & _product.StockQuantity < 1)
                {
                    return(null);
                }

                LinkButton btnAddToCart = new LinkButton
                {
                    Text            = Localization.GetString("AddToCart", LocalResourceFile),
                    CommandArgument = _product.ProductID.ToString()
                };
                btnAddToCart.Click   += btnAddToCart_Click;
                btnAddToCart.CssClass = "CommandButton StoreButtonAddToCart";
                return(btnAddToCart);

            case "ADDTOCARTIMG":
                // Hide control in this case
                if (StoreSettings.InventoryManagement && StoreSettings.ProductsBehavior == (int)Behavior.HideControls & _product.StockQuantity < 1)
                {
                    return(null);
                }

                ImageButton btnAddToCartImg = new ImageButton
                {
                    ImageUrl        = GetImagePath("AddToCartImg"),
                    ToolTip         = Localization.GetString("AddToCart", LocalResourceFile),
                    CommandArgument = _product.ProductID.ToString()
                };
                btnAddToCartImg.Click   += btnAddToCartImg_Click;
                btnAddToCartImg.CssClass = "StoreButtonAddToCartImg";
                return(btnAddToCartImg);

            case "ADDQUANTITY":
                // Hide control in this case
                if (StoreSettings.InventoryManagement && StoreSettings.ProductsBehavior == (int)Behavior.HideControls & _product.StockQuantity < 1)
                {
                    return(null);
                }

                Label          lblQuantity     = new Label();
                LiteralControl litQuantity     = new LiteralControl(Localization.GetString("Quantity", LocalResourceFile));
                TextBox        txtAddToCartQty = new TextBox
                {
                    ID       = "txtQuantity" + _product.ProductID,
                    CssClass = "StoreQuantityTextBox",
                    Text     = "1"
                };
                lblQuantity.Controls.Add(litQuantity);
                lblQuantity.Controls.Add(txtAddToCartQty);
                lblQuantity.CssClass = "StoreAddQuantity";
                return(lblQuantity);

            case "DESCRIPTION":
                Panel pnlDescription = new Panel
                {
                    CssClass = "StoreProductDescription"
                };
                Literal litDescription = new Literal
                {
                    Text = System.Web.HttpUtility.HtmlDecode(_product.Description)
                };
                pnlDescription.Controls.Add(litDescription);
                return(pnlDescription);

            case "LOCALE":
                return(new LiteralControl(System.Threading.Thread.CurrentThread.CurrentCulture.ToString()));

            case "TEMPLATESBASEURL":
                return(new LiteralControl(_templatePath));

            case "IMAGESBASEURL":
                return(new LiteralControl(_imagesPath));

            case "PRODUCTDETAILURL":
                if (_showDetail)
                {
                    StringDictionary urlLink = new StringDictionary
                    {
                        { "ProductID", _product.ProductID.ToString() }
                    };
                    if (StoreSettings.SEOFeature)
                    {
                        urlLink.Add("Product", _product.SEOName);
                    }
                    return(new LiteralControl(_catalogNav.GetNavigationUrl(_detailID, urlLink)));
                }

                return(null);

            case "STOCKQUANTITY":
                if (StoreSettings.InventoryManagement)
                {
                    Label lblStockQuantity = new Label();
                    if (_product.StockQuantity > 0)
                    {
                        lblStockQuantity.Text = string.Format(Localization.GetString("StockQuantity", LocalResourceFile), _product.StockQuantity);
                    }
                    else
                    {
                        switch (StoreSettings.OutOfStock)
                        {
                        case (int)StockMessage.Quantity:
                            lblStockQuantity.Text = string.Format(Localization.GetString("StockQuantity", LocalResourceFile), _product.StockQuantity);
                            break;

                        case (int)StockMessage.Unavailable:
                            lblStockQuantity.Text = Localization.GetString("OOStockUnavailable", LocalResourceFile);
                            break;

                        case (int)StockMessage.Restocking:
                            lblStockQuantity.Text = Localization.GetString("OOStockRestocking", LocalResourceFile);
                            break;
                        }
                    }
                    lblStockQuantity.CssClass = "StoreProductStockQuantity";
                    return(lblStockQuantity);
                }

                return(null);

            case "TELLAFRIEND":
                if (!_inList)
                {
                    HyperLink btnTellAFriend = new HyperLink
                    {
                        Text = Localization.GetString("TellAFriend", LocalResourceFile)
                    };
                    string subject = Localization.GetString("TellAFriendSubject", LocalResourceFile);
                    string body    = Localization.GetString("TellAFriendBody", LocalResourceFile);
                    CatalogTokenReplace tkCatalog = new CatalogTokenReplace();
                    _category.StorePageID   = TabId;
                    tkCatalog.Category      = _category;
                    _product.StorePageID    = TabId;
                    tkCatalog.Product       = _product;
                    tkCatalog.StoreSettings = StoreSettings;
                    subject = tkCatalog.ReplaceCatalogTokens(subject);
                    body    = tkCatalog.ReplaceCatalogTokens(body);
                    btnTellAFriend.NavigateUrl = string.Format(Localization.GetString("TellAFriendHRef", LocalResourceFile), subject, System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.UrlPathEncode(body)));
                    btnTellAFriend.CssClass    = "CommandButton StoreButtonTellAFriend";
                    return(btnTellAFriend);
                }

                return(null);

            case "TELLAFRIENDIMG":
                if (!_inList)
                {
                    HyperLink btnTellAFriendImg = new HyperLink
                    {
                        Text = Localization.GetString("TellAFriend", LocalResourceFile)
                    };
                    string subject = Localization.GetString("TellAFriendSubject", LocalResourceFile);
                    string body    = Localization.GetString("TellAFriendBody", LocalResourceFile);
                    CatalogTokenReplace tkCatalog = new CatalogTokenReplace();
                    _category.StorePageID   = TabId;
                    tkCatalog.Category      = _category;
                    _product.StorePageID    = TabId;
                    tkCatalog.Product       = _product;
                    tkCatalog.StoreSettings = StoreSettings;
                    subject = tkCatalog.ReplaceCatalogTokens(subject);
                    body    = tkCatalog.ReplaceCatalogTokens(body);
                    btnTellAFriendImg.NavigateUrl = string.Format(Localization.GetString("TellAFriendHRef", LocalResourceFile), subject, System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.UrlPathEncode(body)));
                    btnTellAFriendImg.CssClass    = "CommandButton StoreButtonTellAFriend";
                    HtmlImage imgButton = new HtmlImage
                    {
                        Src = GetImagePath("TellAFriendImg"),
                        Alt = Localization.GetString("TellAFriend", this.LocalResourceFile)
                    };
                    btnTellAFriendImg.Controls.Add(imgButton);
                    return(btnTellAFriendImg);
                }

                return(null);

            default:
                LiteralControl litText = new LiteralControl(tokenName);
                return(litText);
            }
        }