Not displaying duplicate items from in an auto slot

Hi,

We run an ecommerce site with products grouped (via folders) in categories and sub-categories. Each cat/sub-cat page has a “view all products in this category” link which displays all product content items in that folder, and in the case of each main category it pulls the product content items from all sub-categories also.

We want to be able to duplicate products across the categories where appropriate. However, if we duplicate a product across sub-categories that are in the same main category, that item will be duplicated in the appropriate “all products” page.

Where this occurs with non product items I have simply coded the slot rather than use a snippet template, for example.

#initslot(“someslot” “someparams”)
#foreach $result in $sys.currentslot.relresults
check if current result is different to last result and do some template code
#end

I’d quite happily do this with the product content items, except I need to call a slot on the product items template that contains related images and grab the product image.

So my questions are:

  1. How do I init the images slot assuming I’m following the code above.
  2. Is there another way of doing this using the conventional #slot(“someslot” “someparams”) and snippet templates instead.

Hope that makes sense, I’m feeling slightly frazzled today.

Thanks,

Damien

We have been able to do something similar, but you need to store the results of the search for products as soon as you have initialised the slot, before calling slots to find images for each product. That is because $sys.currentslot.relresults contains, as its name implies, the results of the more recently initialised slot. Try something like this:


#initslot("someslot" "someparams")
#set($products = $sys.currentslot.relresults)
#foreach($result in $products)
*check if current result is different to last result*
*call slot to find image for each product*
#end

Andrew.

That makes sense. But how do I go about initialising the images slot on a template used by the content items returned by the first initslot ($products)?

Just call #initslot(), or #slot() or #slot_simple() for that matter.

Ah, simpler than I was expecting.

Thanks.

Ok, I was right to think it wouldn’t be that easy.

I was just about to start coding this and realised that callling #initslot a second time, isn’t going to work in the example we’ve been working on.


#initslot("someslot" "someparams")
#set($products = $sys.currentslot.relresults)
#foreach($product in $products)
   *check if current result is different to last result*
   #initslot("imageslot" "params")
   #set($images = $sys.currenslot.relresults)
   #foreach($image in $images)
      *display image
   #end
#end

This code is being called from a template for a category page, the “imageslot” does not exist in this template, it exists in the default template for the product content item represented by $product. So the following line:


#initslot("imageslot" "params")

Would result in nothing.

Presumeably, I need to use $user.psoSlotTools.getSlotContents(assemblyitem, slotname, params)?

If so what do I use for assemblyitem? $sys.assemblyItem is the current item being assembled (category), whereas I would hazard a guess that I need to pass an assemblyItem that relates to the current $product in the loop.

Sorry for the bump, but I really need an answer on this one.

Cheers,

Damien

You have to “clone” the Assembly Item ($sys.AssemblyItem.clone()) and then call “setNode()” to set the node in the newly cloned assembly item.

In your case the node is the product item.

Look at the #nodeslot macro, it shows how to do this.

Dave

Many thanks Dave.

I’ll give that a go in the morning.