Php BigCommerceAPI循环中的多个存储
我目前正在创建一个web应用程序,需要在多个BigCommerce商店中循环。不幸的是,在使用BigCommerceAPI时,我无法使其循环 我正在使用GitHub的最新版本的BC API PHP库(使用名称空间的库),请参阅下面的代码:Php BigCommerceAPI循环中的多个存储,php,api,foreach,bigcommerce,Php,Api,Foreach,Bigcommerce,我目前正在创建一个web应用程序,需要在多个BigCommerce商店中循环。不幸的是,在使用BigCommerceAPI时,我无法使其循环 我正在使用GitHub的最新版本的BC API PHP库(使用名称空间的库),请参阅下面的代码: require_once( 'autoload.php' ); use Bigcommerce\Api\Client as Bigcommerce; $stores[1]['url'] = 'https://www.store1.co.uk'; $stor
require_once( 'autoload.php' );
use Bigcommerce\Api\Client as Bigcommerce;
$stores[1]['url'] = 'https://www.store1.co.uk';
$stores[1]['api_key'] = 'e01e16e6b51d70f6de213fd7445dc0f4';
$stores[1]['user'] = 'admin';
$stores[2]['url'] = 'https://www.store2.co.uk';
$stores[2]['api_key'] = '7b8b934e157eac734b7f7b4311b7cd81';
$stores[2]['user'] = 'admin';
foreach ( $stores as $store ){
echo $store['url'] . ' - ';
Bigcommerce::configure(array(
'store_url' => $store['url'],
'username' => $store['user'],
'api_key' => $store['api_key'],
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer( false );
$products = Bigcommerce::getProductsCount();
echo $products . ' products<br />;
}
我实际上得到的是:
https://www.store1.co.uk - 301 products
https://www.store2.co.uk -
我以前使用过API几次,但每次/每个项目只连接到一个存储。在连接到foreach循环中的下一个存储之前,是否需要关闭连接或其他操作
非常感谢大家的帮助 查看Bigcommerce PHP库中的以下代码片段
/**
* Get an instance of the HTTP connection object. Initializes
* the connection if it is not already active.
*
* @return Connection
*/
private static function connection()
{
if (!self::$connection) {
self::$connection = new Connection();
self::$connection->authenticate(self::$username, self::$api_key);
}
return self::$connection;
}
这来自Client.php-
如果查看正在执行的操作,它将不起作用,因为现有连接将迫使库忽略新值。只有在第一次设置时,才会形成新的存储连接
对于您的特殊用例,一个简单的修复方法是重写上述函数,以重新连接到新商店,而不考虑现有连接
希望一切顺利 谢谢Saran,很抱歉延迟回复。这个项目暂时搁置,但我相信你的建议在不久的将来对别人和我都会有帮助。
/**
* Get an instance of the HTTP connection object. Initializes
* the connection if it is not already active.
*
* @return Connection
*/
private static function connection()
{
if (!self::$connection) {
self::$connection = new Connection();
self::$connection->authenticate(self::$username, self::$api_key);
}
return self::$connection;
}