Product Dropdown Value String on Product Detail Page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 7 años
Hi everyone,
I created a dropdown on admin product page which works fully great. I also added the string resources for dropdown values.

I am trying to show this values on product detail page but I cannot show the string resources. Any help will be appreciated.

Here is the steps I followed,

1- Created a new cs file for dropdown
nopCommerce_3.80_Source/Libraries/Nop.Core/Domain/Catalog/Stowageunit.cs
namespace Nop.Core.Domain.Catalog
{
    /// <summary>
    /// Represents the ship size
    /// </summary>
    public enum Stowageunit
    {
        /// <summary>
        /// Please Select
        /// </summary>
        PleaseSelect = 0,
        /// <summary>
        /// cbm/MT
        /// </summary>
        cbmMT = 10,
        /// <summary>
        /// cbft/MT
        /// </summary>
        cbftMT = 20,
        /// <summary>
        /// cbm/LT
        /// </summary>
        cbmLT = 30,
        /// <summary>
        /// cbft/LT
        /// </summary>
        cbftLT = 40,
    }
}


2- Added following code to nopCommerce_3.80_Source/Libraries/Nop.Core/Domain/Catalog/Product.cs
 /// <summary>
        /// Stowage Unit Id
        /// </summary>
        public int? StowageunitId { get; set; }
        /// <summary>
        /// Gets or sets the Stowage Factor Unit
        /// </summary>
        public Stowageunit Stowageunits
        {
            get
            {
                return (Stowageunit)this.StowageunitId;
            }
            set
            {
                this.StowageunitId = (int)value;
            }
        }


3- this.Ignore(p => p.Stowageunits); on nopCommerce_3.80_Source/Libraries/Nop.Data/Mapping/Catalog/ProductMap.cs and .ForMember(dest => dest.Shipsizes, mo => mo.Ignore()) on nopCommerce_3.80_Source/Presentation/Nop.Web/Administration/Infrastructure/Mapper/AutoMapperConfiguration.cs

4- Added on my ProductModel and _CreateOrUpdate.Info.cshtml and entered the language strings for enums.

After these steps,this works completely fine on Admin.

5- To show on product detail page added the StowageunitId to the ProductDetailsMotel in Nop.Web and in ProductTemplate.Simple.cshtml added following lines;

@if (Model.stowagefactor.HasValue && Model.stowagefactor.Value > 0)
                        {
                            <div class="additional-details">
                                <span class="label">@T("Admin.Catalog.Products.Fields.stowagefactor"):</span>
                                @Html.Raw(Model.stowagefactor)
                                @Html.Raw(((Stowageunit)Model.StowageunitId))
                            </div>


This gives me the cbmMT instead of the language string cbm/MT

When I try DisplayFor it gives me the integer like 10, 20, etc.

How can I display the language string on product detail page?
Hace 7 años
anyone?
Hace 7 años
dianoche wrote:
@Html.Raw(Model.stowagefactor)

With that line you're outputting the stowagefactor property of the product model so I'd guess you just need to look up the resource string that relates to it with something like:

@T("Whatever.Your.Resource.Name.Is." + Model.stowagefactor)

Where you have a resource string with a Name of Whatever.Your.Resource.Name.Is.cbmMT and value cbm/MT
Hace 7 años
Or is it the stowage unit you're trying to get the string resource for? Either way the same approach should work, you've just got to build up the correct resource name string to pass to the @T function.
Hace 7 años
petemitch wrote:
Or is it the stowage unit you're trying to get the string resource for? Either way the same approach should work, you've just got to build up the correct resource name string to pass to the @T function.


Hi Pete,
Thank you for the reply. Stowage unit comes from following line automatically

@Html.Raw(((Stowageunit)Model.StowageunitId))

Is there any other approach? This didn't work :)
Hace 7 años
dianoche wrote:
Stowage unit comes from following line automatically

@Html.Raw(((Stowageunit)Model.StowageunitId))

...and that outputs "cbmMT" right? What's the Name of the resource string you want to retrieve instead?
Hace 7 años
petemitch wrote:
Stowage unit comes from following line automatically

@Html.Raw(((Stowageunit)Model.StowageunitId))
...and that outputs "cbmMT" right? What's the Name of the resource string you want to retrieve instead?


I want it to be cbm/MT instead of cbmMT.
My resource string is enums.nop.core.domain.catalog.stowageunit.cbmmt
Hace 7 años
dianoche wrote:
Stowage unit comes from following line automatically

@Html.Raw(((Stowageunit)Model.StowageunitId))
...and that outputs "cbmMT" right? What's the Name of the resource string you want to retrieve instead?

I want it to be cbm/MT instead of cbmMT.
My resource string is enums.nop.core.domain.catalog.stowageunit.cbmmt

So if you put:
@T("enums.nop.core.domain.catalog.stowageunit.cbmmt")
in your view markup somewhere it should output "cbm/MT" in the generated HTML.

If that works then you just need to dynamically generate the string to pass to the @T helper function with something like:
@T("enums.nop.core.domain.catalog.stowageunit." + (Stowageunit)Model.StowageunitId)

So all that's happening there is it's getting the the Stowageunit enum string associated with the StowageunitId and appending it to the "enums.nop.core.domain.catalog.stowageunit." string to get the full resource name, which it then passes to the @T helper to get the localized resource value.
Hace 7 años
petemitch wrote:
Stowage unit comes from following line automatically

@Html.Raw(((Stowageunit)Model.StowageunitId))
...and that outputs "cbmMT" right? What's the Name of the resource string you want to retrieve instead?

I want it to be cbm/MT instead of cbmMT.
My resource string is enums.nop.core.domain.catalog.stowageunit.cbmmt
So if you put:
@T("enums.nop.core.domain.catalog.stowageunit.cbmmt")
in your view markup somewhere it should output "cbm/MT" in the generated HTML.

If that works then you just need to dynamically generate the string to pass to the @T helper function with something like:
@T("enums.nop.core.domain.catalog.stowageunit." + (Stowageunit)Model.StowageunitId)

So all that's happening there is it's getting the the Stowageunit enum string associated with the StowageunitId and appending it to the "enums.nop.core.domain.catalog.stowageunit." string to get the full resource name, which it then passes to the @T helper to get the localized resource value.


Works great. Thank you Pete!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.