private static List <FullfillDownloadTerms> LoadListFromReader(IDataReader reader)
        {
            List <FullfillDownloadTerms> fullfillDownloadTermList = new List <FullfillDownloadTerms>();

            try
            {
                while (reader.Read())
                {
                    FullfillDownloadTerms fullfillDownloadTerm = new FullfillDownloadTerms();
                    fullfillDownloadTerm.guid                     = new Guid(reader["Guid"].ToString());
                    fullfillDownloadTerm.storeGuid                = new Guid(reader["StoreGuid"].ToString());
                    fullfillDownloadTerm.downloadsAllowed         = Convert.ToInt32(reader["DownloadsAllowed"]);
                    fullfillDownloadTerm.expireAfterDays          = Convert.ToInt32(reader["ExpireAfterDays"]);
                    fullfillDownloadTerm.countAfterDownload       = Convert.ToBoolean(reader["CountAfterDownload"]);
                    fullfillDownloadTerm.created                  = Convert.ToDateTime(reader["Created"]);
                    fullfillDownloadTerm.createdBy                = new Guid(reader["CreatedBy"].ToString());
                    fullfillDownloadTerm.createdFromIP            = reader["CreatedFromIP"].ToString();
                    fullfillDownloadTerm.lastModified             = Convert.ToDateTime(reader["LastModified"]);
                    fullfillDownloadTerm.lastModifedBy            = new Guid(reader["LastModifedBy"].ToString());
                    fullfillDownloadTerm.lastModifedFromIPAddress = reader["LastModifedFromIPAddress"].ToString();
                    fullfillDownloadTermList.Add(fullfillDownloadTerm);

                    fullfillDownloadTerm.Description = reader["Description"].ToString();
                    fullfillDownloadTerm.name        = reader["Name"].ToString();
                }
            }
            finally
            {
                reader.Close();
            }

            return(fullfillDownloadTermList);
        }
        private void grdFullfillDownloadTerms_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (store == null) { return; }

            GridView grid = (GridView)sender;
            Guid guid = (Guid)grid.DataKeys[e.RowIndex].Value;
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            TextBox txtName = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtName");
            TextBox txtDescription = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtDescription");
            TextBox txtDownloadsAllowed = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtDownloadsAllowed");
            TextBox txtExpireAfterDays = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtExpireAfterDays");
            CheckBox chkCountAfterDownload = (CheckBox)grid.Rows[e.RowIndex].Cells[1].FindControl("chkCountAfterDownload");

            FullfillDownloadTerms fullfillDownloadTerms;
            if (guid != Guid.Empty)
            {
                fullfillDownloadTerms = new FullfillDownloadTerms(guid);
            }
            else
            {
                fullfillDownloadTerms = new FullfillDownloadTerms();
                fullfillDownloadTerms.Created = DateTime.UtcNow;
                fullfillDownloadTerms.CreatedBy = siteUser.UserGuid;
                fullfillDownloadTerms.CreatedFromIP = SiteUtils.GetIP4Address();
            }

            fullfillDownloadTerms.StoreGuid = store.Guid;
            fullfillDownloadTerms.Name = txtName.Text;
            fullfillDownloadTerms.Description = txtDescription.Text;

            int downloadsAllowed;
            if (!int.TryParse(txtDownloadsAllowed.Text, out downloadsAllowed))
            {
                downloadsAllowed = 0;
            }
            fullfillDownloadTerms.DownloadsAllowed = downloadsAllowed;

            int expireAfterDays;
            if (!int.TryParse(txtExpireAfterDays.Text, out expireAfterDays))
            {
                expireAfterDays = 0;
            }
            fullfillDownloadTerms.ExpireAfterDays = expireAfterDays;

            fullfillDownloadTerms.CountAfterDownload = chkCountAfterDownload.Checked;
            fullfillDownloadTerms.LastModified = DateTime.UtcNow;
            fullfillDownloadTerms.LastModifedBy = siteUser.UserGuid;
            fullfillDownloadTerms.LastModifedFromIPAddress = SiteUtils.GetIP4Address();
            fullfillDownloadTerms.Save();

            WebUtils.SetupRedirect(this, GetRefreshUrl());
        }
Exemplo n.º 3
0
        public static Order CreateOrder(
            Store store,
            Cart cart, 
            string gatewayRawResponse,
            string gatewayTransactionId,
            string gatewayApprovalCode,
            string currencyCode,
            string paymentMethod,
            Guid orderStatusGuid)
        {
            Order order = new Order(cart.CartGuid);

            order.billingAddress1 = cart.OrderInfo.BillingAddress1;
            order.billingAddress2 = cart.OrderInfo.BillingAddress2;
            order.billingCity = cart.OrderInfo.BillingCity;
            order.billingCompany = cart.OrderInfo.BillingCompany;
            order.billingCountry = cart.OrderInfo.BillingCountry;
            order.billingFirstName = cart.OrderInfo.BillingFirstName;
            order.billingLastName = cart.OrderInfo.BillingLastName;
            order.billingPostalCode = cart.OrderInfo.BillingPostalCode;
            order.billingState = cart.OrderInfo.BillingState;
            order.billingSuburb = cart.OrderInfo.BillingSuburb;

            order.completed = cart.OrderInfo.Completed;
            order.completedFromIP = cart.OrderInfo.CompletedFromIP;
            order.created = DateTime.UtcNow;
            order.createdFromIP = cart.OrderInfo.CompletedFromIP;

            order.customerAddressLine1 = cart.OrderInfo.CustomerAddressLine1;
            order.customerAddressLine2 = cart.OrderInfo.CustomerAddressLine2;
            order.customerCity = cart.OrderInfo.CustomerCity;
            order.customerCompany = cart.OrderInfo.CustomerCompany;
            order.customerCountry = cart.OrderInfo.CustomerCountry;
            order.customerEmail = cart.OrderInfo.CustomerEmail;
            order.customerEmailVerified = cart.OrderInfo.CustomerEmailVerified;
            order.customerFirstName = cart.OrderInfo.CustomerFirstName;
            order.customerLastName = cart.OrderInfo.CustomerLastName;
            order.customerPostalCode = cart.OrderInfo.CustomerPostalCode;
            order.customerState = cart.OrderInfo.CustomerState;
            order.customerSuburb = cart.OrderInfo.CustomerSuburb;
            order.customerTelephoneDay = cart.OrderInfo.CustomerTelephoneDay;
            order.customerTelephoneNight = cart.OrderInfo.CustomerTelephoneNight;

            order.deliveryAddress1 = cart.OrderInfo.DeliveryAddress1;
            order.deliveryAddress2 = cart.OrderInfo.DeliveryAddress2;
            order.deliveryCity = cart.OrderInfo.DeliveryCity;
            order.deliveryCompany = cart.OrderInfo.DeliveryCompany;
            order.deliveryCountry = cart.OrderInfo.DeliveryCountry;
            order.deliveryFirstName = cart.OrderInfo.DeliveryFirstName;
            order.deliveryLastName = cart.OrderInfo.DeliveryLastName;
            order.deliveryPostalCode = cart.OrderInfo.DeliveryPostalCode;
            order.deliveryState = cart.OrderInfo.DeliveryState;
            order.deliverySuburb = cart.OrderInfo.DeliverySuburb;

            order.gatewayAuthCode = gatewayApprovalCode;
            order.gatewayRawResponse = gatewayRawResponse;
            order.gatewayTransID = gatewayTransactionId;

            order.lastModified = DateTime.UtcNow;
            order.lastUserActivity = cart.LastUserActivity;

            order.orderGuid = cart.CartGuid;

            order.OrderTotal = cart.OrderTotal;
            order.statusGuid = orderStatusGuid;

            order.storeGuid = cart.StoreGuid;
            order.clerkGuid = cart.ClerkGuid;
            order.subTotal = cart.SubTotal;
            order.taxTotal = cart.TaxTotal;
            order.discount = cart.Discount;
            order.shippingTotal = cart.ShippingTotal;
            order.taxZoneGuid = cart.OrderInfo.TaxZoneGuid;
            order.userGuid = cart.UserGuid;
            order.discountCodesCsv = cart.DiscountCodesCsv;
            order.customData = cart.CustomData;

            order.Save();

            // TODO: need to add this in insert so we don't have to save 2x
            order.paymentMethod = paymentMethod;
            order.Save();

            foreach (CartOffer cartOffer in cart.CartOffers)
            {
                OrderOffer orderOffer = new OrderOffer();
                orderOffer.AddedToCart = cartOffer.AddedToCart;
                //orderOffer.CurrencyGuid = cartOffer.CurrencyGuid;
                orderOffer.OfferGuid = cartOffer.OfferGuid;
                orderOffer.OfferPrice = cartOffer.OfferPrice;
                orderOffer.OrderGuid = order.OrderGuid;
                //orderOffer.PriceGuid = cartOffer.PriceGuid;
                orderOffer.Quantity = cartOffer.Quantity;
                orderOffer.TaxClassGuid = cartOffer.TaxClassGuid;
                orderOffer.Save();

                Collection<OfferProduct> offerProducts
                    = OfferProduct.GetbyOffer(orderOffer.OfferGuid);

                foreach (OfferProduct offerProduct in offerProducts)
                {
                    OrderOfferProduct orderProduct = new OrderOfferProduct();
                    orderProduct.Created = DateTime.UtcNow;
                    orderProduct.FullfillTermsGuid = offerProduct.FullFillTermsGuid;
                    orderProduct.FullfillType = offerProduct.FullfillType;
                    orderProduct.OfferGuid = offerProduct.OfferGuid;
                    orderProduct.OrderGuid = order.OrderGuid;
                    orderProduct.ProductGuid = offerProduct.ProductGuid;
                    orderProduct.Save();

                    if (
                        (offerProduct.FullfillType
                        == (byte)FulfillmentType.Download)
                        && (offerProduct.FullFillTermsGuid != Guid.Empty)
                        )
                    {
                        // create download fullfillment ticket
                        FullfillDownloadTerms downloadTerms
                            = new FullfillDownloadTerms(offerProduct.FullFillTermsGuid);

                        FullfillDownloadTicket downloadTicket = new FullfillDownloadTicket();
                        downloadTicket.CountAfterDownload = downloadTerms.CountAfterDownload;
                        downloadTicket.DownloadsAllowed = downloadTerms.DownloadsAllowed;
                        downloadTicket.ExpireAfterDays = downloadTerms.ExpireAfterDays;
                        downloadTicket.FullfillTermsGuid = offerProduct.FullFillTermsGuid;
                        downloadTicket.OrderGuid = order.OrderGuid;
                        downloadTicket.ProductGuid = offerProduct.ProductGuid;
                        downloadTicket.PurchaseTime = order.Completed;
                        downloadTicket.StoreGuid = order.StoreGuid;
                        downloadTicket.UserGuid = order.UserGuid;
                        downloadTicket.Save();

                    }
                }

            }

            if (order.DiscountCodesCsv.Length > 0)
            {
                List<WebStore.Business.Discount> discountList = WebStore.Business.Discount.GetValidDiscounts(store.ModuleGuid, cart, cart.DiscountCodesCsv);
                foreach (WebStore.Business.Discount d in discountList)
                {
                    d.UseCount += 1;
                    d.Save();
                    // TODO: Discount log

                }
            }

            Cart.Delete(cart.CartGuid);

            return order;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate("webstore");
            if ((Page.IsValid)&&(store != null))
            {

                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

                if (store.SiteGuid == Guid.Empty)
                {
                    store.SiteGuid = siteSettings.SiteGuid;
                }
                if (store.ModuleId == -1)
                {
                    store.ModuleId = moduleId;
                }

                Module module = new Module(moduleId);
                module.ModuleTitle = txtName.Text;
                module.Save();

                store.Name = txtName.Text;
                store.Description = edDescription.Text;
                store.OwnerName = txtOwnerName.Text;
                store.OwnerEmail = txtOwnerEmail.Text;
                store.SalesEmail = txtSalesEmail.Text;
                store.SupportEmail = txtSupportEmail.Text;
                store.EmailFrom = txtEmailFrom.Text;
                store.OrderBccEmail = txtOrderBCCEmail.Text;
                store.Phone = txtPhone.Text;
                store.Fax = txtFax.Text;
                store.Address = txtAddress.Text;
                store.City = txtCity.Text;

                if (!String.IsNullOrEmpty(ddZoneGuid.SelectedValue))
                {
                    store.ZoneGuid = new Guid(ddZoneGuid.SelectedValue);
                }

                store.PostalCode = txtPostalCode.Text;

                if (!String.IsNullOrEmpty(ddCountryGuid.SelectedValue))
                {
                    store.CountryGuid = new Guid(ddCountryGuid.SelectedValue);
                }

                store.IsClosed = chkIsClosed.Checked;
                store.ClosedMessage = edClosedMessage.Text;

                if (store.Guid == Guid.Empty)
                {
                    store.Created = DateTime.UtcNow;
                    store.CreatedBy = siteUser.UserGuid;

                }

                store.Save();

                List<TaxClass> taxClasses = TaxClass.GetList(siteSettings.SiteGuid);

                if (taxClasses.Count == 0)
                {
                    TaxClass taxClass = new TaxClass();
                    taxClass.SiteGuid = siteSettings.SiteGuid;
                    taxClass.Title = WebStoreResources.TaxClassTaxable;
                    taxClass.Description = WebStoreResources.TaxClassTaxable;
                    taxClass.Save();

                    taxClass = new TaxClass();
                    taxClass.SiteGuid = siteSettings.SiteGuid;
                    taxClass.Title = WebStoreResources.TaxClassNotTaxable;
                    taxClass.Description = WebStoreResources.TaxClassNotTaxable;
                    taxClass.Save();

                }

                List<FullfillDownloadTerms> downloadTerms = FullfillDownloadTerms.GetList(store.Guid);
                if (downloadTerms.Count == 0)
                {
                    if(currentUser == null)currentUser = SiteUtils.GetCurrentSiteUser();
                    if (currentUser != null)
                    {
                        FullfillDownloadTerms term = new FullfillDownloadTerms();
                        term.Name = WebStoreResources.DownloadUnlimited;
                        term.Description = WebStoreResources.DownloadUnlimited;
                        term.CreatedBy = currentUser.UserGuid;
                        term.CreatedFromIP = SiteUtils.GetIP4Address();
                        term.StoreGuid = store.Guid;
                        term.Save();

                    }

                }

                WebUtils.SetupRedirect(this, Request.RawUrl);

            }
        }
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            Store store = new Store(module.SiteGuid, module.ModuleId);
            if (store.Guid == Guid.Empty) // No store created yet
            {
                store = new Store();
                store.SiteGuid = module.SiteGuid;
                store.ModuleId = module.ModuleId;
                store.Save();
            }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);

            Guid taxClassGuid = Guid.Empty;

            List<TaxClass> taxClasses = TaxClass.GetList(siteSettings.SiteGuid);
            if (taxClasses.Count == 0)
            {
                TaxClass taxClass = new TaxClass();
                taxClass.SiteGuid = siteSettings.SiteGuid;
                taxClass.Title = "Taxable";
                taxClass.Description = "Taxable";
                taxClass.Save();

                taxClass = new TaxClass();
                taxClass.SiteGuid = siteSettings.SiteGuid;
                taxClass.Title = "Not Taxable";
                taxClass.Description = "Not Taxable";
                taxClass.Save();

                taxClassGuid = taxClass.Guid;

            }
            else
            {
                foreach (TaxClass t in taxClasses)
                {
                    if (t.Title == "Not Taxable")
                    {
                        taxClassGuid = t.Guid;
                    }
                }
            }

            SiteUser admin = SiteUser.GetNewestUser(siteSettings);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            CultureInfo currencyCulture = new CultureInfo("en-US");

            if (xml.DocumentElement.Name == "store")
            {
                // update the store
                XmlAttributeCollection storeAttrributes = xml.DocumentElement.Attributes;

                if (storeAttrributes["storeName"] != null)
                {
                    store.Name = storeAttrributes["storeName"].Value;
                }

                if (storeAttrributes["emailFrom"] != null)
                {
                    store.EmailFrom = storeAttrributes["emailFrom"].Value;
                }

                if (storeAttrributes["currencyCulture"] != null)
                {
                    currencyCulture = new CultureInfo(storeAttrributes["currencyCulture"].Value);
                }

                if (storeAttrributes["ownerName"] != null)
                {
                    store.OwnerName = storeAttrributes["ownerName"].Value;
                }

                if (storeAttrributes["ownerEmail"] != null)
                {
                    store.OwnerEmail = storeAttrributes["ownerEmail"].Value;
                }

                if (storeAttrributes["city"] != null)
                {
                    store.City = storeAttrributes["city"].Value;
                }

                if (storeAttrributes["postalCode"] != null)
                {
                    store.PostalCode = storeAttrributes["postalCode"].Value;
                }

                if (storeAttrributes["phone"] != null)
                {
                    store.Phone = storeAttrributes["phone"].Value;
                }

                if (storeAttrributes["address"] != null)
                {
                    store.Address = storeAttrributes["address"].Value;
                }

                if (storeAttrributes["countryGuid"] != null)
                {
                    string g = storeAttrributes["countryGuid"].Value;
                    if(g.Length == 36)
                    {
                        Guid countryGuid = new Guid(g);
                        store.CountryGuid = countryGuid;
                    }
                }

                if (storeAttrributes["stateGuid"] != null)
                {
                    string s = storeAttrributes["stateGuid"].Value;
                    if(s.Length == 36)
                    {
                        Guid stateGuid = new Guid(s);
                        store.ZoneGuid = stateGuid;
                    }
                }

                foreach (XmlNode descriptionNode in xml.DocumentElement.ChildNodes)
                {
                    if (descriptionNode.Name == "storeDescription")
                    {
                        store.Description = descriptionNode.InnerText;
                        break;
                    }
                }

                store.Save();

                //module settings
                foreach (XmlNode node in xml.DocumentElement.ChildNodes)
                {
                    if (node.Name == "moduleSetting")
                    {
                        XmlAttributeCollection settingAttributes = node.Attributes;

                        if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0))
                        {
                            string key = settingAttributes["settingKey"].Value;
                            string val = string.Empty;
                            if (settingAttributes["settingValue"] != null)
                            {
                                val = settingAttributes["settingValue"].Value;
                            }

                            ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val);
                        }
                    }
                }

                if (storeAttrributes["productFilesPath"] != null)
                {
                    if (storeAttrributes["productFilesPath"].Value.Length > 0)
                    {
                        string destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/webstoreproductfiles/";
                        if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                        {
                            Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                        }

                        IOHelper.CopyFolderContents(HostingEnvironment.MapPath(storeAttrributes["productFilesPath"].Value), HostingEnvironment.MapPath(destPath));
                    }

                }

                if (storeAttrributes["teaserFilesPath"] != null)
                {
                    if (storeAttrributes["teaserFilesPath"].Value.Length > 0)
                    {
                        string destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/webstoreproductpreviewfiles/";
                        if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                        {
                            Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                        }

                        IOHelper.CopyFolderContents(HostingEnvironment.MapPath(storeAttrributes["teaserFilesPath"].Value), HostingEnvironment.MapPath(destPath));
                    }

                }

                FullfillDownloadTerms term = new FullfillDownloadTerms();
                term.Name = WebStoreResources.DownloadUnlimited;
                term.Description = WebStoreResources.DownloadUnlimited;
                if (admin != null)
                {
                    term.CreatedBy = admin.UserGuid;
                }
                term.StoreGuid = store.Guid;
                term.Save();

                XmlNode offersNode = null;
                foreach (XmlNode n in xml.DocumentElement.ChildNodes)
                {
                    if (n.Name == "offers")
                    {
                        offersNode = n;
                        break;
                    }
                }

                if (offersNode != null)
                {
                    foreach (XmlNode node in offersNode.ChildNodes)
                    {
                        if (node.Name == "offer")
                        {
                            XmlAttributeCollection offerAttrributes = node.Attributes;

                            Offer offer = new Offer();
                            offer.StoreGuid = store.Guid;
                            offer.Created = DateTime.UtcNow;
                            offer.LastModified = DateTime.UtcNow;

                            if (admin != null)
                            {
                                offer.CreatedBy = admin.UserGuid;
                                offer.LastModifiedBy = admin.UserGuid;
                            }

                            if (offerAttrributes["offerName"] != null)
                            {
                                offer.Name = offerAttrributes["offerName"].Value;
                            }

                            if (offerAttrributes["nameOnProductList"] != null)
                            {
                                offer.ProductListName = offerAttrributes["nameOnProductList"].Value;
                            }

                            if (
                                (offerAttrributes["isVisible"] != null)
                                && (offerAttrributes["isVisible"].Value.ToLower() == "true")
                                )
                            {
                                offer.IsVisible = true;
                            }

                            if (
                                (offerAttrributes["isSpecial"] != null)
                                && (offerAttrributes["isSpecial"].Value.ToLower() == "true")
                                )
                            {
                                offer.IsSpecial = true;
                            }

                            //offer.IsDonation = chkIsDonation.Checked;

                            if (
                                (offerAttrributes["showOfferDetailLink"] != null)
                                && (offerAttrributes["showOfferDetailLink"].Value.ToLower() == "true")
                                )
                            {
                                offer.ShowDetailLink = true;
                            }

                            if (offerAttrributes["primarySort"] != null)
                            {
                                int sort = 5000;
                                if (int.TryParse(offerAttrributes["primarySort"].Value,
                                    out sort))
                                {
                                    offer.SortRank1 = sort;
                                }
                            }

                            if (offerAttrributes["secondarySort"] != null)
                            {
                                int sort = 5000;
                                if (int.TryParse(offerAttrributes["secondarySort"].Value,
                                    out sort))
                                {
                                    offer.SortRank2 = sort;
                                }
                            }

                            if (offerAttrributes["price"] != null)
                            {
                                offer.Price = decimal.Parse(offerAttrributes["price"].Value, NumberStyles.Currency, currencyCulture);
                            }

                            offer.TaxClassGuid = taxClassGuid;

                            offer.Url = "/"
                                    + SiteUtils.SuggestFriendlyUrl(
                                    offer.Name + WebStoreResources.OfferUrlSuffix,
                                    siteSettings);

                            foreach (XmlNode descriptionNode in node.ChildNodes)
                            {
                                if (descriptionNode.Name == "abstract")
                                {
                                    offer.Teaser = descriptionNode.InnerText;
                                    break;
                                }
                            }

                            foreach (XmlNode descriptionNode in node.ChildNodes)
                            {
                                if (descriptionNode.Name == "description")
                                {
                                    offer.Description = descriptionNode.InnerText;
                                    break;
                                }
                            }

                            if (offer.Save())
                            {

                                FriendlyUrl newUrl = new FriendlyUrl();
                                newUrl.SiteId = siteSettings.SiteId;
                                newUrl.SiteGuid = siteSettings.SiteGuid;
                                newUrl.PageGuid = offer.Guid;
                                newUrl.Url = offer.Url.Replace("/", string.Empty);
                                newUrl.RealUrl = "~/WebStore/OfferDetail.aspx?pageid="
                                    + module.PageId.ToInvariantString()
                                    + "&mid=" + module.ModuleId.ToInvariantString()
                                    + "&offer=" + offer.Guid.ToString();

                                newUrl.Save();

                            }

                            foreach (XmlNode productNode in node.ChildNodes)
                            {
                                if (productNode.Name == "product")
                                {
                                    XmlAttributeCollection productAttrributes = productNode.Attributes;

                                    Product product = new Product();
                                    product.StoreGuid = store.Guid;
                                    if (admin != null)
                                    {
                                        product.CreatedBy = admin.UserGuid;

                                    }

                                    product.Created = DateTime.UtcNow;
                                    product.TaxClassGuid = taxClassGuid;

                                    if (productAttrributes["name"] != null)
                                    {
                                        product.Name = productAttrributes["name"].Value;
                                    }

                                    if (productAttrributes["modelNumber"] != null)
                                    {
                                        product.ModelNumber = productAttrributes["modelNumber"].Value;
                                    }

                                    if (productAttrributes["teaser"] != null)
                                    {
                                        product.TeaserFile = productAttrributes["teaser"].Value;
                                    }

                                    if (productAttrributes["fulfillmentType"] != null)
                                    {
                                        product.FulfillmentType
                                        = Product.FulfillmentTypeFromString(productAttrributes["fulfillmentType"].Value);
                                    }

                                    product.Status = ProductStatus.Available;
                                    product.Weight = 0;
                                    product.QuantityOnHand = 0;

                                    if (
                                        (productAttrributes["showInProductList"] != null)
                                        && (productAttrributes["showInProductList"].Value.ToLower() == "true")
                                        )
                                    {
                                        product.ShowInProductList = true;
                                    }

                                    if (
                                        (productAttrributes["enableRating"] != null)
                                        && (productAttrributes["enableRating"].Value.ToLower() == "true")
                                        )
                                    {
                                        product.EnableRating = true;
                                    }

                                    if (productAttrributes["primarySort"] != null)
                                    {
                                        int sort = 5000;
                                        if (int.TryParse(productAttrributes["primarySort"].Value,
                                            out sort))
                                        {
                                            product.SortRank1 = sort;
                                        }
                                    }

                                    if (productAttrributes["secondarySort"] != null)
                                    {
                                        int sort = 5000;
                                        if (int.TryParse(productAttrributes["secondarySort"].Value,
                                            out sort))
                                        {
                                            product.SortRank2 = sort;
                                        }
                                    }

                                    product.Url = "/"
                                            + SiteUtils.SuggestFriendlyUrl(
                                            product.Name + WebStoreResources.ProductUrlSuffix,
                                            siteSettings);

                                    foreach (XmlNode descriptionNode in productNode.ChildNodes)
                                    {
                                        if (descriptionNode.Name == "abstract")
                                        {
                                            product.Teaser = descriptionNode.InnerText;
                                            break;
                                        }
                                    }

                                    foreach (XmlNode descriptionNode in productNode.ChildNodes)
                                    {
                                        if (descriptionNode.Name == "description")
                                        {
                                            product.Description = descriptionNode.InnerText;
                                            break;
                                        }
                                    }

                                    if (product.Save())
                                    {
                                        if (productAttrributes["file"] != null)
                                        {

                                            ProductFile productFile = new ProductFile(product.Guid);
                                            productFile.ServerFileName = productAttrributes["file"].Value;

                                            if (productAttrributes["fileName"] != null)
                                            {
                                                productFile.FileName = productAttrributes["fileName"].Value;
                                            }

                                            if (admin != null)
                                            {
                                                productFile.CreatedBy = admin.UserGuid;
                                            }

                                            productFile.Save();
                                        }

                                        FriendlyUrl newUrl = new FriendlyUrl();
                                        newUrl.SiteId = siteSettings.SiteId;
                                        newUrl.SiteGuid = siteSettings.SiteGuid;
                                        newUrl.PageGuid = product.Guid;
                                        newUrl.Url = product.Url.Replace("/", string.Empty);
                                        newUrl.RealUrl = "~/WebStore/ProductDetail.aspx?pageid="
                                            + module.PageId.ToInvariantString()
                                            + "&mid=" + module.ModuleId.ToInvariantString()
                                            + "&product=" + product.Guid.ToString();

                                        newUrl.Save();

                                    }

                                    // create offer product
                                    OfferProduct offerProduct = new OfferProduct();
                                    if (admin != null)
                                    {
                                        offerProduct.CreatedBy = admin.UserGuid;
                                    }

                                    offerProduct.ProductGuid = product.Guid;

                                    if (productAttrributes["fulfillmentType"] != null)
                                    {
                                        offerProduct.FullfillType = Convert.ToByte(productAttrributes["fulfillmentType"].Value);
                                    }

                                    if (productAttrributes["sortOrder"] != null)
                                    {
                                        int sort = 100;
                                        if (int.TryParse(productAttrributes["sortOrder"].Value, out sort))
                                        {
                                           offerProduct.SortOrder = sort;
                                        }
                                    }

                                    if (productAttrributes["quantity"] != null)
                                    {
                                        int qty = 1;
                                        if (int.TryParse(productAttrributes["quantity"].Value, out qty))
                                        {
                                            offerProduct.Quantity = qty;
                                        }
                                    }

                                    offerProduct.FullfillType = (byte)product.FulfillmentType;
                                    offerProduct.FullFillTermsGuid = term.Guid;

                                    offerProduct.OfferGuid = offer.Guid;
                                    offerProduct.Save();

                                }
                            }

                        }

                    }

                }

            }

            //create product
        }
        private static List<FullfillDownloadTerms> LoadListFromReader(IDataReader reader)
        {
            List<FullfillDownloadTerms> fullfillDownloadTermList = new List<FullfillDownloadTerms>();
            try
            {
                while (reader.Read())
                {
                    FullfillDownloadTerms fullfillDownloadTerm = new FullfillDownloadTerms();
                    fullfillDownloadTerm.guid = new Guid(reader["Guid"].ToString());
                    fullfillDownloadTerm.storeGuid = new Guid(reader["StoreGuid"].ToString());
                    fullfillDownloadTerm.downloadsAllowed = Convert.ToInt32(reader["DownloadsAllowed"]);
                    fullfillDownloadTerm.expireAfterDays = Convert.ToInt32(reader["ExpireAfterDays"]);
                    fullfillDownloadTerm.countAfterDownload = Convert.ToBoolean(reader["CountAfterDownload"]);
                    fullfillDownloadTerm.created = Convert.ToDateTime(reader["Created"]);
                    fullfillDownloadTerm.createdBy = new Guid(reader["CreatedBy"].ToString());
                    fullfillDownloadTerm.createdFromIP = reader["CreatedFromIP"].ToString();
                    fullfillDownloadTerm.lastModified = Convert.ToDateTime(reader["LastModified"]);
                    fullfillDownloadTerm.lastModifedBy = new Guid(reader["LastModifedBy"].ToString());
                    fullfillDownloadTerm.lastModifedFromIPAddress = reader["LastModifedFromIPAddress"].ToString();
                    fullfillDownloadTermList.Add(fullfillDownloadTerm);

                    fullfillDownloadTerm.Description = reader["Description"].ToString();
                    fullfillDownloadTerm.name = reader["Name"].ToString();

                }
            }
            finally
            {
                reader.Close();
            }

            return fullfillDownloadTermList;
        }