1

I'm working on my first Magento 2 project, and I'm slowly getting to grips with how everything works.

Then, I reach the point where I need to customize the checkout page and it throws a massive curveball, replacing the phtml/XML template system I've gotten used to with a completely different Knockout one.

In a nutshell, I store some personalization data in the quote item's "additional_data" field, and I need to show it in the checkout order summary.

I have successfully overridden /frontend/web/template/summary/item/details.html with my own custom template, but I have no idea how to get the data from the product object and display it using Knockout.

Has anyone done anything similar they wish to share to get me started?

1 Answer 1

1

You should be able to access the quote's 'additional data' here: window.checkoutConfig.quoteItemData[0].additional_data

So in your knockout template, you might have something like this:

<span data-bind="text: window.checkoutConfig.quoteItemData[0].additional_data"></span>
5
  • That's superb, thanks so much. I couldn't find a single resource on the net and you answered it in 3 lines.
    – Geat
    Oct 24, 2016 at 21:29
  • My additional_data field is actually a JSON encoded string with a bunch of information in it. What would be the "proper" way of specifying some sort if callback function so that the string is parsed before being output, rather than just displayed as a string using data-bind: text?
    – Geat
    Oct 24, 2016 at 21:30
  • A quick and easy way to do that would be to just call JSON.parse within the text bind like text: JSON.parse(window.checkoutConfig.quoteItemData[0].additional_data).someField. Perhaps a better way is to extend the JS component that your template is using by adding the logic for parsing your json and assigning it to variables for easy use in the template. Oct 24, 2016 at 23:02
  • Thanks again! It's a pretty steep learning curve for someone who primarily uses Drupal.
    – Geat
    Oct 24, 2016 at 23:32
  • How to use your answer when multiple products in cart, quoteItemData[0] ? Nov 21, 2016 at 11:43

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.