示例#1
0
        public HttpResponseMessage update(ValueAddedTax post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }

            // Make sure that the data is valid
            post.value = AnnytabDataValidation.TruncateDecimal(post.value, 0, 9.99999M);

            // Get the saved post
            ValueAddedTax savedPost = ValueAddedTax.GetOneById(post.id);

            // Check if the post exists
            if (savedPost == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist"));
            }

            // Update the post
            ValueAddedTax.Update(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful"));
        } // End of the update method
示例#2
0
        public ValueAddedTax get_by_id(Int32 id = 0)
        {
            // Create the post to return
            ValueAddedTax post = ValueAddedTax.GetOneById(id);

            // Return the post
            return(post);
        } // End of the get_by_id method
示例#3
0
        public ActionResult edit(Int32 id = 0, string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get the default admin language
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Add data to the view
            ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");
            ViewBag.ValueAddedTax = ValueAddedTax.GetOneById(id);
            ViewBag.ReturnUrl = returnUrl;

            // Create a new empty value added tax post if the value added taxt post does not exist
            if (ViewBag.ValueAddedTax == null)
            {
                // Add data to the view
                ViewBag.ValueAddedTax = new ValueAddedTax();
            }

            // Return the edit view
            return View("edit");

        } // End of the edit method
示例#4
0
    } // End of the Create method

    /// <summary>
    /// Write one product item to the file
    /// </summary>
    /// <param name="writer">A reference to an stream writer</param>
    /// <param name="domain">A reference to a domain</param>
    /// <param name="country">A referende to a country</param>
    /// <param name="product">A reference to a product</param>
    /// <param name="currency">A reference to a currency</param>
    /// <param name="decimalMultiplier">The decimal multiplier</param>
    private static void WriteProductItem(StreamWriter writer, Domain domain, Country country, Product product, Currency currency,
        Int32 decimalMultiplier)
    {
        // Get the value added tax
        ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(product.value_added_tax_id);

        // Get the unit
        Unit unit = Unit.GetOneById(product.unit_id, domain.front_end_language);

        // Get the category
        Category category = Category.GetOneById(product.category_id, domain.front_end_language);

        // Get a chain of parent categories
        List<Category> parentCategoryChain = Category.GetParentCategoryChain(category, domain.front_end_language);

        // Create the category string
        string categoryString = "";
        for (int i = 0; i < parentCategoryChain.Count; i++)
        {
            categoryString += parentCategoryChain[i].title;

            if (i < parentCategoryChain.Count - 1)
            {
                categoryString += " > ";
            }
        }

        // Remove html from the title and the main content
        string title = StringHtmlExtensions.StripHtml(product.title);
        title = title.Replace("|", "");
        string main_content = Regex.Replace(product.main_content, @"(<br\s*[\/]>)+", " ");
        main_content = StringHtmlExtensions.StripHtml(main_content);
        main_content = Regex.Replace(main_content, @"\r\n?|\n", "");
        main_content = main_content.Replace("|", "");
        main_content = AnnytabDataValidation.TruncateString(main_content, 5000);
        
        // Calculate the price
        decimal basePrice = product.unit_price * (currency.currency_base / currency.conversion_rate);
        decimal regularPrice = Math.Round(basePrice * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        decimal salePrice = Math.Round(basePrice * (1 - product.discount) * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

        // Get the country code as upper case letters
        string countryCodeUpperCase = country.country_code.ToUpper();

        // Add value added tax to the price
        if (countryCodeUpperCase != "US" && countryCodeUpperCase != "CA" && countryCodeUpperCase != "IN")
        {
            regularPrice += Math.Round(regularPrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            salePrice += Math.Round(salePrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        }

        // Calculate the freight
        decimal freight = (product.unit_freight + product.toll_freight_addition) * (currency.currency_base / currency.conversion_rate);
        freight = Math.Round(freight * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

        // Add value added tax to the freight
        if (countryCodeUpperCase != "US" && countryCodeUpperCase != "CA" && countryCodeUpperCase != "IN")
        {
            freight += Math.Round(freight * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        }

        // Create the line to write to
        // Category|Product name|SKU|Price|Shipping Cost|Product URL|Manufacturer SKU|Manufacturer|EAN or UPC|Description|Image URL|Stock Status|Delivery time|Product state|ISBN
        string line = "";

        // Category
        line += categoryString + "|";

        // Product name
        line += title + "|";

        // SKU
        line += product.product_code + "|";

        // Price
        line += salePrice.ToString(CultureInfo.InvariantCulture) + "|";

        // Shipping Cost
        line += freight.ToString(CultureInfo.InvariantCulture) + "|";

        // Product URL
        line += domain.web_address + "/home/product/" + product.page_name + "|";

        // Manufacturer SKU
        line += product.manufacturer_code + "|";

        // Manufacturer
        line += product.brand + "|";

        // EAN or UPC
        line += product.gtin + "|";

        // Description
        line += main_content + "|";

        // Image URL
        line += domain.web_address + Tools.GetProductMainImageUrl(product.id, domain.front_end_language, product.variant_image_filename, product.use_local_images) + "|";

        // Stock Status
        line += GetAvailabilityStatus(product.availability_status) + "|";

        // Delivery time
        line += product.delivery_time + "|";

        // Product state
        line += product.condition != "" ? product.condition + "|" : "new|";

        // ISBN
        line += product.gtin;

        // Write the line to the file
        writer.WriteLine(line);

    } // End of the WriteProductItem method
示例#5
0
        public ActionResult add_to_cart(FormCollection collection)
        {
            // Get form data
            Int32 productId = Convert.ToInt32(collection["pid"]);
            decimal quantity = 0;
            decimal.TryParse(collection["qty"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out quantity);
            string[] productOptionTypeIds = collection["optionTypes"].Split('|');
            string[] selectedOptionIds = collection["optionIds"].Split('|');

            // Get the current domain
            Domain domain = Tools.GetCurrentDomain();

            // Get the currency
            Currency currency = Currency.GetOneById(domain.currency);

            // Get the product by id
            Product product = Product.GetOneById(productId, domain.front_end_language);

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(domain.front_end_language, "id", "ASC");

            // Make sure that the product not is null
            if (product == null)
            {
                return new EmptyResult();
            }

            // Get product values
            string productName = product.title;
            string productCode = product.product_code;
            string manufacturerCode = product.manufacturer_code;
            decimal unitPrice = product.unit_price;
            decimal unitFreight = product.unit_freight + product.toll_freight_addition;
            string variantImageUrl = product.variant_image_filename;

            // Update the added to cart statistic
            if (product.added_in_basket <= Int32.MaxValue - 1)
            {
                Product.UpdateAddedInBasket(product.id, product.added_in_basket + 1);
            }

            // The count of option ids
            Int32 optionIdCount = selectedOptionIds != null && selectedOptionIds[0] != "" ? selectedOptionIds.Length : 0;

            // Loop option identities and add to the price, freight and product code
            for (int i = 0; i < optionIdCount; i++)
            {
                // Convert the ids
                Int32 optionTypeId = Convert.ToInt32(productOptionTypeIds[i]);
                Int32 optionId = Convert.ToInt32(selectedOptionIds[i]);

                // Get the product option type and the product option
                ProductOptionType productOptionType = ProductOptionType.GetOneById(optionTypeId, domain.front_end_language);
                ProductOption productOption = ProductOption.GetOneById(optionTypeId, optionId, domain.front_end_language);

                // Add to values
                productName += "," + productOptionType.title + ": " + productOption.title;
                productCode += productOption.product_code_suffix;
                manufacturerCode += productOption.mpn_suffix;
                unitPrice += productOption.price_addition;
                unitFreight += productOption.freight_addition;
                variantImageUrl = variantImageUrl.Replace("[" + i + "]", productOption.product_code_suffix);
            }

            // Add delivery time to the product name
            productName += "," + tt.Get("delivery_time") + ": " + product.delivery_time;

            // Adjust the price and the freight with the conversion rate
            unitPrice *= (currency.currency_base / currency.conversion_rate);
            unitFreight *= (currency.currency_base / currency.conversion_rate);

            // Round the price to the minor unit for the currency
            Int32 decimalMultiplier = (Int32)Math.Pow(10, currency.decimals);
            unitPrice = Math.Round(unitPrice * (1 - product.discount) * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            unitFreight = Math.Round(unitFreight * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

            // Get the value added tax
            ValueAddedTax vat = ValueAddedTax.GetOneById(product.value_added_tax_id);

            // Create a cart item
            CartItem cartItem = new CartItem();
            cartItem.product_code = productCode;
            cartItem.product_id = product.id;
            cartItem.manufacturer_code = manufacturerCode;
            cartItem.product_name = productName;
            cartItem.quantity = quantity;
            cartItem.unit_price = unitPrice;
            cartItem.unit_freight = unitFreight;
            cartItem.vat_percent = vat.value;
            cartItem.variant_image_url = variantImageUrl;
            cartItem.use_local_images = product.use_local_images;

            // Add the cart item to the shopping cart
            CartItem.AddToShoppingCart(cartItem);

            // Check if prices should include VAT or not
            bool pricesIncludesVat = Session["PricesIncludesVat"] != null ? Convert.ToBoolean(Session["PricesIncludesVat"]) : domain.prices_includes_vat;

            // Get the current culture info
            CultureInfo cultureInfo = Tools.GetCultureInfo(Language.GetOneById(domain.front_end_language));

            // Get cart statistics
            Dictionary<string, decimal> cartStatistics = CartItem.GetCartStatistics(domain, pricesIncludesVat);

            // Create the dictionary to return
            Dictionary<string, string> cartData = new Dictionary<string, string>(3);
            cartData.Add("cart_quantity", cartStatistics["total_quantity"].ToString("##,0.##", cultureInfo));
            cartData.Add("cart_amount", cartStatistics["total_amount"].ToString("##,0.##", cultureInfo) + " " + domain.currency + (pricesIncludesVat == true ? " (" + tt.Get("including_vat").ToLower() + ")" : " (" + tt.Get("excluding_vat").ToLower() + ")"));
            cartData.Add("units_in_cart", tt.Get("units_in_cart").ToLower());

            // Return a dictionary with cart data
            return Json(cartData);

        } // End of the add_to_cart method
示例#6
0
        public ActionResult add_product(FormCollection collection)
        {
            // Get the product id
            Int32 productId = Convert.ToInt32(collection["hiddenProductId"]);

            // Get the current domain
            Domain domain = Tools.GetCurrentDomain();

            // Get the currency
            Currency currency = Currency.GetOneById(domain.currency);

            // Get the product by id
            Product product = Product.GetOneById(productId, domain.front_end_language);

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(domain.front_end_language, "id", "ASC");

            // Make sure that the product not is null
            if (product == null)
            {
                Response.StatusCode = 404;
                Response.Status = "404 Not Found";
                Response.Write(Tools.GetHttpNotFoundPage());
                return new EmptyResult();
            }

            // Get form data
            decimal quantity = 0;
            decimal.TryParse(collection["txtQuantity"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out quantity);
            string[] productOptionTypeIds = collection.GetValues("productOptionTypeId");
            string[] selectedOptionIds = collection.GetValues("selectProductOption");

            // Get other values
            string productName = product.title;
            string productCode = product.product_code;
            string manufacturerCode = product.manufacturer_code;
            decimal unitPrice = product.unit_price;
            decimal unitFreight = product.unit_freight + product.toll_freight_addition;
            string variantImageUrl = product.variant_image_filename;

            // Update the added to cart statistic
            if(product.added_in_basket <= Int32.MaxValue - 1)
            {
                Product.UpdateAddedInBasket(product.id, product.added_in_basket + 1);
            }

            // Check if the product has a affiliate link
            if (product.affiliate_link != "")
            {
                // Redirect the user to the affiliate site
                return Redirect(product.affiliate_link);
            }

            // The count of option ids
            Int32 optionIdCount = selectedOptionIds != null ? selectedOptionIds.Length : 0;

            // Loop option identities and add to the price, freight and product code
            for (int i = 0; i < optionIdCount; i++)
            {
                // Convert the ids
                Int32 optionTypeId = Convert.ToInt32(productOptionTypeIds[i]);
                Int32 optionId = Convert.ToInt32(selectedOptionIds[i]);

                // Get the product option type and the product option
                ProductOptionType productOptionType = ProductOptionType.GetOneById(optionTypeId, domain.front_end_language);
                ProductOption productOption = ProductOption.GetOneById(optionTypeId, optionId, domain.front_end_language);

                // Add to values
                productName += "," + productOptionType.title + ": " + productOption.title;
                productCode += productOption.product_code_suffix;
                manufacturerCode += productOption.mpn_suffix;
                unitPrice += productOption.price_addition;
                unitFreight += productOption.freight_addition;
                variantImageUrl = variantImageUrl.Replace("[" + i + "]", productOption.product_code_suffix);
            }

            // Add delivery time to the product name
            productName += "," + tt.Get("delivery_time") + ": " + product.delivery_time;

            // Adjust the price and the freight with the conversion rate
            unitPrice *= (currency.currency_base / currency.conversion_rate);
            unitFreight *= (currency.currency_base / currency.conversion_rate);

            // Round the price to the minor unit for the currency
            Int32 decimalMultiplier = (Int32)Math.Pow(10, currency.decimals);
            unitPrice = Math.Round(unitPrice * (1 - product.discount) * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            unitFreight = Math.Round(unitFreight * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

            // Get the value added tax
            ValueAddedTax vat = ValueAddedTax.GetOneById(product.value_added_tax_id);

            // Create a cart item
            CartItem cartItem = new CartItem();
            cartItem.product_code = productCode;
            cartItem.product_id = product.id;
            cartItem.manufacturer_code = manufacturerCode;
            cartItem.product_name = productName;
            cartItem.quantity = quantity;
            cartItem.unit_price = unitPrice;
            cartItem.unit_freight = unitFreight;
            cartItem.vat_percent = vat.value;
            cartItem.variant_image_url = variantImageUrl;
            cartItem.use_local_images = product.use_local_images;

            // Add the cart item to the shopping cart
            CartItem.AddToShoppingCart(cartItem);

            // Redirect the user to the same product page
            return RedirectToAction("product", "home", new { id = product.page_name, cu = "true" });

        } // End of the add_product method
示例#7
0
        public ActionResult product(string id = "")
        {
            // Get the domain, the product, the currency and the value added tax
            Domain currentDomain = Tools.GetCurrentDomain();
            Product currentProduct = Product.GetOneByPageName(id, currentDomain.front_end_language);
            
            // Make sure that the product not is null
            if (currentProduct == null)
            {
                Response.StatusCode = 404;
                Response.Status = "404 Not Found";
                Response.Write(Tools.GetHttpNotFoundPage());
                return new EmptyResult();
            }

            // Get additional data
            Currency currency = Currency.GetOneById(currentDomain.currency);
            ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(currentProduct.value_added_tax_id);
            Category currentCategory = Category.GetOneById(currentProduct.category_id, currentDomain.front_end_language);
            currentCategory = currentCategory != null ? currentCategory : new Category();

            // Get the product price and product code
            decimal productPrice = currentProduct.unit_price;
            string productCode = currentProduct.product_code;
            string manufacturerCode = currentProduct.manufacturer_code;
            string variantImageUrl = currentProduct.variant_image_filename;

            // Get product option types and product options
            List<ProductOptionType> productOptionTypes = ProductOptionType.GetByProductId(currentProduct.id, currentDomain.front_end_language);
            Dictionary<Int32, List<ProductOption>> productOptions = new Dictionary<int, List<ProductOption>>(productOptionTypes.Count);

            // Loop all the product option types
            for (int i = 0; i < productOptionTypes.Count; i++)
            {
                List<ProductOption> listProductOptions = ProductOption.GetByProductOptionTypeId(productOptionTypes[i].id, currentDomain.front_end_language);

                if (listProductOptions.Count > 0)
                {
                    productPrice += listProductOptions[0].price_addition;
                    productCode += listProductOptions[0].product_code_suffix;
                    manufacturerCode += listProductOptions[0].mpn_suffix;
                    variantImageUrl = variantImageUrl.Replace("[" + i + "]", listProductOptions[0].product_code_suffix);
                }

                // Add all the product options for the option type to the dictionary
                productOptions.Add(productOptionTypes[i].option_type_id, ProductOption.GetByProductOptionTypeId(productOptionTypes[i].id, currentDomain.front_end_language));
            }

            // Adjust the product price with the currency conversion rate
            productPrice *= (currency.currency_base / currency.conversion_rate);

            // Round the price to the minor unit for the currency
            Int32 decimalMultiplier = (Int32)Math.Pow(10, currency.decimals);
            decimal ordinaryPrice = Math.Round(productPrice * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            productPrice = Math.Round(productPrice * (1 - currentProduct.discount) * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

            // Check if prices should include vat
            bool pricesIncludesVat = Session["PricesIncludesVat"] != null ? Convert.ToBoolean(Session["PricesIncludesVat"]) : currentDomain.prices_includes_vat;

            // Add vat if prices should include vat
            if (pricesIncludesVat == true)
            {
                ordinaryPrice += Math.Round(ordinaryPrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
                productPrice += Math.Round(productPrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            }

            // Calculate the comparison price
            decimal comparisonPrice = 0;
            if (currentProduct.unit_pricing_measure > 0 && currentProduct.unit_pricing_base_measure > 0)
            {
                comparisonPrice = (currentProduct.unit_pricing_base_measure / currentProduct.unit_pricing_measure) * productPrice;
                comparisonPrice = Math.Round(comparisonPrice * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            }

            // Get the translated texts
            KeyStringList tt = StaticText.GetAll(currentDomain.front_end_language, "id", "ASC");

            // Get a chain of parent categories
            List<Category> parentCategoryChain = Category.GetParentCategoryChain(currentCategory, currentDomain.front_end_language);

            // Create the bread crumb list
            List<BreadCrumb> breadCrumbs = new List<BreadCrumb>(10);
            breadCrumbs.Add(new BreadCrumb(tt.Get("start_page"), "/"));
            for (int i = 0; i < parentCategoryChain.Count; i++)
            {
                breadCrumbs.Add(new BreadCrumb(parentCategoryChain[i].title, "/home/category/" + parentCategoryChain[i].page_name));
            }
            breadCrumbs.Add(new BreadCrumb(currentProduct.title, "/home/product/" + currentProduct.page_name));

            // Update page views
            if (currentProduct.page_views <= Int32.MaxValue - 1)
            {
                Product.UpdatePageviews(currentProduct.id, currentProduct.page_views + 1);
            }

            // Get the unit
            Unit unit = Unit.GetOneById(currentProduct.unit_id, currentDomain.front_end_language);

            // Set form values
            ViewBag.BreadCrumbs = breadCrumbs;
            ViewBag.CurrentDomain = currentDomain;
            ViewBag.TranslatedTexts = tt;
            ViewBag.CurrentLanguage = Language.GetOneById(currentDomain.front_end_language);
            ViewBag.CurrentCategory = currentCategory;
            ViewBag.Currency = currency;
            ViewBag.CurrentProduct = currentProduct;
            ViewBag.ValueAddedTax = valueAddedTax;
            ViewBag.ProductOptionTypes = productOptionTypes;
            ViewBag.ProductOptions = productOptions;
            ViewBag.ProductPrice = productPrice;
            ViewBag.OrdinaryPrice = ordinaryPrice;
            ViewBag.ComparisonPrice = comparisonPrice;
            ViewBag.Unit = unit != null ? unit : new Unit();
            ViewBag.ProductCode = productCode;
            ViewBag.ManufacturerCode = manufacturerCode;
            ViewBag.VariantImageUrl = variantImageUrl;
            ViewBag.UserSettings = (Dictionary<string, string>)Session["UserSettings"];
            ViewBag.PricesIncludesVat = pricesIncludesVat;
            ViewBag.CultureInfo = Tools.GetCultureInfo(ViewBag.CurrentLanguage);

            // Return the view
            return currentDomain.custom_theme_id == 0 ? View() : View("/Views/theme/product.cshtml");

        } // End of the product method
    } // End of the Create method

    /// <summary>
    /// Write one product item to the file
    /// </summary>
    /// <param name="writer">A reference to an xml text writer</param>
    /// <param name="domain">A reference to a domain</param>
    /// <param name="country">A referende to a country</param>
    /// <param name="product">A reference to a product</param>
    /// <param name="currency">A reference to a currency</param>
    /// <param name="decimalMultiplier">The decimal multiplier</param>
    /// <param name="googleVariants">A list with google variants</param>
    private static void WriteProductItem(XmlTextWriter writer, Domain domain, Country country, Product product, Currency currency,
                                         Int32 decimalMultiplier, List <string[]> googleVariants)
    {
        // Get the value added tax
        ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(product.value_added_tax_id);

        // Get the unit
        Unit unit = Unit.GetOneById(product.unit_id, domain.front_end_language);

        // Get the comparison unit
        Unit   comparisonUnit       = Unit.GetOneById(product.comparison_unit_id, domain.front_end_language);
        string comparison_unit_code = comparisonUnit != null ? comparisonUnit.unit_code_si : "na";

        // Get the category
        Category category = Category.GetOneById(product.category_id, domain.front_end_language);

        // Get a chain of parent categories
        List <Category> parentCategoryChain = Category.GetParentCategoryChain(category, domain.front_end_language);

        // Create the category string
        string categoryString = "";

        for (int i = 0; i < parentCategoryChain.Count; i++)
        {
            categoryString += parentCategoryChain[i].title;

            if (i < parentCategoryChain.Count - 1)
            {
                categoryString += " > ";
            }
        }

        // Write the start item tag
        writer.WriteStartElement("item");

        // Remove html from the title and the main content
        string title = StringHtmlExtensions.StripHtml(product.title);

        title = AnnytabDataValidation.TruncateString(title, 150);
        string main_content = Regex.Replace(product.main_content, @"(<br\s*[\/]>)+", " ");

        main_content = StringHtmlExtensions.StripHtml(main_content);
        main_content = Regex.Replace(main_content, @"\r\n?|\n", "");
        main_content = AnnytabDataValidation.TruncateString(main_content, 5000);

        // Write item base information
        writer.WriteStartElement("g:id");
        writer.WriteString(product.product_code);
        writer.WriteEndElement();
        writer.WriteStartElement("title");
        writer.WriteString(title);
        writer.WriteEndElement();
        writer.WriteStartElement("description");
        writer.WriteString(main_content);
        writer.WriteEndElement();
        writer.WriteStartElement("g:google_product_category");
        writer.WriteString(product.google_category);
        writer.WriteEndElement();
        writer.WriteStartElement("g:product_type");
        writer.WriteString(categoryString);
        writer.WriteEndElement();
        writer.WriteStartElement("link");
        writer.WriteString(domain.web_address + "/home/product/" + product.page_name);
        writer.WriteEndElement();
        writer.WriteStartElement("g:image_link");
        writer.WriteString(domain.web_address + Tools.GetProductMainImageUrl(product.id, domain.front_end_language, product.variant_image_filename, product.use_local_images));
        writer.WriteEndElement();
        writer.WriteStartElement("g:condition");
        writer.WriteString(product.condition != "" ? product.condition : "new");
        writer.WriteEndElement();

        // Calculate the price
        decimal basePrice    = product.unit_price * (currency.currency_base / currency.conversion_rate);
        decimal regularPrice = Math.Round(basePrice * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        decimal salePrice    = Math.Round(basePrice * (1 - product.discount) * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

        // Get the country code as upper case letters
        string countryCodeUpperCase = country.country_code.ToUpper();

        // Add value added tax to the price
        if (countryCodeUpperCase != "US" && countryCodeUpperCase != "CA" && countryCodeUpperCase != "IN")
        {
            regularPrice += Math.Round(regularPrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            salePrice    += Math.Round(salePrice * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        }

        // Calculate the freight
        decimal freight = (product.unit_freight + product.toll_freight_addition) * (currency.currency_base / currency.conversion_rate);

        freight = Math.Round(freight * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;

        // Add value added tax to the freight
        if (countryCodeUpperCase != "US" && countryCodeUpperCase != "CA" && countryCodeUpperCase != "IN")
        {
            freight += Math.Round(freight * valueAddedTax.value * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
        }

        // Product availability and price
        writer.WriteStartElement("g:availability");
        writer.WriteString(GetGoogleAvailabilityStatus(product.availability_status));
        writer.WriteEndElement();
        writer.WriteStartElement("g:price");
        writer.WriteString(regularPrice.ToString(CultureInfo.InvariantCulture) + " " + currency.currency_code);
        writer.WriteEndElement();

        // Set the sale price if the product has a discount
        if (product.discount > 0M)
        {
            writer.WriteStartElement("g:sale_price");
            writer.WriteString(salePrice.ToString(CultureInfo.InvariantCulture) + " " + currency.currency_code);
            writer.WriteEndElement();
        }

        // Set the availability date
        if (product.availability_status == "availability_to_order")
        {
            writer.WriteStartElement("g:availability_date");
            writer.WriteString(product.availability_date.ToString("s"));
            writer.WriteEndElement();
        }

        // Unique product codes
        writer.WriteStartElement("g:brand");
        writer.WriteString(product.brand);
        writer.WriteEndElement();
        writer.WriteStartElement("g:gtin");
        writer.WriteString(product.gtin);
        writer.WriteEndElement();
        writer.WriteStartElement("g:mpn");
        writer.WriteString(product.manufacturer_code);
        writer.WriteEndElement();

        // An indentifier does not exist if brand and mpn or gtin is missing
        if ((product.brand != "" && product.manufacturer_code != "") || product.gtin != "")
        {
            writer.WriteStartElement("g:identifier_exists");
            writer.WriteString("TRUE");
            writer.WriteEndElement();
        }
        else
        {
            writer.WriteStartElement("g:identifier_exists");
            writer.WriteString("FALSE");
            writer.WriteEndElement();
        }

        // Freight
        writer.WriteStartElement("g:shipping");
        writer.WriteStartElement("g:country");
        writer.WriteString(country.country_code);
        writer.WriteEndElement();
        writer.WriteStartElement("g:price");
        writer.WriteString(freight.ToString(CultureInfo.InvariantCulture) + " " + currency.currency_code);
        writer.WriteEndElement();
        writer.WriteEndElement();

        // Is bundle product
        if (ProductBundle.GetByBundleProductId(product.id).Count > 0)
        {
            writer.WriteStartElement("g:is_bundle");
            writer.WriteString("TRUE");
            writer.WriteEndElement();
        }

        // Gender
        if (product.gender != "")
        {
            writer.WriteStartElement("g:gender");
            writer.WriteString(product.gender);
            writer.WriteEndElement();
        }

        // Age group
        if (product.age_group != "")
        {
            writer.WriteStartElement("g:age_group");
            writer.WriteString(product.age_group);
            writer.WriteEndElement();
        }

        // Adult only
        if (product.adult_only == true)
        {
            writer.WriteStartElement("g:adult");
            writer.WriteString("TRUE");
            writer.WriteEndElement();
        }
        else
        {
            writer.WriteStartElement("g:adult");
            writer.WriteString("FALSE");
            writer.WriteEndElement();
        }

        // Unit pricing measure
        if (product.unit_pricing_measure > 0 && product.unit_pricing_base_measure > 0)
        {
            writer.WriteStartElement("g:unit_pricing_measure");
            writer.WriteString(product.unit_pricing_measure.ToString() + comparison_unit_code);
            writer.WriteEndElement();
            writer.WriteStartElement("g:unit_pricing_base_measure");
            writer.WriteString(product.unit_pricing_base_measure.ToString() + comparison_unit_code);
            writer.WriteEndElement();
        }

        // Size type
        if (product.size_type != "")
        {
            writer.WriteStartElement("g:size_type");
            writer.WriteString(GetGoogleSizeType(product.size_type));
            writer.WriteEndElement();
        }

        // Size system
        if (product.size_system != "")
        {
            writer.WriteStartElement("g:size_system");
            writer.WriteString(product.size_system);
            writer.WriteEndElement();
        }

        // Energy efficiency class
        if (product.energy_efficiency_class != "")
        {
            writer.WriteStartElement("g:energy_efficiency_class");
            writer.WriteString(product.energy_efficiency_class);
            writer.WriteEndElement();
        }

        // Add the item group id
        if (googleVariants.Count > 0)
        {
            writer.WriteStartElement("g:item_group_id");
            writer.WriteString(product.id.ToString());
            writer.WriteEndElement();
        }

        // Add google variants
        for (int i = 0; i < googleVariants.Count; i++)
        {
            // Get the value pair
            string[] valuePair = googleVariants[i];

            writer.WriteStartElement(valuePair[0]);
            writer.WriteString(valuePair[1]);
            writer.WriteEndElement();
        }

        // Write the end of the item tag
        writer.WriteEndElement();
    } // End of the WriteProductItem method
示例#9
0
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get all the form values
            Int32 id = Convert.ToInt32(collection["txtId"]);
            decimal percent = 0;
            decimal.TryParse(collection["txtPercent"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out percent);

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the value added tax
            ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(id);
            bool postExists = true;

            // Check if the value added tax exists
            if (valueAddedTax == null)
            {
                // Create an empty value added tax
                valueAddedTax = new ValueAddedTax();
                postExists = false;
            }

            // Update values
            valueAddedTax.value = percent;

            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors in the value added tax
            if (valueAddedTax.value < 0 || valueAddedTax.value > 9.99999M)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_range"), tt.Get("percent"), "9.99999") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the static text
                if (postExists == false)
                {
                    // Add the value added tax
                    ValueAddedTax.Add(valueAddedTax);
                }
                else
                {
                    // Update the value added tax
                    ValueAddedTax.Update(valueAddedTax);
                }

                // Redirect the user to the list
                return Redirect("/admin_value_added_taxes" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.ValueAddedTax = valueAddedTax;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method
示例#10
0
    } // End of the GetCartAmounts method

    /// <summary>
    /// Get a list of order rows
    /// </summary>
    /// <param name="cartItems">A list of cart items</param>
    /// <param name="vatCode">The current vat code</param>
    /// <param name="languageId">A language id</param>
    /// <param name="decimalMultiplier">A decimal multiplier</param>
    /// <returns>A list with order rows</returns>
    public static List <OrderRow> GetOrderRows(List <CartItem> cartItems, byte vatCode, Int32 languageId, Int32 decimalMultiplier)
    {
        // Create order rows
        List <OrderRow> orderRows = new List <OrderRow>(10);

        // Loop all the cart items
        Int16 rowCounter = 0;

        for (int i = 0; i < cartItems.Count; i++)
        {
            // Get data
            Product product = Product.GetOneById(cartItems[i].product_id, languageId);

            // Calculate the freight price
            decimal price        = Math.Round(cartItems[i].unit_price * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            decimal freight      = Math.Round(cartItems[i].unit_freight * decimalMultiplier, MidpointRounding.AwayFromZero) / decimalMultiplier;
            decimal priceFreight = price + freight;

            // Create a new order row and add values to it
            OrderRow orderRow = new OrderRow();
            orderRow.product_code      = AnnytabDataValidation.TruncateString(cartItems[i].product_code, 50);
            orderRow.manufacturer_code = AnnytabDataValidation.TruncateString(cartItems[i].manufacturer_code, 50);
            orderRow.product_id        = product.id;
            orderRow.gtin            = product.gtin;
            orderRow.product_name    = AnnytabDataValidation.TruncateString(cartItems[i].product_name, 100);
            orderRow.vat_percent     = vatCode != 0 ? 0 : cartItems[i].vat_percent;
            orderRow.quantity        = AnnytabDataValidation.TruncateDecimal(cartItems[i].quantity, 0, 999999.99M);
            orderRow.unit_id         = product.unit_id;
            orderRow.unit_price      = AnnytabDataValidation.TruncateDecimal(priceFreight, 0, 9999999999.99M);
            orderRow.account_code    = product.account_code;
            orderRow.supplier_erp_id = product.supplier_erp_id;
            orderRow.sort_order      = rowCounter;

            // Add to the row counter
            rowCounter += 1;

            // Update product buys
            Product.UpdateBuys(product.id, AnnytabDataValidation.TruncateDecimal(cartItems[i].quantity + product.buys, 0, 9999999999.99M));

            // Add the row to the list
            orderRows.Add(orderRow);

            // Get bundle items
            List <ProductBundle> bundleItems = ProductBundle.GetByBundleProductId(product.id);

            // Add all the bundle items
            for (int j = 0; j < bundleItems.Count; j++)
            {
                // Get the product
                product = Product.GetOneById(bundleItems[j].product_id, languageId);

                // Get the value added tax
                ValueAddedTax valueAddedTax = ValueAddedTax.GetOneById(product.value_added_tax_id);

                // Create a new order row and add values to it
                orderRow = new OrderRow();
                orderRow.product_code      = product.product_code;
                orderRow.manufacturer_code = product.manufacturer_code;
                orderRow.product_id        = product.id;
                orderRow.gtin            = product.gtin;
                orderRow.product_name    = product.title;
                orderRow.vat_percent     = vatCode != 0 ? 0 : valueAddedTax.value;
                orderRow.quantity        = bundleItems[j].quantity;
                orderRow.unit_id         = product.unit_id;
                orderRow.unit_price      = 0;
                orderRow.account_code    = product.account_code;
                orderRow.supplier_erp_id = product.supplier_erp_id;
                orderRow.sort_order      = rowCounter;

                // Update product buys
                Product.UpdateBuys(product.id, AnnytabDataValidation.TruncateDecimal(bundleItems[j].quantity + product.buys, 0, 9999999999.99M));

                // Add to the row counter
                rowCounter += 1;

                // Add the row to the list
                orderRows.Add(orderRow);
            }
        }

        // Return the list
        return(orderRows);
    } // End of the GetOrderRows method