Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            base.Initialize(context);

            if (!UserCanEditModule(ModuleId, Store.FeatureGuid))
            {
                log.Info("User has no edit permission so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentSite == null)
            {
                log.Info("CurrentSite is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentUser == null)
            {
                log.Info("CurrentUser is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (FileSystem == null)
            {
                log.Info("FileSystem is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count == 0)
            {
                log.Info("Posted File Count is zero so returning 404");
                Response.StatusCode = 404;
                return;
            }

            productGuid = WebUtils.ParseGuidFromQueryString("prod", productGuid);

            if (productGuid == Guid.Empty)
            {
                log.Info("No productGuid provided so returning 404");
                Response.StatusCode = 404;
                return;
            }

            module = GetModule(ModuleId, Store.FeatureGuid);

            if (module == null)
            {
                log.Info("Module is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            string type = "product";
            if (Request.Params["type"] != null)
            {
                type = Request.Params["type"];
            }

            HttpPostedFile file = Request.Files[0];  // only expecting 1 file

            context.Response.ContentType = "text/plain";//"application/json";
            var r = new System.Collections.Generic.List<UploadFilesResult>();
            JavaScriptSerializer js = new JavaScriptSerializer();

            if (type == "product")
            {
                //product file
                string upLoadPath = "~/Data/Sites/" + CurrentSite.SiteId.ToInvariantString()
                + "/webstoreproductfiles/";

               ProductFile productFile = new ProductFile(productGuid);
                productFile.FileName = Path.GetFileName(file.FileName);
                productFile.ByteLength = file.ContentLength;
                productFile.Created = DateTime.UtcNow;
                productFile.CreatedBy = CurrentUser.UserGuid;
                productFile.ServerFileName = productGuid.ToString() + ".config";

                string ext = System.IO.Path.GetExtension(file.FileName);
                string mimeType = IOHelper.GetMimeType(ext).ToLower();

                if (productFile.Save())
                {
                    string destPath = upLoadPath + productFile.ServerFileName;
                    FileSystem.DeleteFile(destPath);

                    using (Stream s = file.InputStream)
                    {
                        FileSystem.SaveFile(destPath, s, mimeType, true);
                    }

                    r.Add(new UploadFilesResult()
                    {
                        //Thumbnail_url =
                        Name = file.FileName,
                        Length = file.ContentLength,
                        Type = mimeType
                    });
                }

            }
            else
            {
                // teaser file
                string upLoadPath = "~/Data/Sites/" + CurrentSite.SiteId.ToInvariantString()
                   + "/webstoreproductpreviewfiles/";

                Product product = new Product(productGuid);
                product.TeaserFile = Path.GetFileName(file.FileName).ToCleanFileName();

                string ext = System.IO.Path.GetExtension(file.FileName);
                string mimeType = IOHelper.GetMimeType(ext).ToLower();

                if (product.Save())
                {
                    string destPath = upLoadPath + product.TeaserFile;
                    FileSystem.DeleteFile(destPath);

                    using (Stream s = file.InputStream)
                    {
                        FileSystem.SaveFile(destPath, s, mimeType, true);
                    }

                    r.Add(new UploadFilesResult()
                    {
                        //Thumbnail_url =
                        Name = file.FileName,
                        Length = file.ContentLength,
                        Type = mimeType
                    });
                }

            }

            var uploadedFiles = new
            {
                files = r.ToArray()
            };

            var jsonObj = js.Serialize(uploadedFiles);
            context.Response.Write(jsonObj.ToString());
        }
        private static void IndexItem(Product product)
        {
            if (WebConfigSettings.DisableSearchIndex) { return; }
            if (product == null)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("product object passed to ProductSearchIndexBuilder.IndexItem was null");
                }
                return;
            }

            Store store = new Store(product.StoreGuid);

            Module module = new Module(store.ModuleId);
            Guid webStoreFeatureGuid = new Guid("0cefbf18-56de-11dc-8f36-bac755d89593");
            ModuleDefinition webStoreFeature = new ModuleDefinition(webStoreFeatureGuid);

            //// get list of pages where this module is published
            List<PageModule> pageModules
                = PageModule.GetPageModulesByModule(store.ModuleId);

            foreach (PageModule pageModule in pageModules)
            {
                PageSettings pageSettings
                    = new PageSettings(
                    product.SiteId,
                    pageModule.PageId);

                //don't index pending/unpublished pages
                if (pageSettings.IsPending) { continue; }

                mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem();
                if (product.SearchIndexPath.Length > 0)
                {
                    indexItem.IndexPath = product.SearchIndexPath;
                }
                indexItem.SiteId = product.SiteId;
                indexItem.PageId = pageSettings.PageId;
                indexItem.PageName = pageSettings.PageName;
                indexItem.ViewRoles = pageSettings.AuthorizedRoles;
                indexItem.ModuleViewRoles = module.ViewRoles;
                if (product.Url.Length > 0)
                {
                    indexItem.ViewPage = product.Url.Replace("~/", string.Empty);
                    indexItem.UseQueryStringParams = false;
                }
                else
                {
                    indexItem.ViewPage = "/WebStore/ProductDetail.aspx";
                }
                indexItem.ItemKey = product.Guid.ToString();
                indexItem.ModuleId = store.ModuleId;
                indexItem.ModuleTitle = module.ModuleTitle;
                indexItem.Title = product.Name;
                indexItem.PageMetaDescription = product.MetaDescription;
                indexItem.PageMetaKeywords = product.MetaKeywords;

                indexItem.CreatedUtc = product.Created;
                indexItem.LastModUtc = product.LastModified;

                indexItem.Content
                    = product.Teaser
                    + " " + product.Description.Replace(tabScript, string.Empty)
                    + " " + product.MetaDescription
                    + " " + product.MetaKeywords;

                indexItem.FeatureId = webStoreFeatureGuid.ToString();
                indexItem.FeatureName = webStoreFeature.FeatureName;
                indexItem.FeatureResourceFile = webStoreFeature.ResourceFile;
                indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                indexItem.PublishEndDate = pageModule.PublishEndDate;

                mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem);
            }

            if (debugLog) log.Debug("Indexed " + product.Name);
        }
Example #3
0
        public static bool Delete(
            Guid productGuid, 
            Guid userGuid, 
            string userIPAddress)
        {
            Product product = new Product(productGuid);
            if (
                (product.Guid == productGuid)
                &&(productGuid != Guid.Empty)
                )
            {
                DBProduct.AddHistory(
                    Guid.NewGuid(),
                    product.Guid,
                    product.StoreGuid,
                    product.TaxClassGuid,
                    product.Sku,
                    ConvertProductStatusToByte(product.Status),
                    ConvertFulfillmentTypeToByte(product.FulfillmentType),
                    product.Weight,
                    product.QuantityOnHand,
                    product.ImageFileName,
                    product.ImageFileBytes,
                    product.Created,
                    product.CreatedBy,
                    product.LastModified,
                    product.LastModifedBy,
                    DateTime.UtcNow,
                    product.shippingAmount);

                OfferProduct.DeleteByProduct(
                    productGuid,
                    userGuid,
                    userIPAddress);
            }

            return DBProduct.Delete(
                productGuid,
                DateTime.UtcNow,
                userGuid,
                userIPAddress);
        }
Example #4
0
        private bool Update()
        {
            Product product = new Product(this.guid);
            DBProduct.AddHistory(
                Guid.NewGuid(),
                product.Guid,
                product.StoreGuid,
                product.TaxClassGuid,
                string.Empty,
                ConvertProductStatusToByte(product.Status),
                ConvertFulfillmentTypeToByte(product.FulfillmentType),
                product.Weight,
                product.QuantityOnHand,
                product.ImageFileName,
                product.ImageFileBytes,
                product.Created,
                product.CreatedBy,
                product.LastModified,
                product.LastModifedBy,
                DateTime.UtcNow,
                product.shippingAmount);

            bool result = DBProduct.Update(
                this.guid,
                this.taxClassGuid,
                this.modelNumber,
                this.status,
                this.fulfillmentType,
                this.weight,
                this.quantityOnHand,
                this.imageFileName,
                this.imageFileBytes,
                this.lastModified,
                this.lastModifedBy,
                this.url,
                this.name,
                this.description,
                this.teaser,
                this.showInProductList,
                this.enableRating,
                this.metaDescription,
                this.metaKeywords,
                this.sortRank1,
                this.sortRank2,
                this.teaserFile,
                this.teaserFileLink,
                this.compiledMeta,
                this.shippingAmount);

            if (result)
            {
                ContentChangedEventArgs e = new ContentChangedEventArgs();
                OnContentChanged(e);
            }

            return result;
        }
Example #5
0
        //public decimal CalculateItemTax(
        //    Guid siteGuid,
        //    Guid taxZoneGuid,
        //    Guid taxClassGuid,
        //    decimal itemPrice,
        //    int quantity)
        //{
        //    decimal taxAmount = 0;
        //    if (taxZoneGuid == Guid.Empty) { return taxAmount; }
        //    if (taxClassGuid == Guid.Empty) { return taxAmount; }
        //    if (itemPrice == 0) { return taxAmount; }
        //    Collection<TaxRate> taxRates = TaxRate.GetTaxRates(siteGuid, taxZoneGuid);
        //    if (taxRates.Count > 0)
        //    {
        //        foreach (TaxRate taxRate in taxRates)
        //        {
        //            if (taxClassGuid == taxRate.TaxClassGuid)
        //            {
        //                taxAmount += (taxRate.Rate * (itemPrice * quantity));
        //                break;
        //            }
        //        }
        //    }
        //    return taxAmount;
        //}
        public void CalculateShipping(Cart cart)
        {
            decimal shippingAmount = 0;

            foreach (CartOffer offer in cart.CartOffers)
            {
                Collection<OfferProduct> offerProducts = OfferProduct.GetbyOffer(offer.OfferGuid);

                if (offerProducts != null)
                {
                    foreach (OfferProduct offerProduct in offerProducts)
                    {
                        Product product = new Product(offerProduct.ProductGuid);
                        if (product != null)
                        {
                            shippingAmount += (product.ShippingAmount * offer.Quantity);
                        }
                    }
                }
            }

            cart.ShippingTotal = Math.Round(shippingAmount, this.RoundingDecimalPlaces, this.RoundingMode);
            cart.Save();
        }