Hi, I need to ask for some help. I'm modifying a Couch site to use https://snipcart.com/, they seem to work well together. However, I'm getting a bit out of my depth with webhooks and JSON. I have belatedly discovered that my client uses a a fulfilment partner, and they need to be able to access the snipcart data. So I have set up a webhook, which seems to work. I can receive the JSON, and have managed to store it in Couch.
My problem is that I have only ever used JSON in a very limited way. I can access some of the data, but I am struggling the deeper I get. This post has been helpful viewtopic.php?f=5&t=10892#p27841
Here is the JSON (don't worry about the formatting - it's fine, I have deleted a lot for demonstration purposes)
And here is my code:
Getting and displaying Name, description, price, quantity is fine. My problem is - I can't figure out how to extract the sub-array stored in Custom Fields. I'm sure it's not a big deal, I'm just not great with dealing with data like this - it makes my head hurt... Any assistance would be great!
My problem is that I have only ever used JSON in a very limited way. I can access some of the data, but I am struggling the deeper I get. This post has been helpful viewtopic.php?f=5&t=10892#p27841
Here is the JSON (don't worry about the formatting - it's fine, I have deleted a lot for demonstration purposes)
- Code: Select all
{
"eventName":"order.completed",
"mode":"Test",
"createdOn":"2021-03-15T16:36:30.7898192Z",
"content":{
"discounts":[],
"items":[
{
"name":"Product 1",
"price":55,
"quantity":1,
"id":"387",
"customFields":[]
},
{
"name":"Product 2",
"price":30,
"quantity":1,
"id":"403",
"customFields":[
{
"name":"Size",
"placeholder":"",
"displayValue":"Large",
"type":"dropdown",
"options":"Small|Medium|Large",
"required":false,
"value":"Large",
"operation":null,
"optionsArray":["Small","Medium","Large"]}],
"unitPrice":30,
"hasDimensions":false,"hasTaxesIncluded":false,
"totalPriceWithoutDiscountsAndTaxes":30}
]
}
}
And here is my code:
- Code: Select all
<cms:capture into='orders' is_json='1' ><cms:show test_field /></cms:capture>
<cms:each orders.content.items>
<cms:if "<cms:is_array item />">
<cms:each item>
<cms:if key="name">Item: <cms:show item/><br></cms:if>
<cms:if key="description">Desc: <cms:show item/><br></cms:if>
<cms:if key="price">Price: <cms:show item/><br></cms:if>
<cms:if key="quantity">Quantity: <cms:show item/><br></cms:if>
<cms:if (key="customFields") && ("<cms:is_array item />")>
<cms:each item>
<cms:if key="name">Options: <cms:show item/><br></cms:if> //Nothing shows here
-- <cms:show key /> (<cms:array_count item />)<br> //Shows -- 0 (9) (Why is key 0? This is maybe where my problem is)
</cms:each>
</cms:if>
</cms:each>
</cms:if>
<hr>
</cms:each>
Getting and displaying Name, description, price, quantity is fine. My problem is - I can't figure out how to extract the sub-array stored in Custom Fields. I'm sure it's not a big deal, I'm just not great with dealing with data like this - it makes my head hurt... Any assistance would be great!