dongtao1262 2015-03-12 14:22
浏览 58

bigcommerce api php获得订单优惠券

We are moving to BC and I am getting orders through the api while using the usexml function as I have to output a file for each order. I have been successful getting orders, products in the orders, and shipping address from BC. I have had to add a number of function to the bigcommerce.php library to do this, as while they may be referenced in the online docs, they don't actually exist in the library. My last step is getting the coupons associated with an order. The functions which I implemented in the library are as follows:

// Function missing from library addded 030215 PH - Get products on an order

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');             
    }

// Function missing form library added 030215 - Get Coupons on an order

    public static function getOrderCoupons($id)
    {
         return self::getCollection('/orders/' . $id . '/coupons','Order');       
    }

While similar in syntax I can't get the getOrderCoupons function to return coupon info to substitute for the link provided in the normal getOrders return.

I am using the same logic for coupon as executed for getting shipping addresses as shown below. Any solutions are greatly appreciated.

N.B Bigcommerce::useXML(); is used so XML strings are being used

      $shipping_xml = Bigcommerce::getOrderShippingAddresses($order->id);
      $shippings = simplexml_load_string($shipping_xml);

// Should only have one shipping address per order

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

// Should only have one coupon per order

    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);
          }   
  • 写回答

1条回答 默认 最新

  • dsj60862 2015-03-12 17:57
    关注

    i use the bigcommerce api and i can get orders,coupons,coupon by id,shipping addresses, but I only use the class Connection.php with my own methods to get ones.

    you have to track and check if the curl url is right, doing var_dum($url);

    method in 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();
    }
    

    You also can check the response in 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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入