Developer forum

Forum » Development » Linking products to items

Linking products to items

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have an ecommerce site that features case studies. We need to be able to link to specific case studies from a product details page.

What's the best way to go about this? It doesn't have to be all standard functionality, I am OK with implementing anything using the Extensibility API if I have to.

Some general guidance or ideas would be much appeciated.

Imar


Replies

 
Vladimir
Reply

Hi Imar, 

theare is a new type of item field "Product" in DW 8.4.1

It allows to select ecom product/group

 

Best regards,

Vladimir

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Vladimir,

Thanks for that. That helps somewhat because I can then tie products to an item. But what about the other way around? How would I display the selected items for a product?

Imar

 
Vladimir
Reply

The other way is:

You can select Items(located on pages/paragraphs) for product by using link field.

And display then in product details by using product template extender + ItemPublisher.Frontend.GetContentBySettings(settings)

Hope it helps

Best regards,

Vladimir

 
Vladimir
Reply
This post has been marked as an answer

ps: example:

ItemPublisher.Frontend module = new ItemPublisher.Frontend();
t.SetTag("MyItem", module.GetContentBySettings("ItemType:MyItem;ItemId:11;DetailsTemplate:ItemPublisher/Details/Details.html;ItemFields:Field1,Field2;"));

 

 

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

This looks interesting. Is the ItemId=11 something I would be able to retrieve from the selected product from the custom field?

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

And another question: where does the ItemPublisher live? I looked in Dynamicweb.dll and Dynamicweb.Modules.dll but can't find it. Is all of this new for 8.4.1

If so, what's an alternative I can use today?


Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Never mind that last question Found it. Thought it was a type, but it's a namespace.

 

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Vladimir,

I think I am close, but not completely there yet. I have the following code:

using Dynamicweb.eCommerce.Products;
using Dynamicweb.Modules.ItemPublisher;

namespace Pc.Guru.Extenders
{
  public class ProductTemplateExtender2 : ProductTemplateExtender
  {
    public override void ExtendTemplate(Dynamicweb.Rendering.Template template)
    {
      var value = this.Product.GetCategoryValue("Configurable_Servers", "Link_to_item");
      if (value!=null)
      {
        var id = value.ToString().Split(new char[] {'='})[1]; // Contains something like 772, the ID of my item based page

        var module = new Frontend();
        template.SetTag("MyItem", module.GetContentBySettings("ItemType:Test2;ItemId:" + id + ";DetailsTemplate:/Templates/ItemPublisher/Details/Details.html;ItemFields:Name;"));
      }
    }
  }
}

Test2 is the name of my item, I can also see that ID has a valid value for the item based page (that BTW does show up using a regular Item Publisher module). I also tried various paths to the templates (including your suggestion of ItemPublisher/Details/Details.html) but no matter what I try, the call to GetContentBySettings returns an empty string.

Any idea what I am doing wrong?  I am testing this on DW 8.4.0.17

Thanks!

Imar

 
Vladimir
Reply
This post has been marked as an answer

Hi Imar!

sorry, example is deprecated a little: instead of ItemId you should now use SourceItemEntry parameter.

(yes function is pretty "low lewel" , however it was created to work with tags Item.Render / Item.Renderlist)

ItemFields - a list of comma separated field's systemnames (in latest version it allows to use "*" for all fields)

And  latest notice: SourceItemEntry - it should be the id of item. But you store in product field the id of page with item

So you should to create a page at first and use it:

var page = Page.GetPageById(id);

var itemType = page.ItemType;

var itemEntry = page.ItemId;

Best regards,

Vladimir

 

 

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Vladimir,

That worked great. Thank you!

Is this an internal solutuon or is this an officially supported way to get data? Don't want to run the risk of breaking things on an upgrade of DW.

Imar

 
Vladimir
Reply

Hi!

I am very glad :)

It is absolutelly officially and legally :)

Kind regards,

Vladimir

 

You must be logged in to post in the forum