In the theme settings the end user is able to select a product from a drop down list of all products. This is done in the settings_scheme.json file.
[
{
{
"name": "Home page - Feature Box 2 (Product 1)",
"settings": [
{
"type": "product",
"id": "homepage-grid-product-1"
}
]
}
]
Then using liquid I want to display the name of the product.
On my page I am using the liquid code:
{{ settings.homepage-grid-product-1 }}
This seems to display the SEO url of the product, how can I make the product title display?
I'm sure this is really straightforward, I am still learning and not quite sure what to look up so not been able to find an answer online.
Cheers, DB.
You can always do a handle lookup via the all_products object.
all_products[settings.my-product-handle]
Related
I'm trying to access metafields containing an array that I want to loop over.
I've tried solutions online to no avail. Do you have any suggestions?
This is the JSON.
[
{
"id": 1,
"title": "Why do pets love CBD so much?",
"pub": "ScienceDirect",
"url": "https://www.efsa.europa.eu/en/news/cannabidiol-novel-food-evaluations-hold-pending-new-data"
},
{
"id": 2,
"title": "When will CBD take over the world",
"pub": "Anna Research Institute",
"url": "https://www.efsa.europa.eu/en/news/cannabidiol-novel-food-evaluations-hold-pending-new-data"
}
]
The metafield is article.metafields.custom.source_snippet
In my article template I'm trying to access it via {% assign sources = article.metafields.custom.source_snippet %}
This usually worked with the old "Metafields Guru".
Thanks.
In shopify there are actually two types of JSON metafields: json and json_string.
json_string is the old and deprecated type and json is the new version.
If your metafield was a json_string your code would have worked, but with json to access the actual value you need to add .value so your code should look like this
{% assign sources = article.metafields.custom.source_snippet.value %}
We are using Survey Creator to allow our users to build questionnaires. However, we want to keep it simple and we don't want them to have to deal with pagination.
In other words, in the builder, we want to disable pages (showPagesToolbox = false) and have them create a set of questions all on a single page.
When we present this to respondents, we want them to see a single question per page. I.e. Q1 is on page 1, Q2 is on page 2, etc.
Does the SurveyJS library provide a way of handling this situation, i.e. here are all the questions, show them with N questions per page?
There is an option, whch allows you to automatically display one question per page. To enable this you need to set "questionsOnPageMode": "questionPerPage" on the survey level. Here's an example:
{
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1"
},
{
"type": "checkbox",
"name": "question2",
"choices": [
"item1",
"item2",
"item3"
]
}
]
}
],
"questionsOnPageMode": "questionPerPage"
}
This is also configurable through the SurveyJS creator by opening the "Survey Settings" dialog, then going to the "Navigation" section, and finally setting the "Questions on page mode" value.
Unfortunately at this time there is no option to specify N number of questions per page. The documentation for this setting is here.
I want to hide one of the fields created in Advanced Settings > Account Setup Form (Address Fields) during the Shipping and Billing steps of optimized one-page checkout.
I can the field names/values using this api, but no ID.
https://developer.bigcommerce.com/api-reference/customer-subscribers/v3-customers-api/customer-form-fields/customerformfieldsget
https://api.bigcommerce.com/stores/{{store-hash}}/v3/customers/form-field-values?customer_id=1
gives me this output
{
"data": [
{
"name": "Sales Agent",
"customer_id": 1,
"value": "Unassigned Customer-web (9990)"
}
]
}
When editing in the admin console, it's referred to as FormFieldID
When in the checkout, the markup for this field is contained inside of a custom element, dynamic-form-field with a very predictable name attribute.
What's the deal with this?
<dynamic-form-field
ng-repeat="formField in checkoutAddressCtrl.formFields track by formField.name"
class="dynamic-form-field dynamic-form-field--field_41"
ng-attr-mirror="{{ formField.name === 'addressLine1' &&
checkoutAddressCtrl.hasAutocomplete() ?'google-autocomplete' : null }}"
name="field_41"
field="formField"
on-change="checkoutAddressCtrl.onFieldChange(value, formField.name)"
value="checkoutAddressCtrl.address[formField.name]"
mirror="">
Why don't you use some css?
[name="field_41"] {
display: none;
}
I believe from memory you can add a css class for the custom field in the Big Commerce control panel. So give it a class of, say, nodisplay, then add
.nodisplay {display: none}
to your store's css.
Suppose we are building one-page app with two views: list view and detail view.
In list view, we present a list of objects with just their names and maybe some more minimal data.
In detail view, we present all possible fields of particular object.
Hence the question: when we GET /api/items/, should we or should not to JSON-encode all fields of the objects listed, or just those presented in list view?
In other words, if we show list of food like
Name Price
Potato 1
Milk 2
does our API need to respond with JSON like this:
{
[
{
"name": "Potato",
"quantity": "1 kg",
"origin": "Egypt",
"manufacturer": "Egypt Farmers",
"price": 1,
"packaging": "String bag",
"_type": "Food"
},
{
"name": "Milk",
"quantity": "1 litre",
"origin": "Finland",
"manufacturer": "Valio",
"price": 2,
"packaging": "Tetra Pak",
"_type": "Food"
},
]
}
or like this:
{
[
{
"name": "Potato",
"price": 1,
"_type": "Food"
},
{
"name": "Milk",
"price": 2,
"_type": "Food"
},
]
}
The RESTful API should concentrate on the resources that are represented, not necessarily how those resources are used.
In a master/detail scenario, typically the master will contain details of the master object, and include a list of its details (including a link to the API for each detail resource. So /api/items/ might look like this:
{
items: [
{ name: 'item 1', href: '/api/items/1' },
{ name: 'item 2', href: '/api/items/2' }
]
}
The detail resource would contain properties of an individual item in the items list. So the /api/items/{itemName} api might look like this:
{
name: 'item 1',
color: 'blue',
weight: 100,
id: '/api/items/1'
}
So this would probably be closest to your second scenario. There are a number of advantages to this model: it probably matches the domain model that your api is accessing, it makes each api very simple and single-purpose, it's easy to scale, even to very large lists. The disadvantage is that it may lead to more complexity on the client.
The answer as usual may be: it all depends ;)
In case of the connection is limited or unstable (e.g. mobile connection like LTE or even wifi) the best idea is to return the whole list of resources with all fields filled and use the same data on both views. In the company I work for we often take this approach since our backend almost always provide data for mobile applications.
The second idea is to use a mechanism called field or resource expansion. In general a request is made to the endpoint and fields of resources to be returned are included in this request:
/api/items?fields=(name, quantity, origin, whatever)
This mechanism is very convenient since you can use this endpoint to server multiple views without any performance loss.
Personally I'd use two endpoints. An /api/items/ endpoint with field/resource expansion mechanism built-in (with a limited list of fields that can be expanded) and the second one /api/items/{itemID}/ to return a particular item with all the data. This is also the most RESTful approach.
If I POST an issue transition like this:
{
"fields" : {
"resolution" : {
"name" : "Fixed"
}
}
}
...I get this error:
{
"errorMessages" : ["Missing 'transition' identifier"],
"errors" : {}
}
This seems to imply that I need to include a transition ID along with my list of changed fields. https://stackoverflow.com/a/14642966/565869 seems to say the same. Fine.
However, transition IDs appear to be global. It's not enough to look up the highest transition ID for this issue and increment it; such an ID is probably in use elsewhere. At some expense, I could get the highest transaction ID used anywhere in the system; this might be 68,000 at this moment. But if I were then to use transaction ID 68,001 there's a real chance that a GUI user would attempt a transition of their own and use this ID before I could.
I could use transaction IDs in the range of 1,000,001 and up, but if the JIRA web GUI uses the highest previously used transaction ID when generating new IDs I'll just collide in this range instead of the 68,000 range. I could use 69,000 and trust that there won't be a thousand transitions in the length of time it takes to get the highest transaction ID.
These both seem terribly clumsy, however. Is there no way to post a transition and let JIRA generate its own unique ID? I don't need to retrieve the generated IDs, I just want to update issues' statuses and resolutions.
You're getting mixed up a bit. So lets see if I can explain it better for you.
To transition a JIRA Issue, you use the Transition ID to identify what transition to apply to the issue. You aren't specifying an ID for a transaction or a transition ID to identify that the transition occurred, JIRA takes care of this for you.
The easiest way to understand it is to see it.
So first you can look at what transitions are available to an Issue by doing a GET to the API Call:
/rest/api/2/issue/${issueIdOrKey}/transitions
Example:
/rest/api/2/issue/ABC-123/transitions
Which will show something like this:
{
"expand": "transitions",
"transitions": [
{
"id": "161",
"name": "Resolve",
"to": {
"description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
"iconUrl": "https://localhost:8080/images/icons/statuses/resolved.png",
"id": "5",
"name": "Resolved",
"self": "https://localhost:8080/rest/api/2/status/5"
}
}
]
}
So you can see only 1 transition is available for issue ABC-123 and it has an ID of 161.
If you were to browse to that JIRA Issue through the GUI, you would see only 1 Transition available and it would match the API Call. In fact if you inspected the element you should see it having an a tag and in the href something like action=161
So should you want to transition this issue, you'll need to do a POST to the following URL:
/rest/api/2/issue/ABC-123/transitions
With JSON like this:
{
"update": {
"comment": [
{
"add": {
"body": "Bug has been fixed."
}
}
]
},
"fields": {
"assignee": {
"name": "bob"
},
"resolution": {
"name": "Fixed"
}
},
"transition": {
"id": "161"
}
}
Which uses the transition ID found from the call that shows all transitions. I also update the resolution and assignee and add comments at the same time.
That make a bit more sense?