Close

Put a product collection on just one page?

adwebdev
8 years ago
#12828 Quote
Avatar
  • 1
Is there any way to put a product collection on just one specific page? (topic)

Thanks!
anton_ivanov
8 years ago
#12832 Quote
Avatar
  • Moderator
  • 277
Hello,

You can put a product collection on a specific topic page but that requires a bit of code modifications.

You will need to add a custom widget zone that will be set to display the product collections on your topic page.
To add a widget zone you will firstly need to go to Plugins\SevenSpikes.Nop.Plugins.SmartProductCollections\SupportedWidgetZones.xml. You will need to add your widget zone there.

After that you will need to go to Views\Topic\TopicDetails.cshtml and add your widget zone by placing the following line of code wherever you want the product collections to appear:
@Html.Widget("your_widget_zone_name")

After that you will simply need to create a product collection and select the widget zone you created.
This will, however, display the product collections on all of the topic pages. In order to display it on only one topic page you will need to write some code that will check if you are on the correct topic page. It should be something like that :

@if (Model.SystemName.Equals("YourTopicName"))
{
    Html.Widget("your_widget_zone_name");
}


Note: I need to warn you that there are complications that come with modifying the nopCommerce code. During updates, you will need to merge all your changes with the files of the new version of nopCommerce. Also, our support can`t help you with problems that occurred because of modification or customization of the source code.
Regards,
Anton Ivanov
Nop-Templates.com
Cbauto
3 years ago
#21694 Quote
Avatar
  • 1
Really can't get this to work getting the following error:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
h:----->\TopicDetails.cshtml

'IHtmlHelper<TopicModel>' does not contain a definition for 'Widget' and no extension method 'Widget' accepting a first argument of type 'IHtmlHelper<TopicModel>' could be found (are you missing a using directive or an assembly reference?)

I've copied the above exactly and inserted the correct names. What could be the error?
todor.atanasov
3 years ago
#21707 Quote
Avatar
  • Moderator
  • 249
Cbauto wrote:
Really can't get this to work getting the following error:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
h:----->\TopicDetails.cshtml

'IHtmlHelper<TopicModel>' does not contain a definition for 'Widget' and no extension method 'Widget' accepting a first argument of type 'IHtmlHelper<TopicModel>' could be found (are you missing a using directive or an assembly reference?)

I've copied the above exactly and inserted the correct names. What could be the error?


Greetings,

I assume that you are using a more recent version of nopCommerce. When you modify the TopicDetails.cshtml template, instead of adding:

@if (Model.SystemName.Equals("YourTopicName"))
{
    Html.Widget("your_widget_zone_name");
}


You now have to use (in 4.40 nopCommerce):

@if (Model.SystemName.Equals("YourTopicName"))
{
    @await Component.InvokeAsync("Widget", new { widgetZone = "your_widget_zone_name" })
}


Please let me know if you need any further advice or if you are using a version where the above code does not work.
Best regards,
Todor Atanasov
Nop-templates.com