1

In my shop, I have two different kinds of products.type items and my products have variants.

For one of products type, I would like to show the note field in the cart.

My product types are:

  • products
  • options

For product type options, I don't want to show the note field.

How can I set this up?

Tried this without success.

{% for item in cart.lineItems %}
<form method="POST">
<input type="hidden" name="action" value="commerce/cart/updateLineItem">
<input type="hidden" name="lineItemId" value="{{ item.id }}">

{% if product.type('products') %}
<input class="form-control" type="text" placeholder="Productsort"  name="note" value="{{ item.note }}" required>
{% endif %}
<input class="form-control" type="submit" class="button" value="Bijwerken"/>
</form>
{% endfor %}
1

I think you can do something like;

{% if product.type('products') %}
    code to show notes field
{% endif %}

See the product model docs here https://craftcommerce.com/docs/product-model

The note attribute is part of the lineitem model so you should be able to show it.

https://craftcommerce.com/docs/line-item-model#note

The following should work.

{% for item in order.lineitems %}
    {{ item.note }}
{% endfor %}

You could try naming your input field like so;

<input class="form-control" type="text" placeholder="Productsort"  name="item[note]" value="{{ item.note }}" required>

I'd need to test this though. I've done something along these lines but can't remember exactly what I did.

  • That is what was my first thought too. But the note element is in the cart.lineItems and maybe that is why it is not working? – John Stevens Feb 10 '18 at 12:43
  • I misunderstood what you were trying to do. You want to show a note that has already been added to the item within the cart view right? – foamcow Feb 10 '18 at 12:47
  • Yes that is correct. – John Stevens Feb 10 '18 at 12:49
  • I've updated my answer – foamcow Feb 10 '18 at 12:57
  • Actually, you're doing it right. Is the problem that the note isn't being stored or is it simply that you are having problems with the condition to show/hide the note field? – foamcow Feb 10 '18 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.