Additional Shipping Charge

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 12 ans
Hi,
Is there a way to show the additional shipping charge above the regular product price in the product details page?

just like this guy did - http://panika.co.il (go into some product, you will see old price, regular price, then additional shipping price).

I tried my best but I cant get it to work. please guide me I'll love you forever!
Il y a 12 ans
1. Open NopCommerceStore\Modules\ProductPrice1.ascx file
2. Add a new 'lblAdditionalShippingCharge' label control for additional shipping charge
3. Open NopCommerceStore\Modules\ProductPrice1.ascx.cs file
4. Assign appropriate value to 'Text' property of the new 'lblAdditionalShippingCharge' control. (similar to other controls such as 'lblPriceValue')
P.S. Don't forget to recompile the solution
Il y a 12 ans
Andrei, thank you so much.
I'm sorry for not being so easy to teach, but can you please tell me where to put the code in .cs ? there are many "if" and "else" and stuff I dont really know where to put it in the right place.

one more question - after I work on a solution and recompile it, do I need to upload the whole store again to the server? or just the file I edited?


Thank you again!
Amit.
Il y a 12 ans
amit2602 wrote:
I'm sorry for not being so easy to teach, but can you please tell me where to put the code in .cs ? there are many "if" and "else" and stuff I dont really know where to put it in the right place.

Just put it before "if (productVariant.CustomerEntersPrice)"

amit2602 wrote:
one more question - after I work on a solution and recompile it, do I need to upload the whole store again to the server? or just the file I edited?

Upload the following files:
1. Modules\ProductPrice1.ascx file
2. \bin\NopCommerceStore.dll
Il y a 12 ans
Thank you Andrei! I did what you told me to, but it is showing 0.00 for price in all products, it's not showing the additional shipping price as I added in product variants.

here are the codes I did:

ProductPrice1.ascx

<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.ProductPrice1Control"
    CodeBehind="ProductPrice1.ascx.cs" %>
<asp:PlaceHolder runat="server" ID="phOldPrice">
    <%=GetLocaleResourceString("Products.OldPrice")%>&nbsp;
    <asp:Label ID="lblOldPrice" runat="server" CssClass="oldProductPrice" />
</asp:PlaceHolder>
<br />
<asp:Label ID="lblCustomerEnterPrice" runat="server" Visible="false" />
<asp:Label ID="lblPrice" runat="server" Visible="true" />
<asp:Label ID="lblPriceValue" runat="server" CssClass="productPrice" />
<asp:Label ID="lblAdditionalShippingCharge" runat="server" CssClass="shippingPrice" />
<asp:PlaceHolder runat="server" ID="phDiscount">
    <br />
    <%=GetLocaleResourceString("Products.FinalPriceWithDiscount")%>&nbsp;&nbsp;
    <asp:Label ID="lblFinalPriceWithDiscount" runat="server" CssClass="productPrice" />
</asp:PlaceHolder>


ProductPrice1.acsx.cs

//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  https://www.nopcommerce.com/License.aspx.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
//
// Contributor(s): _______.
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.BusinessLogic.Localization;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.Tax;
using NopSolutions.NopCommerce.Common.Utils;
using System.Text.RegularExpressions;
using System.Globalization;
using NopSolutions.NopCommerce.BusinessLogic.Infrastructure;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class ProductPrice1Control: BaseNopFrontendUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            var productVariant = this.ProductService.GetProductVariantById(this.ProductVariantId);
            if (productVariant != null)
            {
                if (!this.SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                        (NopContext.Current.User != null &&
                        !NopContext.Current.User.IsGuest))
                {
                    lblAdditionalShippingCharge.Text = PriceHelper.FormatPrice(AdditionalShippingCharge);
                    if (productVariant.CustomerEntersPrice)
                    {
                        phOldPrice.Visible = false;
                        lblPrice.Visible = false;
                        lblPriceValue.Visible = false;
                        phDiscount.Visible = false;

                        lblCustomerEnterPrice.Visible = true;
                        lblCustomerEnterPrice.Text = GetLocaleResourceString("Products.EnterProductPrice");
                    }
                    else
                    {
                        if (productVariant.CallForPrice)
                        {
                            lblPriceValue.Text = GetLocaleResourceString("Products.CallForPrice");
                            phOldPrice.Visible = false;
                            phDiscount.Visible = false;
                        }
                        else
                        {
                            decimal taxRate = decimal.Zero;
                            decimal oldPriceBase = this.TaxService.GetPrice(productVariant, productVariant.OldPrice, out taxRate);
                            decimal finalPriceWithoutDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                            decimal finalPriceWithDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true), out taxRate);

                            decimal oldPrice = this.CurrencyService.ConvertCurrency(oldPriceBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            decimal finalPriceWithoutDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithoutDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            decimal finalPriceWithDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                            if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                            {
                                lblOldPrice.Text = PriceHelper.FormatPrice(oldPrice);
                                lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                phOldPrice.Visible = true;
                            }
                            else
                            {
                                lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                phOldPrice.Visible = false;
                            }

                            if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                            {
                                lblFinalPriceWithDiscount.Text = PriceHelper.FormatPrice(finalPriceWithDiscount);
                                phDiscount.Visible = true;
                            }
                            else
                            {
                                phDiscount.Visible = false;
                            }

                            if (phDiscount.Visible)
                            {
                                lblPriceValue.CssClass = string.Empty;
                            }
                            else
                            {
                                lblPriceValue.CssClass = "productPrice";
                            }

                            if (phDiscount.Visible || phOldPrice.Visible)
                            {
                                lblPrice.Text = GetLocaleResourceString("Products.FinalPriceWithoutDiscount");
                            }
                            if (this.SettingManager.GetSettingValueBoolean("ProductAttribute.EnableDynamicPriceUpdate"))
                            {
                                string pattern = this.SettingManager.GetSettingValue("ProductAttribute.PricePattern", "(?<val>(\\d+[\\s\\,\\.]?)+)");
                                string replacement = String.Format("<span class=\"price-val-for-dyn-upd-{0}\">${{val}}</span> ", productVariant.ProductVariantId);

                                if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                                {
                                    lblFinalPriceWithDiscount.Text = Regex.Replace(lblFinalPriceWithDiscount.Text, pattern, replacement);
                                }
                                else
                                {
                                    lblPriceValue.Text = Regex.Replace(lblPriceValue.Text, pattern, replacement);
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            if(this.SettingManager.GetSettingValueBoolean("ProductAttribute.EnableDynamicPriceUpdate"))
            {
                var productVariant = this.ProductService.GetProductVariantById(this.ProductVariantId);
                if(productVariant != null && !productVariant.CallForPrice)
                {
                    decimal taxRate = decimal.Zero;
                    decimal finalPriceWithoutDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                    decimal finalPriceWithoutDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithoutDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    decimal finalPriceWithDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true), out taxRate);
                    decimal finalPriceWithDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    float val = (float)(finalPriceWithoutDiscountBase != finalPriceWithDiscountBase ? finalPriceWithDiscount : finalPriceWithoutDiscount);
                    string key = String.Format("PriceValForDynUpd_{0}", productVariant.ProductVariantId);
                    string script = String.Format(CultureInfo.InvariantCulture, "var priceValForDynUpd_{0} = {1};", productVariant.ProductVariantId, val);

                    Page.ClientScript.RegisterClientScriptBlock(GetType(), key, script, true);
                }
            }
            base.OnPreRender(e);
        }

        public int ProductVariantId
        {
            get
            {
                object obj2 = this.ViewState["ProductVariantId"];
                if (obj2 != null)
                    return (int)obj2;
                else
                    return 0;
            }
            set
            {
                this.ViewState["ProductVariantId"] = value;
            }
        }

        public decimal AdditionalShippingCharge { get; set; }
    }
}


Where am I wrong?
Il y a 12 ans
Any last minute help Andrei? I'm really stuck here.
Il y a 12 ans
It's showing 0 because your 'AdditionalShippingCharge' is always 0. Replace:
lblAdditionalShippingCharge.Text = PriceHelper.FormatPrice(AdditionalShippingCharge);

with the following code:
lblAdditionalShippingCharge.Text = PriceHelper.FormatPrice(productVariant .AdditionalShippingCharge);


P.S. And remove your new 'AdditionalShippingCharge' property at the end of the class
Il y a 12 ans
Andrei - THANK YOU!!
Thank you! Thank you!

(btw - it worked :))
Il y a 12 ans
Is there a way to do this with version 2.5?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.