Developer forum

Forum » Templates » Print name of unit

Print name of unit

Per Ljung
Reply
Hi!

How do you get the name of the default unit for a product in Ecom? The default unit for my products is 'ML' and I want to display that.

Is there a way to do this?

Replies

 
Vladimir
Reply
Hi Per!

  <!--@LoopStart(Units)-->
    <!--@If(Ecom:VariantOption.Selected=='SELECTED')-->
        <br /><br />
        <h2 class="h2">Default Unit</h2>
        <!--@Ecom:VariantOption.ID-->
        <!--@Ecom:VariantOption.Name-->   
        <!--@Ecom:VariantOption.Selected-->   
    <!--@EndIf-->
  <!--@LoopEnd(Units)--> 

Best regards,
Vladimir

 
Per Ljung
Reply

But how do you do this in xslt?

Best regards,
Per
 
Per Ljung
Reply

Hi!

Your code does not work. The unit of a product is there when you look on the product card and choose Store/Warehouse, but nothing is printed when I run this loop.

Do I have to make a setting or something?

Best regards,
Per
 
Morten Bengtson
Reply
Things to check:
  1. Is the unit available in the current language? (management center > ... > product units)
  2. Is a default unit selected on the product (dropdown)? (edit product > stock)
  3. Is the unit active on the product (checkbox)? (edit product > stock)
...and make sure you actually save the settings - sometimes i forget that part :)
 
If all of the above is done and it still doesn't work, the problem must be your template.

/Morten
 
Per Ljung
Reply

Hi!

Question 1: yes

Question 2: There is nothing to select when you look in product -> stock, just a list with the columns "Unit", "Stock", "Weight" and "Size".

Question 3: There is nothing to activate, no checkbox.

Best regards,
Per
 
Nicolai Høeg Pedersen
Reply
Hi Per

I think it would help if we could get a url so we can see your setup.

 
Per Ljung
Reply

 

I just emailed you the url.
 
Nicolai Høeg Pedersen
Reply
I've asked someone have a look.
 
Vladimir
Reply
Hi Per!

You really don't have section 'unit' on the stock tab!O_O
As I understand, this error is due to the fact that in the table 'EcomVariantsOptions' you have the unit 'tum' with id = "
Please correct id for this unit.

Best regards,
Vladimir



 
Per Ljung
Reply


Hi!

Now it's correct.

But nothings is printed when I run this:
 

<xsl:for-each select="loop[@name='Units']/item">
                <xsl:value-of select="Ecom.VariantOption.Name" disable-output-escaping="yes" />
              </xsl:for-each>

 

It doesn't go through the loop at all.
 

Best regards,
Per

 
Per Ljung
Reply

Is it possible to get any help on this?

Best regards,
Per
 
Vladimir
Reply
Hi Per!
Do you add Units in availableloops variable?:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
    <xsl:param name="html-content-type"/>
    <xsl:variable name="availableloops" select="Units" />
If yes, show me please your template)

Best regards,
Vladimir


 
Per Ljung
Reply

No, it does not work. Look in Templates/Ecom/ProductList/list.html.xslt

The loop is placed inside the product loop, I've even tried with adding static text in the unit loop so that I can see it loops, but nothing is printed.

Best regards,
Per
 
Vladimir
Reply
Hmm... This loop isn't available for product list template, only in the product template..
So to get default unit  in productlist you should use extender.
Something like:
    public class MyProductTemplateExtender : ProductTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
        {
            foreach(VariantOption unit in product.UnitList)
            {
                if (unit.ID == product.DefaultUnitID){
                       template.SetTag("Ecom:Product.DefaultUnitName", unit.Name);
                }
            }
        }
    }
Best regards,
Vladimir


 

You must be logged in to post in the forum