Adding product variant title in shopify - shopify

I've got a few products that have different variants - i.e. Colour, Size, etc.
I'm trying to output the parent(?) variant title using - {{ variant.title }} but that's only outputting the variant options themselves i.e. Small, Medium, Large for Size. Is there a way to output the "Size" title and not the individual variant titles.
Sorry if that's confusing, I know I'm in the close but maybe in the wrong ball park!

I don't think the option titles are available on the variant object - for those you would normally look on the parent product object.
If you are printing the variant details from the context of a product page (or other situation where you already have a product object), you can use product.options or product.options_with_values to get the option category names. The option names will always be in the same order as the option values are listed on the variant, so the first value of the product.options array will be for the first item in the variant.options array.
Once an item is added to the cart, the resulting line_item object gets its own style of an options_with_values object that has the names and values of the associated options, but unfortunately this object does not appear to exist on the variant object itself.
Above links all go to the relevant Shopify Liquid reference pages

Related

How to get variant metafield value + price combined in shopify collection page's each product

This is the product page. I have here "variant meta field value" + "variant price" combined. So, when I select a variant, it shows variant price + (related) variant meta field value. As you can see on the right side.
How I can do the same for other pages, where we have a list of products. ex: single collection pages etc. Anyone did/do similar things?
My Aim is to get: Product variant Metafield value + Variant price combined. So, when I select variant from dropdown, I'll get both of them and can show below the product title.
Is there a point to this exercise? When you go to checkout, your customer will only ever pay the variant price, never the combined price with the metafield. So what is the point of the metafield price? Seems like a lot of work for no benefit.

Shopify selected variant id to update

I have an inquiry form built into my Shopify product page.
Where they can request a callback in regards to the product they're on and the variant id select.
I'm able to call back the current selected variant ID
product.selected_or_first_available_variant.id
But if I change the drop-down selection to another variant, this id will not update.
How do I may this update on the selection of a different variant?
Thank you
Correct - the {{ product.selected_or_first_available_variant.id }} is a Liquid variable, and Liquid is parsed server-side to generate the HTML document that is sent to the browser. Liquid can only ever be accurate as of the time of the initial page load
If you want to respond to user changes after the page has loaded, you'll need to use Javascript. If you are on a product page, there will be some javascript function firing that updates the price, image, etc. when the variant changes. If you can find that function (often, but not always, called selectCallback), you could add the code needed to update your contact form in there.
If you just need a variant ID, one other method to get it would be to write a small javascript function which, on submit of your contact form, takes the current value from the variant ID field in the product form and puts that value into the appropriate field in your contact form.
Hope this helps!

StringList in VBA

A function I'm using in VBA returns a variable ErrorTags which has to be defined as type StringList. In Debug watch if I watch ErrorTags I can see string variables returned as Item 1, Item 2 etc. However I can't find any way in the code to access these variables. Eg I've tried
Test = ErrorTags.Item 1
and
Test = ErrorTags.Item_1
without any success
What is the correct format?
Assuming that ErrorTags is indeed a collection, you have to think of it like this:
ErrorTags is an object that holds all the values associated with it (the Items you see in the watch list). That object has a default property, Item. That property can return all the values stored in the object, but only one at a time. Which will be returned depends on the parameter you pass to the property:
ErrorTags.Items(1)
This will return the first item stored in the collection. The parameter serves as an index by which you can address all items in the collection. Some collections in VBA also accept strings as an index, but that depends on the type of collection. In Excel, for example, the Sheets property of a workbook returns a collection (containing all the worksheets in an Excel file). That collection does not only take numbers as an index but also works with the sheet name as an index.
As said above, the Item property of a collection is the default property. In VBA, an object can have a default property, which means, it can be omitted. To access the first item from your collection can therefore also be written like this:
ErrorTags(1)
Now, you probably want sometimes to access not just one item but all of them in a loop. You could do this with a For loop using the counter as an index for the collection.
But there is a better way:
Dim et As Variant
For Each et In ErrorTags
' now you have one item stored in et, do with it as you like
Next et
Using a For Each loop you can iterate over all items of a collection (it also works for arrays). For each pass the current item will be written to the variable et. Use that variable instead of ErrorTags.Items() as long as you are in the loop. Assuming the items in the ErrorTags collection are simple strings you could output all of them to the immediate window if you put Debug.Print et in the body of the loop.
If the items in your collection are objects themselves, then you should change the declaration of the variable et to that object type:
Dim et As ErrorTag ' assuming that is the object type
More information about the For Each loop can be obtained from the documentation.

Create an `Items` collection containing references to already existing `Item`s

I mean to create an Items collection, and add to it several already existing Items.
For instance, if I have two references to MailItems, I want to set an Items collection containing those two Items.
It would be something like
' ...
' Code that assigns references to olMail1 and olMail2, of type Outlook.MailItem
' ...
Dim MyItems As Outlook.Items
' Assign with Set / create the object
MyItems.Add olMail1
MyItems.Add olMail2
' Code that can use MyItems(1) to get a reference to olMail1
How can that be done?
Things to clarify are:
How to setup the new collection.
How to add items.
Documentation on Items.Add seems to indicate that it is used for adding newly created objects, not references to existing Items.
I would later iterate through that collection, for instance. I would also apply Find or Restrict; this allows for applying the methods on a much smaller collection than a whole Folder.
PS: I cannot get an Items collection even from
Application.ActiveExplorer.Selection (i.e., without need for creating the collection and add Items one by one). This would be good for a starter.
Background
I mean to find what Items have a sender matching a given string. The aspects that perhaps make my case somewhat more complex than a "base case" are:
I mean to apply the filter only on a selected group of items. E.g., only on the Items that are selected in the Inbox index.
I want to do partial matching. At this point I do not need regular expressions, or even full use of wildcards *?. But at least partial matching as in InStr.
I mean to have a specific Function for the minimal unit: testing one Item, for a single condition. Then loop through all target Items, and all conditions.
I conceived 3 approaches:
Use Rules.
Use Filter or Restrict. These do not accept wildcards (in principle?).
"Manually" check conditions, with InStr, e.g.
Each of the aspects above may bear some complexity for one or more of the approaches.
At this point, I was exploring approach 2. I have a reference to a single Item, and I found how to apply a Filter with a matching condition (see
http://www.outlookcode.com/news.aspx?id=30 ,
http://blogs.msdn.com/b/andrewdelin/archive/2005/05/11/416312.aspx , and the non-accepted answer of VBA Search in Outlook). But to apply the Filter, I need an Items collection, containing my single item.
I have something working with approach 3 (as suggested in the accepted answer of VBA Search in Outlook).
Related links
Identify MailItems satisfying a Rule
You can just use a regular collection:
Dim myItems As Collection
Set myItems = New Collection
myItems.Add olMail1
myItems.Add olMail2
Now if you're looking to restrict the type of objects than can be contained by myItems, then it becomes a bit more complicated, but here's a way to do it:
Restrict type in a Collection inside a class module
I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.
An instance of the Items class can't be created in the code. It is asociated and belongs to any folder. You can create a folder to get a new Items instance.
You can use the Copy method of Outlook items to create another instance of the object. Then the Move method can be used to move the item to another Items collection (folder).
1.I mean to apply the filter only on a selected group of items. E.g., only on the Items that are selected in the Inbox index.
You need to iterate over all selected items instead. The Find/FindNext and Restrict methods belong to the Items class only. So, you can apply them to the Folder items only.
2.I want to do partial matching. At this point I do not need regular expressions, or even full use of wildcards *?. But at least partial matching as in InStr.
See Filtering Items Using a String Comparison. You can use the ci_startswith or ci_phrasematch operators.
3.I mean to have a specific Function for the minimal unit: testing one Item, for a single condition. Then loop through all target Items, and all conditions.
Take a look at the Filtering Items section in MSDN which describes the general rules for specifying properties in filters that are supported by various objects in Outlook.
The Filter method of the View class is applied to the Outlook view only. The Items property will return the full list of items.
It would be better if you specify the final goal, not possible way to solve the problem which is not clear for us.

Is it possible to colour a cell with value from data in Cognos BI?

Let me first be clear. I'm not asking about how I do conditional formatting in Cognos BI. If there were a simple Red/Amber/Green colour scheme, based upon value ranges then I could do that. If it were a static list of colours, which never changed, I could also do that.
What I am after is accessing a hex colour code that is stored in my database, and I want to use that colour as my table cell background colour. This is something I commonly do in SSRS reports, but cannot see a method for in Cognos BI.
Is this even possible?
You can do this via the HTML object in Cognos.
The HTML object can get its definition from one of the three main ways:
1) Hard-coded text
2) Data Item Value
3) Report Expression
Obviously the first method provides no way to dynamically set the value. I couldn't get the second one to work at all. I'm not yet sure why. However, I was able to use the third type to work to allow dynamic setting of a visual style.
For the solution we'll assume you have a data item called [Color] which pulls a string value from a database in the standard hex form that is used in CSS: #xxxxxx, e.g. #CCCCCC. For the purpose of this example we'll assume it is in query Query1. The following steps describe how to set it up.
1) Add an HTML item right above your list
2) Add another HTML item at the bottom of your list
3) In the top HTML item add a span tag with a unique id such as:
<span id="list">
4) In the bottom HTML item add a closing span tag
</span>
5) Add a third HTML item before all of the other HTML items
6) Set the 'Source Type' property of the HTML item to 'Report Expression'
7) In the Report Expression put the following code:
'<style>
#list td {
background-color: ' + [Query1].[Color] + '
}
</style>'
8) Select the Page object and set the Query property to Query1
9) Click on the Properties property. Check the Color column to give the page access to that query-sourced value.
Now you can dynamically set the column color based on a database provided value. We used the span to give us a way to isolate just the table cells we want to manipulate.
The technique isn't perfect. For instance, the header cells also get their background changed to the color in question, which may or may not be desirable. This is because Cognos doesn't use the th tag for headers but instead renders them as normal cells (td).
I know it's quite and old post but just for completeness I'll add the references to get this working in html, pdf and excel.
To get this working not only for html but also for pdf and excel use a rich text item instead of a html item.
You can use following code in a query item for instance:
<span style="display:block; background-color:' + [Query Subject].[Query Item] + '"> </span>
The query item must then contain a valid color (e.g. rgb(255,0,0)) etc. which is defined by your data source.
Dragging a rich text item in a list and changing it to data item value and selecting the query item will work.
By using the span it will work for excel too, however to make sure it follows the size of the upper object in the hierarchy (the list column or a table etc) you want the display:block style.
Instead of the space in between the > < you can use any other query item that you want to appear as text.