Add second name for products

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hello guys
I want to know is there any way to add another field for second product name? For instance, I want to have 2 names for my products, first one for the English name and second one for the Arabic name, Like this:

Probook 4540s
بروبوک 4540اس

Is there any way to add another field(Below the Current Product name field) in product management section (Catalog>Products>Manage products) to write the second name? Or at least, separate these two names by a "Special Character" in the current Product Name field? Regarding to this aim that I want to show these two names in two separate lines and not in one line.

I will appreciate any help
Thanks
9 years ago
If you are not using Short Description, you may use it for this purpose
9 years ago
Dear eadameg
Thanks for your reply. Yes but the point is that I want to show the second name right below the current name and in that format. For other reasons like search, name display in category(grid, list) and so on.... I want to add the new field as a second name... The main reason is to have both names every where that the current name field exist...
9 years ago
iman.m wrote:
Hello guys
I want to know is there any way to add another field for second product name? For instance, I want to have 2 names for my products, first one for the English name and second one for the Arabic name, Like this:

Probook 4540s
بروبوک 4540اس

Is there any way to add another field(Below the Current Product name field) in product management section (Catalog>Products>Manage products) to write the second name? Or at least, separate these two names by a "Special Character" in the current Product Name field? Regarding to this aim that I want to show these two names in two separate lines and not in one line.

I will appreciate any help
Thanks


Hi,

Quick solution to resolve the issue (add code directly to the view):

- Go to the "Presentation\Nop.Web\Views\Catalog\ProductTemplate.Simple.cshtml" file

- Inside the "@{ ... }" block, add following lines of code:
  

  var productService = EngineContext.Current.Resolve<IProductService>();
  var languageService = EngineContext.Current.Resolve<ILanguageService>();

  var secondLanguage = languageService.GetAllLanguages().Where(i => i.UniqueSeoCode.Equals("vn", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
  var product = productService.GetProductById(Model.Id);
  


  In the above code block, I had 2 languages enabled (English and Vietnamese).
  The second language I want to add here is Vietnamese, so that, I will find it by the "UniqueSeoCode" field's value (it is "vn").

- Go to the code block that render the product's name, add the product's name in the second language:
  + Before:
  

  <h1 class="heading" itemprop="name">@Model.Name</h1>
  

  + After:
  

  <h1 class="heading" itemprop="name">@Model.Name @product.GetLocalized(i => i.Name, secondLanguage.Id, false, false)</h1>
  
9 years ago
Dear Ima9ines
Thanks for your reply

I have edited the cshtml file as you said, but when I go to Product page, the error page comes up.
In the Log page,  it says :  

D:\nop\Views\Product\ProductTemplate.Simple.cshtml(16): error CS0246: The type or namespace name 'IProductService' could not be found (are you missing a using directive or an assembly reference

D:\nop\Views\Product\ProductTemplate.Simple.cshtml(18): error CS0103: The name 'languageService' does not exist in the current context
D:\nop\Views\Product\ProductTemplate.Simple.cshtml(20): error CS0103: The name 'productService' does not exist in the current context


Any solution for this one? Doesn't it need any other modifications in other files?

It will be appreciated if you send me a copy of your file, so I can replace it with mine.
This is my Email: [email protected]
thanks for you Help........
9 years ago
iman.m wrote:
Dear Ima9ines
Thanks for your reply

I have edited the cshtml file as you said, but when I go to Product page, the error page comes up.
In the Log page,  it says :  

D:\nop\Views\Product\ProductTemplate.Simple.cshtml(16): error CS0246: The type or namespace name 'IProductService' could not be found (are you missing a using directive or an assembly reference

D:\nop\Views\Product\ProductTemplate.Simple.cshtml(18): error CS0103: The name 'languageService' does not exist in the current context
D:\nop\Views\Product\ProductTemplate.Simple.cshtml(20): error CS0103: The name 'productService' does not exist in the current context


Any solution for this one? Doesn't it need any other modifications in other files?

It will be appreciated if you send me a copy of your file, so I can replace it with mine.
This is my Email: [email protected]
thanks for you Help........


Hi,

Please add following "@using" block at the top of the "ProductTemplate.Simple.cshtml" file:

@using Nop.Services.Catalog;
@using Nop.Services.Localization;
9 years ago
Thank you soooooo much. It become what i want.....
Just a question: Now when I search by each of these two names, only one of these two can be found, I mean the Standard name can be found and the second one does not index and there is no result for second name search.
Any Idea?
9 years ago
iman.m wrote:
Thank you soooooo much. It become what i want.....
Just a question: Now when I search by each of these two names, only one of these two can be found, I mean the Standard name can be found and the second one does not index and there is no result for second name search.
Any Idea?


Hi,

You can try this:

- Open the "Presentation\Nop.Web\Controllers\CatalogController.cs" file
- Find the following code block (in the "Search" method)

//products
                    products = _productService.SearchProducts(
                        categoryIds: categoryIds,
                        manufacturerId: manufacturerId,
                        storeId: _storeContext.CurrentStore.Id,
                        visibleIndividuallyOnly: true,
                        priceMin: minPriceConverted,
                        priceMax: maxPriceConverted,
                        keywords: model.Q,
                        searchDescriptions: searchInDescriptions,
                        searchSku: searchInDescriptions,
                        searchProductTags: searchInProductTags,
                        languageId: _workContext.WorkingLanguage.Id,
                        pageIndex: command.PageNumber - 1,
                        pageSize: command.PageSize);
                    model.Products = PrepareProductOverviewModels(products).ToList();

- Remove or comment the following line of code:

languageId: _workContext.WorkingLanguage.Id,


With this modification, the "Search" method will search all products without any language (mean that it will search in all available languages).

Hope this help :)
9 years ago
Dear Ima9ines

Thank you for your replies.

The Product name in product page issue have been solved by your help.
Now i have another problem:
My product has 2 names, one in Arabic and another one in English:

"Iphone" in English tab
"آی فون" in Arabic tab
And because its necessary to set a name for Standard, I have set Iphone in it.
Now when I load my store in Arabic language, everything is all right, except that when I search these names, the result is the same, For example when i search "آی فون", it shows the product with its Arabic name:"آی فون" that is correct.
But when I search "Iphone", result shows "آی فون" Again!! that is not correct.In other words, the result is related to webpage language..... not what i search....

I want to show the results in Its language,like: when i search iphone, "Iphone" appears, and when i search "آی فون"  its arabic name(آی فون) appears.

Or if its possible, show both names, for each of its names, for example when "Iphone" or "آی فون" is searched, the result shows both names in two seperate lines, like:

آی فون
Iphone

Another thing is in management, in Bulk edit Menu(Catalog-->Products--> Bulk edit products), I want to show a column beside "name" column, that shows "Local name". Can you help me to add this column, too?
9 years ago
iman.m wrote:
Dear Ima9ines

Thank you for your replies.

The Product name in product page issue have been solved by your help.
Now i have another problem:
My product has 2 names, one in Arabic and another one in English:

"Iphone" in English tab
"آی فون" in Arabic tab
And because its necessary to set a name for Standard, I have set Iphone in it.
Now when I load my store in Arabic language, everything is all right, except that when I search these names, the result is the same, For example when i search "آی فون", it shows the product with its Arabic name:"آی فون" that is correct.
But when I search "Iphone", result shows "آی فون" Again!! that is not correct.In other words, the result is related to webpage language..... not what i search....

I want to show the results in Its language,like: when i search iphone, "Iphone" appears, and when i search "آی فون"  its arabic name(آی فون) appears.

Or if its possible, show both names, for each of its names, for example when "Iphone" or "آی فون" is searched, the result shows both names in two seperate lines, like:

آی فون
Iphone

Another thing is in management, in Bulk edit Menu(Catalog-->Products--> Bulk edit products), I want to show a column beside "name" column, that shows "Local name". Can you help me to add this column, too?


Hi again,

I have solution for you, it likely not perfect fit your requirements, but I think it is acceptable.
Continue with the first modification in above posts. We should modify something more.

Following are steps:

- Edit the "ProductLoadAllPaged" SQL Server procedure
- Find following block of code:

DECLARE
    @SearchKeywords bit,
    @sql nvarchar(max),
    @sql_orderby nvarchar(max)

and then, replace with

DECLARE
    @SearchKeywords bit,
    @sql nvarchar(max),
    @sql_orderby nvarchar(max),
        @oneLanguageCondition nvarchar(max),
        @allLanguagesCondition nvarchar(max)

- Find following block of code:

    --localized product name
    SET @sql = @sql + '

and then, replace with

        SET @oneLanguageCondition = 'AND lp.LanguageId = ' + ISNULL(CAST(@LanguageId AS nvarchar(max)), '0')
        SET @allLanguagesCondition = 'AND lp.LanguageId IN (SELECT l.Id FROM Language AS l)'

    --localized product name
    SET @sql = @sql + '

- Next block

--localized product name
    SET @sql = @sql + '
    UNION
    SELECT lp.EntityId
    FROM LocalizedProperty lp with (NOLOCK)
    WHERE
      lp.LocaleKeyGroup = N''Product''
      AND lp.LanguageId = ' + ISNULL(CAST(@LanguageId AS nvarchar(max)), '0') + '
      AND lp.LocaleKey = N''Name'''
    IF @UseFullTextSearch = 1

replace with

--localized product name
    SET @sql = @sql + '
    UNION
    SELECT lp.EntityId
    FROM LocalizedProperty lp with (NOLOCK)
    WHERE
      lp.LocaleKeyGroup = N''Product'''
        IF @LanguageId = 0
            SET @sql = @sql + @allLanguagesCondition
        ELSE
      SET @sql = @sql + @oneLanguageCondition

        SET @sql = @sql + ' AND lp.LocaleKey = N''Name'''

    IF @UseFullTextSearch = 1

- Next block

--localized product short description
      SET @sql = @sql + '
      UNION
      SELECT lp.EntityId
      FROM LocalizedProperty lp with (NOLOCK)
      WHERE
        lp.LocaleKeyGroup = N''Product'''
            IF @LanguageId = 0
                SET @sql = @sql + @allLanguagesCondition
            ELSE
          SET @sql = @sql + @oneLanguageCondition
            
            SET @sql = @sql + 'AND lp.LocaleKey = N''ShortDescription'''
      
            IF @UseFullTextSearch = 1

replace with

--localized product short description
      SET @sql = @sql + '
      UNION
      SELECT lp.EntityId
      FROM LocalizedProperty lp with (NOLOCK)
      WHERE
        lp.LocaleKeyGroup = N''Product''
        AND lp.LanguageId = ' + ISNULL(CAST(@LanguageId AS nvarchar(max)), '0') + '
        AND lp.LocaleKey = N''ShortDescription'''
      IF @UseFullTextSearch = 1

- Next block

--localized product full description
      SET @sql = @sql + '
      UNION
      SELECT lp.EntityId
      FROM LocalizedProperty lp with (NOLOCK)
      WHERE
        lp.LocaleKeyGroup = N''Product''
        AND lp.LanguageId = ' + ISNULL(CAST(@LanguageId AS nvarchar(max)), '0') + '
        AND lp.LocaleKey = N''FullDescription'''
      IF @UseFullTextSearch = 1

replace with

--localized product full description
      SET @sql = @sql + '
      UNION
      SELECT lp.EntityId
      FROM LocalizedProperty lp with (NOLOCK)
      WHERE
        lp.LocaleKeyGroup = N''Product'''
            IF @LanguageId = 0
                SET @sql = @sql + @allLanguagesCondition
            ELSE
          SET @sql = @sql + @oneLanguageCondition

            SET @sql = @sql + 'AND lp.LocaleKey = N''FullDescription'''

      IF @UseFullTextSearch = 1

- Next block

--localized product tag
      SET @sql = @sql + '
      UNION
      SELECT pptm.Product_Id
      FROM LocalizedProperty lp with (NOLOCK) INNER JOIN Product_ProductTag_Mapping pptm with(NOLOCK) ON lp.EntityId = pptm.ProductTag_Id
      WHERE
        lp.LocaleKeyGroup = N''ProductTag''
        AND lp.LanguageId = ' + ISNULL(CAST(@LanguageId AS nvarchar(max)), '0') + '
        AND lp.LocaleKey = N''Name'''
      IF @UseFullTextSearch = 1

replace with

--localized product tag
      SET @sql = @sql + '
      UNION
      SELECT pptm.Product_Id
      FROM LocalizedProperty lp with (NOLOCK) INNER JOIN Product_ProductTag_Mapping pptm with(NOLOCK) ON lp.EntityId = pptm.ProductTag_Id
      WHERE
        lp.LocaleKeyGroup = N''ProductTag'''
            IF @LanguageId = 0
                SET @sql = @sql + @allLanguagesCondition
            ELSE
          SET @sql = @sql + @oneLanguageCondition

            SET @sql = @sql + 'AND lp.LocaleKey = N''Name'''
      
            IF @UseFullTextSearch = 1

- Update the SQL Server procedure
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.