Set config on run time instead of config file
Hi, first of all, thank you for your work!
i guess it would be very nice to have the ability to set config as arguments to the WoocommerceApi Class, bypassing the static config file, this would help in case of batch calling on multiple endpoints, i know you can use the builtin config([]) function but in my test it does not work if i run a loop through php artisan command
example code:
foreach(['A', 'B', 'C'] as $endpoint){
config(['woocommerce.store_url' => '...']);
config(['woocommerce.consumer_key' => '...']);
config(['woocommerce.consumer_secret' => '...']);
$orders = WooCommerce::all('orders', ...);
// $orders will output the same results for every endpoint,
// because the config changes only for the first endpoint
}
hope this make sense! ;-)
Hello @aSeptik, Thanks for your information and complement. I fixed your issues, please make sure you are using version v2.2 or above. Follow the code sample
$endpoints = [
[
'store_url' => 'http://www.example1.com',
'consumer_key' => 'store_1_consume_key',
'consumer_secret' => 'store_1_consume_secret',
'verify_ssl' => false,
],
[
'store_url' => 'https://www.example2.com',
'consumer_key' => 'store_2_consume_key',
'consumer_secret' => 'store_2_consume_secret',
'verify_ssl' => true,
],
];
foreach($endpoints as $endpoint){
config([
'woocommerce.store_url' => $endpoint['store_url'],
'woocommerce.consumer_key' => $endpoint['consumer_key'],
'woocommerce.consumer_secret' => $endpoint['consumer_secret'],
'woocommerce.verify_ssl' => $endpoint['verify_ssl'],
]);
$products = Product::all();
var_dump($products);
}
don't forget to add verify_ssl if your site is SSL protected otherwise it won't work. Reply me if you face any other issue.
Best regards, Md Abu Ahsan Basir
Maybe a stupid question :) How did you select the store you want use in your example ?