Ok, so, I have a fair bit of experience with the Woocommerce API and PHP and use it for lots of product population from XML files. However, I'm having a problem adding attributes. Well, thats not strictly true, the attributes DO add, but then throw up an error after they do.
I'm using the Automattic PHP code and, as I say, it does most things fine.
$data = [
'attributes' => [
[
'id' => 9,
'position' => 0,
'visible' => true,
'variation' => false,
'options' => [
'bathroom'
]
]
]
];
$woocommerce->put('products/123', $data);
but that gives me the error
'Error: Invalid parameter(s): attributes [rest_invalid_param]' in
/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:348 Stack trace: #0
Although when I look at the product, the attribute has been added correctly.
Related
I'm using Crocoblocks/JetReviews to add reviews to my site (on a custom post type).
I can see there is a setting to require admin approval for it to be published, but I want to trigger an email to one of the admins when a review is submitted, and I don't see any settings for that so I'll have to do it myself.
I think I can handle the function to send the email, but can't sort out what to hook into or trigger it against?
Using something like this:
if ( function_exists( 'notification' ) ) :
notification( [
'title' => 'Admin Notification for Review Approval', // For internal reference.
'trigger' => 'trigger_slug', // Trigger slug (can be a Triggerable object).
'carriers' => [ // An array with format: carrier_slug => data array
'email' => [
'activated' => true, // Must be true.
'enabled' => true, // Must be true.
'subject' => 'A New Review Needs Approval',
'body' => 'There is a new review awaiting your approval.',
'recipients' => [
[
'type' => 'administrator',
'recipient' => 'admin#adminemail.com',
],
],
],
],
'enabled' => true, // Must be true.
] );
endif;
But right now that's not connected to any action...and that's where I'm lost.
Any thoughts of where to look? I couldn't figure it out from their docs so hoping someone here might have an idea of where to start at least.
Thanks!
Chad
Lets say I have following structure:
Article:
name
content
galleries: array of Gallery
Gallery:
name
description
media : array of Media
thumbnail: Media
Media:
name
file
Now when I am serializing The article or something that contains a gallery I need to specify groups for all children like this:
'groups' => [
'All',
'gallery' => [
'Details',
'thumbnail' => ['Basic'],
],
],
Now every time I add something to the gallery I need to go thorough all controllers and add the deep dependencies eg. After adding a largeThumbnail field:
'groups' => [
'All',
'gallery' => [
'Details',
'thumbnail' => ['Basic'],
'largeThumbnail' => ['Basic'],
],
],
If I dont do it, or miss a controller, it will include "largeThumbnail" with group "Details" instead of "Basic" and cause a lot of databasse requests (since without Groups defined it will just follow the tree and add everything it finds) killing the performance.
Is there a way to tell JMS what groups an entities children should have when a specific group is used for parent?
In other words can I tell that if I used "Details" For Gallery than it should use "Basic" for Gallery->media, so I can simplify the above to just saying:
'groups' => [
'All',
'gallery' => ['Details'],
],
And it would fill in 'thumbnail' => ['Basic'], for me?
I've created a custom post type that is however not showing up in the GraphiQL explorer.
function create_custom_visions_post_type() {
register_post_type('visions',
array(
'labels' => array(
'name' => __('Visions'),
'singular_name' => __('Visions')
),
'public' => true,
'show_in_admin_bar' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'Vision',
'graphql_plural_name' => 'Visions',
));
}
According to the wp-graphql docs only the flags "show_in_graphql", 'graphql_single_name' and 'graphql_plural_name' are needed in order to expose a custom post type to the graphql schema.
What am i missing?
ok stupid me, i forgot to add
{
resolve: `gatsby-source-graphql`,
options: {
// This type will contain remote schema Query type
typeName: `WPGraphQL`,
// This is field under which it's accessible
fieldName: `wpgraphql`,
// Url to query from
url: `blablabla.local/graphql`,
},
to gatsby-config.js
now my custom post type is available inside wpgraphql{}
Make sure you're registering your CPT before the WPGraphQL initializes the schema. You can do this by running your CPT registration code in the graphql_init hooks like this.
function create_custom_visions_post_type() {
register_post_type('visions',
array(
'labels' => array(
'name' => __('Visions'),
'singular_name' => __('Visions')
),
'public' => true,
'show_in_admin_bar' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'Vision',
'graphql_plural_name' => 'Visions',
));
add_action( 'graphql_init', 'create_custom_visions_post_type' );
May be a bit unrelated, but I found this post while trying to figure out why my Custom Post Type that was registered with the popular plugin "Custom Post Type UI" wasn't appearing in my GraphQL Schema. I was messing with plugin code, and couldn't figure it out until I noticed that in the plugin page for Custom Post Types UI, there is a checkbox to toggle the inclusion of the CPT in GraphQL at the bottom of the edit page for each Custom Post Type in CPTUI.
If your function to create your custom post type looks good, then you might just need to run gatsby clean beyond just restarting your project. The Gatsby docs say you might want to run gatsby clean when there's a "GraphQL error, e.g. this GraphQL resource should be present but is not".
https://www.gatsbyjs.com/docs/reference/gatsby-cli/#clean
Drupal does not allow me to delete extension (recurring_commerce) as some fields needs to be deleted manually. This issue is described in detalis below.
Solution is to add some code to a file as described in #11 of the issue below.
Basically I need to programmatically delete a field and I have never done it before. Writing kind of a hook (?).
I tried to paste the suggested code before, after the original code as well as replacing the original code with a suggested one.
Every time after changing the code I am restarting the server, running cron and clear cache.
Still I am unable to uninstall the exension from drupal as I have the following message:
The following reason prevents Commerce Recurring from being uninstalled:
The Billing period field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period
Details of the following issue:
please skip to #11
https://www.drupal.org/project/commerce_recurring/issues/2924965
Suggested code to apply:
function commerce_recurring_update_8101(&$sandbox) {
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_schedule')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.order_items')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.subscription')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.subscription')->delete();
}
function commerce_recurring_update_8102(&$sandbox) {
\Drupal::entityTypeManager()->getStorage('commerce_order_type')->load('recurring')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_standalone')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_product_variation')->delete();
}
Original code in my file:
/**
* Add the 'trial_starts' and "trial_ends" fields to subscriptions.
*/
function commerce_recurring_update_8101(&$sandbox) {
$fields = [];
$fields['trial_starts'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial starts'))
->setDescription(t('The time when the subscription trial starts.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$fields['trial_ends'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial ends'))
->setDescription(t('The time when the subscription trial ends.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($fields as $name => $storage_definition) {
$update_manager->installFieldStorageDefinition($name, 'commerce_subscription', 'commerce_recurring', $storage_definition);
}
}
/**
* Make the billing_schedule field required on subscriptions.
*/
function commerce_recurring_update_8102() {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$field_definition = $entity_definition_update->getFieldStorageDefinition('billing_schedule', 'commerce_subscription');
$field_definition->setRequired(TRUE);
$entity_definition_update->updateFieldStorageDefinition($field_definition);
}
i am trying to create webhook using the api call inlaravel but it gives me the error "The requested URL returned error: 406 Not Acceptable".
my code is as bellow.
$webhookData = [
'webhook' => [
'topic' => 'app/uninstalled',
'address' => url('/uninstall'),
'fields' => 'name',
'format' => 'json'
]
];
$uninstall = $sh->call(['URL' => 'https://' . $shop . '/admin/webhooks.json', 'METHOD' => 'POST', 'DATA' => $webhookData]);
There are certain things you need to take care of while creating the Shopify webhooks.
The address field should be a globally accessible URL (ex: https://example.com/webhook/uninstall.php)
You can not give localhost links for creating webhooks.
I think the address field is not passed with a valid URL in your post request.