Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set config on run time instead of config file #12

Open
lucafilosofi opened this issue Mar 29, 2020 · 2 comments
Open

Set config on run time instead of config file #12

lucafilosofi opened this issue Mar 29, 2020 · 2 comments

Comments

@lucafilosofi
Copy link

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! ;-)

@Codexshaper Codexshaper pinned this issue Mar 30, 2020
@maab16
Copy link
Collaborator

maab16 commented Mar 30, 2020

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

@piloufaces
Copy link

Maybe a stupid question :)
How did you select the store you want use in your example ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants