Product Variation attribute won't pass WooCommerce Rest API - woocommerce

I am trying to create a Variation for a variable type product using WooCommerce Rest API (https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#create-a-product-variation). Sadly, whenever I create one, it creates the product variation with the correct price and image, but the attribute which is being passed doesn't get selected. even though it exists in the product attributes tab and selected as a "Variations attribute"
I tried passing the attribute options as an array, a string, and what not. the id of the attribute was always correct as well as the id of the product. keys are definitely right since the variation is created but it doesn't contain the attribute.
Here's an example in cURL, even there I couldn't get it done. so it isn't related to my C# code for sure:
curl -X POST https://example.com/wp-json/wc/v3/products/IDHERE/variations \
-u cc:cc \
-H "Content-Type: application/json" \
-d '{
"regular_price":"549.99",
"image":{
"src":"https://www.cookingclassy.com/wp-content/uploads/2014/03/hummus-31.jpg"
},
"attributes":[
{
"id":9,
"options": "olive"
}
]
}'
The product variation should be listed with it's attribute/s. as well as the image and price that are currently listed correctly.
Thanks in advance everyone

There's a bug that avoids adding Variation Attribute 'option' values to Attributes with Hebrew names.
Please read bug report no. 24312: https://github.com/woocommerce/woocommerce/issues/24312

Related

Automatically set category based on wordpress post visibility?

I've been looking for a way to automatically append a category everytime a post is set to private. I've seen several of ways of doing this for custom post types but i've yet to figure out a way how to achieve this with post visibility.
Any ideas?
This filter should do the job.
function add_categories_automatically($postID) {
if(get_post_status($postID) == 'private'){
$catsID = array(5);
wp_set_post_categories($postID, $catsID, true);
}
}
add_action('publish_post', 'add_categories_automatically');
This will check the post status when it is published. If the status is private, specified categories will be appended to the post.
Be careful, as wp_set_post_categories will overwrite any existing categories already assigned to the post unless the third parameter is set to true: wp_set_post_categories

Wordpress Woocommerce REST API V3 attributes and terms

I woocommerce you can create Attributes, like Color
These attributes can have terms, like red, green, white. Later on, you can add these attributes to a product.
I know how to add these attributes by means of the API, like described here:
http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-product-attribute
I've been searching for hours, but there seems to be no way to add terms with the API. Am I missing something?
You add terms with the Update A Product api, here:
You make a PUT request: /wc-api/v3/products/<id>
In the request body you send:
{"product":{"categories":[...],"tages":[...]}}
Since WooCommerce 2.5 you have new endpoint for adding attributes term. Just look at the documentation.
http://woothemes.github.io/woocommerce-rest-api-docs/#product-attribute-terms
For example for creating term for the specific attribute you can POST to endpoint
/wc-api/v3/products/attributes/<attribute_id>/terms
JSON message:
{
"product_attribute_term": {
"name": "Black"
}
}
It accepts the attribute slug/taxonomy name; Just use this one:
example.com/wp-json/wc/v3/products?attribute=pa_compatible-for&attribute_term=249
I know it's not documented properly!
Have a good time.

Filter property based searches in Artifactory

I'm looking to use the Artifactory property search
https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactSearch%28QuickSearch%29
Currently this will pull json listing any artifact that matches my properties.
"results" : [
{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom"
},{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver2/lib-ver2.pom"
}
]
I need to be able to filter the artifacts I get back as i'm only interested in a certain classifier. The GAVC Search has this with &c=classifier
I can do it in code if this isn't possible via the interface
Any help appreciated
Since the release of AQL in Artifactory 3.5, it's now the official and the preferred way to find artifacts.
Here's an example similar to your needs:
items.find
(
{
"$and":[
{"#license":{"$eq":"GPL"}},
{"#version":{"$match":"1.1.*"}},
{"name":{"$match":"*.jar"}}
]
}
)
To run the query in Artifactory, copy the query to a file and name it aql.query
Run the following command from the directory that contains the aql.query file
curl -X POST -uUSER:PASSWORD 'http://HOST:PORT/artifactory/api/search/aql' -Taql.query
Don't forget to replace the templates (USER, PASSWORD,HOST and PORT) to real values.
In the example
The first two criteria are used to filter items by properties.
The third criteria filters items by the artifact name (in our case the artifact name should end with .jar)
For more details on how to write AQL query are in AQL
Old answer
Currently you can't combine the property search with GAVC search.
So you have two options:
Executing one of them (whichever gives you more precise results) and then filter the JSON list on the client by a script
Writing an execution user plugin that will execute the search by using the Searches service and then filter the results on the server side.
Of course, the later is preferable.

Custom post types permalink with parent custom post type

Hard to define the Title of this Question....
I want to create a nice readable permalink structure for my 2 custom post types (CPT).
My first CPT "family" has the following rewrite-slug "family/%postname%" (all works fine)
The second CPT "childs" has a metabox where I can select the parent_id-field by choosing a CPT "family" where the child-CPT belongs to. That also works great.
Now I set the rewrite-slug for "childs" to "%parent_post_url%/child/%postname%" so that I can get the following URL "family/the-griffons/child/peter" . But when I call this URL wordpress displays a not-found-page. The crazy thing is that if I set the rewrite-slug hard to "family/the-griffons/child/%postname%" I can call the URL (both URLs are the same!!!)
So why toes WP throws an error when I try to get the URL dynamically but not when I hardcode the URL??
The child-parent relationship you think you have is not quite there. Based on what you've told us so far, it seems that all you have is a custom field denoting the "pseudo-parent" id. So what your question should really read is
How do I rewrite the first part of the cpt url, based on the cpt custom field value ?
because, as far as wordpress is concerned in your case, that's all that "parent id" really is- a custom field value.
you can try following the last part(Part 3.) of this tutorial, keeping in mind, that you'll want the actual path of the url of the "parent id" and not the cf "parent id" value itself, you'll have to implement something along the lines of:
$parent_id = get_post_meta($post_id, "your_cf_key_for_parent_id", true);
$full_parent_post_url = parse_url( get_permalink( $parent_id ) );
$parent_post_url = $full_parent_post_url['path'];
if(!$parent_post_url) { $parent_post_url = "default-fallback" }
$permalink = str_replace(‘%parent_post_url%’, $parent_post_url, $permalink);
return $permalink;
another relevant stackexchange answer:
using-custom-fields-in-custom-post-type-url
BUT as #c0ns0l3 mentioned using custom taxonomies IS the proper way to go about this.

open graph sample object, invalid og:type?

I've set up a custom action and custom object. I'm attempting to post to my timeline with the sample code Facebook offers:
curl -F 'access_token=<my token>' \
-F 'photo=http://samples.ogp.me/351656114891990' \
'https://graph.facebook.com/me/stipple_staging:stipple'
The response that comes back is this (parsed out for easier reading):
{
"error":{
"type":"Exception",
"message":"Object at URL 'http:\/\/samples.ogp.me\/351656114891990' is invalid because the configured 'og:type' of '103770389680565:photo' is invalid."
}
}
I'm sort of clueless at this point. Is this a known gotcha where I need to do something, or just a bug?
EDIT: Facebook now seems to have fixed this problem.
I think your issue is that your og:type is supposed to be your app namespace:action type, like
<meta property="og:type" content="your_app_namespace:photo" />
Check out section IV of the custom objects walkthrough, it has some examples of how the og:type tag should be formatted. I'm not certain that appid and namespace are the same thing, in the eyes of FB.
On a side note, you can check your FB URL's here instead of doing everything through cURL, if you prefer.
If you want to make it easy on yourself, there is a list of allowed values available on the Facebook website. If can use any of them in the type field: http://developers.facebook.com/docs/opengraphprotocol/#types

Resources