I am trying to use the image metafield functionality described in the Shopify API reference as such:
"{
"position":1,
"metafields":[
{"key":"variant_sku",
"value":"A176-6053",
"value_type":"string",
"namespace":"global"}
],
"src":"http://some.url/images/000/013/369/original/a176-6053.jpg?1337973636
}
When I pull up this product in Rails console I do not see the metafields (there is no metafields method for the image object), and I haven't had any luck referring to the metafields in the liquid template as such:
{{ image.metafields.global.variant_sku }}
I noticed that images are conspicuously absent from this list describing where metafields can be used: "You can store additional information about your products, variants, collections, orders, blogs, pages and you shop itself in metafields."
Yet there is an image example in the API reference. What am I missing?
My ultimate goal is to send the SKU along with the image via the API, and then to access this through liquid/javascript to support displaying the correct image for specific color/style variations.
Thank you for any help.
Metafield need to be requested on their own for the resource, they are not embedded into the response by default. The API docs have examples of how to retrieve them.
Seeing the 'alt' tag of the image is a metafield, why not set the SKU in the alt tag for the image.
You will be able to access the set value for the 'alt' tag via Shopify liquid - it is just you will not be able to retrieve the 'alt' tag via the ShopifyAPI.
This is my Rails example of saving an image that is submitted via an html form, and saving an 'alt' tag with it...
images = params[:images] || nil
if images
images.each do |image|
a = ShopifyAPI::Image.new
a.prefix_options = {:product_id => params[:product_id]}
a.metafields = [{:key => 'alt', :value => 'Cake', :value_type => "string", :namespace => "tags"}]
a.attachment = Base64.encode64(image.read)
a.filename = image.original_filename
a.save
end
else
.
.
.
Hope that helps.
Related
I am trying to generate an < img src > tag for including in an email report, for which I am using Google charts api to generate an image using the following URL.
I have my URL something like this:
https://chart.googleapis.com/chart?cht=pc&chco=f6c23e%2Cae7f06%2Cffdf8d&chd=t:60,7,167&chs=275x100&chl=High(25.6%)%7CMedium(3.0%)%7CLow(71.4%)
The challenge is that I need to show the percentage numbers marked in brackets inside the slices of pie-charts [25.6% , 3.0%, 71.4%].
Kindly let me know if there is any attribute or parameter which allows to do that.
Any help is appreciated.
I am newbie in perl programming. I'm creating wikipages using perl.
So, I am updating whole wiki page using MediaWiki ::API interface.
Code is as follows:
my $wiki = MediaWiki::API->new();
# [...code...]
$wiki->edit( { title => "My_page", text => $all_lines, action => 'edit'} );
My question is, What if I have to update only some portion of webpage ??
NOT ENTIRE WEBPAGE ?
And selection of that part of webpage is dynamic. That means, it depends on what input file I get from user.
So lets say, if user says modify "Introduction" section in webpage then,I should be able to search that particular section and update ?
Any pointers or any suggestions would be appreciated.
Thank you.
You need to set the section parameter.
I have configured image for my page using sidekick >Page properties>Images tab. Now I want to fetch my this page image(thumbnail) in one of my jsp. Can someone give me pointers or code snippet for api class and method that I can use to achieve this.
Thanks,
Rajeev
I would suggest using the default image component as an example - /libs/foundation/components/image.
If you're putting your code into a component for your specific page type though, your code should be something like this:
if (currentNode.hasNode("image")) {
String imagePath = currentNode.getNode("image").getPath();
Resource imageRes = resourceResolver.getResource(imagePath);
image = new Image(imageRes);
image.loadStyleData(currentStyle);
image.setSelector(".img");
if (!currentDesign.equals(resourceDesign)) {
image.setSuffix(currentDesign.getId());
}
image.draw(out);
}
Keep in mind though, even though you set an image, it does NOT mean it will show up - if you're using the default page dialog for page properties, it will only show a broken image. That's because there is a bug in CQ where the sling:resourceType property of the image doesn't get set, and thus it won't show up. This is because the .img selector that gets put on the image doesn't know what to do, unless it get's pointed to a resource type with a definition for the .img selector, so it can properly render the image.
I've uploaded a package that you can use as a hotfix for the issue with the default /libs/foundation/components/page component dialog, so that it will actually set the resource type when you upload an image. You can find/download the package from my Google Drive
Hopefully that helps. Let me know if you need more help.
EDIT
If you're trying to get the page properties image from one page on another page, you just need to use a resource resolver. You should have one available to you in CQ, so this would essentially be the code:
Resource imageRes = resourceResolver.getResource(pathFromYourDialog);
Image image = new Image(imageRes);
The rest would be the same - you're just giving it a different path to start from.
I think Nicholaus was more on point with his EDIT answer to your immediate need. If the user is providing you a path to the thumbnail via the dialog (i.e. a DAM image).
You can simply create the image, or if it has DAM information you can load it as a DAM Asset and pull the necessary information.
Image image = new Image();
Resource imageResource = resourceResolver.getResource(imageUrl);
Asset imageAsset = imageResource.adaptTo(Asset.class);
Map<String, Object> valueMap = imageAsset.getMetadata();
long width = Long.parseLong(valueMap.get("tiff:ImageWidth").toString());
long height = Long.parseLong(valueMap.get("tiff:ImageLength").toString());
Object titleObject = valueMap.get("tiff:ImageTitle");
String title = (titleObject == null) ? null : titleObject.toString();
if (title != null)
{
image.setTitle(title);
}
image.setWidth(width);
image.setHeight(height);
image.setUrl(imageUrl);
This is a little long hand for what Nicholaus had suggested, the Image class will create itself based off the Resource you pass it. (actually upvoted Nicholaus for that, have some optimizations we can make).
Another, simpler option would be to just use the src that the user passes through, in the event that all you're doing is setting a thumbnail. I'm guessing you could be safe in doing something like:
in java:
String thumbSrc = properties.get("thumbSrc", "defaultThumbnail.path");
if (!thumbSrc.isEmpty())
{
pageContext("thumbSrc", thumbSrc);
}
in jsp:
<img alt="thumbnail" src="${thumbSrc}"/>
or if you don't want to do anything in the java you could just do something like
<c:if test="${not empty properties.thumbSrc}">
<img alt="thumbnail" src="${properties.thumbSrc}"/>
</c:if>
In order to get the same result as the first part in just jsp, you'd need to wrap it in a choose, because passing it through some processing before sending to view makes it easier to set default values.
I have a view with a number of exposed filters that I want to add an exposed filter for the author, so that the user can limit a list of nodes by the creator of the node (in addition to a number of other filters).
What I've done so far:
I've added an exposed filter of the author and set the operator to "contains any word" (so the usernames could just be a + separated list)
This is by default a text field, but I would like it to appear as a list of checkboxes (similar to taxonomy)
Using hook_form_alter I've added the following code to change it to a list of checkboxes (harcoded for now but I'll fix shortly)
$form['name']['#type'] = "select";
$form['name']['#size'] = "3";
$form['name']['#multiple'] = TRUE;
$form['name']['#options'] = array(
'admin' => 'admin',
'tyler' => 'tyler',
'test' => 'test'
);
$form['name']['#theme'] = "select_as_checkboxes";
When this form is submitted it changes the url to &name[]=tyler&name[]=admin, what I would like to do is combine these with a foreach so that url would look like &name=tyler+admin, but I'm really not sure how exactly to achieve this in the API.
I tried adding a function to $form['#submit'], and changing the value of the field in there, but that still didn't change the output.
Any advice?
Quick Edit
For the time being I have switched this to use radios instead of checkboxes, which solves the issue that I was having.
To break down the issue I was having a bit further, the names of the checkboxes where getting set to name[]= instead of name= because of the multiple inputs. The name filter in Views does not know how to handle multiple values for the name field.
For now I will see if this flies with the client, but if anybody has an answer for the original question of adding checkboxes for all authors to an exposed filter that would be awesome!
Use Better Exposed Filters module.
I'm creating a very basic classifieds website. In this website i'll have various content-types; such as :
Car (which has the cck fields : year, kilometers, color
House (which has the cck fields : number of floors, garden (yes/no)
So each 'element' is a content-type.
I'm listing all the content-types in a view that I display to the user aand then clicking on a link goes to 'create content type of type (clicked type)'.
It's working pretty well; but i can't get rid of the 'create new car' at the top of the create page (which reflects the 'drupalish' behaviour).
I'd like to have it in a more conveniant way such as a three step form like :
Choose category
Choose your options
Register to post your new classified
I've seen the ctools; which provide 'almost' the multistep behaviour; however i can't imagine having all my dozen content-types being 'hardcoded' in a single module.
I wonder if anyone has achieved this kind of setup or if there's a kind of module that can do the trick. I'd like to keep a content type for each type of classified (the webmaster is now used to the interface).
Any help, starting points would be appreciated.
For the first step we had to solve a simular problem. To do so we created what was basicly an override of the /node/add page (the one that lists all the content types), which you've done. To change the title the simplest is to create a yourtheme_preprocess_page() function that changes the title when the url is /node/add or node/*/edit
However: I would strongly suggest switching to a system that uses 1 content type for all listings. We created a very simular site, and after working with different content types it because clear that having 1 content type with fields that were displayed conditionally was a much more sane solution. Using categories for the different product types, and then using the Conditional Fields module to hide and show the correct fields worked much better.
http://drupal.org/project/conditional_fields
Here is and example snippet for setting the title in a page preprocess function:
Setting the title on the node/add page:
if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == '') {
$vars['title'] = 'Choose an Industry';
$vars['head_title'] = $vars['title'] . " | " . variable_get('site_name', "Industry Trader");
}