How to add custom fields for products in Craft Commerce and output them in the cart You can add a note field for a product on the 'Add to Basket' form in Craft Commerce, and output this on the basket page using {{ item.note }}

So I'm using the note field field to record the page URL for the product, so I can link back to the product page for each line item in the basket.

However, I'd rather use a custom field or a dynamic field to do this instead. Is this possible? If so, how?

I've tried creating a dynamic field named 'test-page-url', but that didn't work when trying to output {{ item.testPageUrl }} on the basket page. I got this error: 


  Craft\Commerce_LineItemModel and its behaviors do not have a method or
  closure named "testPageUrl".


I also tried creating a new product field (productPageUrl) and using this name, but that didn't work either. I got this error when trying to use {{ item.productPageUrl }} on the basket page: 


  Craft\Commerce_LineItemModel and its behaviors do not have a method or
  closure named "productPageUrl".


Thanks for any help in advance.
Ok, I think your thinking on this stuff is a little wrong at the moment.  

The way Commerce works is that when you add to a cart, it creates a lineItem.  That data model holds basic stuff like qty and a description and so on, enough to just manage and print out the basics of the cart.  However, it also  (for each lineItem) maintains a reference to the purchasable itself - with this purchasable being a purchasable variant (either a products defaultVariant if it is a non-variant product, or the actual variant chosen if it is a variant product).

From this purchasable, you can get back to the full product and/or variant model.

So, you don't actually need any custom fields to get the product's url.  You can print it simply  by working back from the lineitem to the product or variant as you need, using:

lineItem.purchasable.product.url - for the product url
lineItem.purchasable.url - for a specific variant url

In more general terms, in Commerce settings, you can add as many fields to products as you like, and indeed you can also add custom fields to variants.  It's hugely powerful.  And from then on you can get to those fields using the same approach:

lineItem.purchasable.product.fieldHandle - for product fields
lineItem.purchasable.fieldHandle - for variant fields.

The Commerce example templates are very handy for figuring this stuff out, and it's well worth spending a couple hours with the default Commerce install and those templates to see how it all hangs together.