php-shopify icon indicating copy to clipboard operation
php-shopify copied to clipboard

How to create multiple shopify objects to access multiple stores

Open vuivenao opened this issue 6 years ago • 5 comments

Hi everybody, I want to update data to my two Shopify stores. But if I changed a config of Shopify SDK, it's not working. Object 1 of store 1 is same to Object 2 of store 2.

Here 's my code:

PHPShopify\ShopifySDK::config($config_store_1);
$shopify_1 = new PHPShopify\ShopifySDK;

PHPShopify\ShopifySDK::config($config_store_2);
$shopify_2 = new PHPShopify\ShopifySDK;
    
$locations_1 = $shopify_1->Location->get();
echo json_encode($locations_1)."<br/><br/><br/>==========================<br/><br/><br/>";

$locations_2 = $shopify_2->Location->get();
echo json_encode($locations_2);

===> $locations_1 is same to $locations_2

Please help me. Thanks!

vuivenao avatar Jan 18 '19 10:01 vuivenao

I have exactly the same issue. It appears PHPShopify\ShopifySDK is a singleton.

I need to clone/copy from one store to another. But the 2nd shopify store object overrides the 1st one. I have limited knowledge on using php object, but it appears to be the same as using "static" in C/C++.

Can someone please look into this issue?

Thank you!

vicn1222 avatar Feb 17 '19 04:02 vicn1222

After looking at the code, I see “static” is used throughout the class. That is the bug,

vicn1222 avatar Feb 17 '19 12:02 vicn1222

I made the changes to support multiple instances of ShopifySDK

How can I submit the changes for review? Can someone check in for me?

Thanks!

fixBug.tar.gz

vicn1222 avatar Feb 20 '19 18:02 vicn1222

The static for config is never fixed. It is still there.

vicn1222 avatar May 01 '21 02:05 vicn1222

you need change the 3 files in the issue https://github.com/phpclassic/php-shopify/issues/61#issuecomment-465708743

adviewmx avatar Aug 26 '22 16:08 adviewmx