我们正在迁移到BC,我在使用usexml函数时通过api获取订单,因为我必须为每个订单输出一个文件。我已成功获得订单,订单中的产品以及BC的送货地址。我不得不在bigcommerce.php库中添加一些函数来执行此操作,因为虽然它们可能在在线文档中被引用,但它们实际上并不存在于库中。我的最后一步是获得与订单相关的优惠券。我在库中实现的功能如下:
//库中缺少的功能已添加030215 PH - 订购产品
public static function getOrderProducts($id)
{
return self::getCollection('/orders/' . $id . '/products','Order');
}
// Function missing form library added 030215 - Get Shipping adds on order
public static function getOrderShippingAddresses($id)
{
return self::getCollection('/orders/' . $id .'/shipping_addresses','Order');
}
//添加了功能缺失表单库030215 - 获取订单上的优惠券
public static function getOrderCoupons($id)
{
return self::getCollection('/orders/' . $id . '/coupons','Order');
}
虽然语法相似,但我无法通过getOrderCoupons函数返回优惠券信息来代替普通getOrders返回时提供的链接。
我使用与获取送货地址相同的优惠券逻辑,如下所示。非常感谢任何解决方案。
N.B Bigcommerce :: useXML();使用XML字符串
$shipping_xml = Bigcommerce::getOrderShippingAddresses($order->id);
$shippings = simplexml_load_string($shipping_xml);
//每个订单只能有一个送货地址
foreach($shippings as $shipping) {
$xmlship = $shipping->asXML();
$domship = new DOMDocument();
$domship = dom_import_simplexml($shipping);
$domordship = dom_import_simplexml($order->shipping_addresses);
$domship = $domordship->ownerDocument->importNode($domship, TRUE);
$domordship->appendChild($domship);
}
$coupon_xml = Bigcommerce::getOrderCoupons($order->id);
$coupons = simplexml_load_string($coupon_xml);
//每个订单只能有一张优惠券
foreach($coupons as $coupon) {
$xmlcoup = $coupon->asXML();
$domcoup = new DOMDocument();
$domcoup = dom_import_simplexml($coupon);
$domordcoup = dom_import_simplexml($order->coupons);
$domcoup = $domordcoup->ownerDocument->importNode($domcoup, TRUE);
$domordcoup->appendChild($domcoup);
}
答案 0 :(得分:1)
我使用bigcommerce api,我可以通过身份证,送货地址获得订单,优惠券,优惠券,但我只使用Connection.php类和我自己的方法来获取。
你必须跟踪并检查卷曲网址是否正确,做var_dum($ url);
connection.php中的方法// Bigcommerce \ Api \ Connection
public function get($url, $query=false)
{
$this->initializeRequest();
if (is_array($query)) {
$url .= '?' . http_build_query($query);
}
var_dum($url);//**CHECK IF THIS URL IS BUILT CORRECTLY**//
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_HTTPGET, true);
curl_exec($this->curl);
return $this->handleResponse();
}
您还可以检查connection.php中的响应
private function handleResponse()
{
if (curl_errno($this->curl)) {
throw new NetworkError(curl_error($this->curl), curl_errno($this->curl));
}
var_dump(body);//CHECK THIS LINE
$body = ($this->useXml) ? $this->getBody() : json_decode($this->getBody());
$status = $this->getStatus();
var_dump(status);//CHECK THIS LINE
if ($status >= 400 && $status <= 499) {
if ($this->failOnError) {
throw new ClientError($body, $status);
} else {
$this->lastError = $body;
return false;
}
} elseif ($status >= 500 && $status <= 599) {
if ($this->failOnError) {
throw new ServerError($body, $status);
} else {
$this->lastError = $body;
return false;
}
}
if ($this->followLocation) {
$this->followRedirectPath();
}
var_dump(body);//CHECK THIS LINE
return $body;
}