如何将收发地址和帐单邮寄地址从Bigcommerce发送到cloudcommercepro

时间:2018-05-29 07:42:37

标签: php xml api bigcommerce

有没有Bigcommerce开发者?请帮我解决Bigcommerce问题。 我有Bigcommerce api的所有工作代码,但此代码不发送 shipping_addresses和billing_address to cloud commerce pro。 我的代码出了什么问题?

function createCloudCommerceOrderXML($customr_id, $order)
{

    echo "<br/> creating XML for cloud commerce order";
     $shipping_method1 = 'Free Shipping';
     $shipping_method2 = 'Royal Mail';
     $shipping_method2_2 = 'Next Day';
     $shipping_method2_3 = 'International';
     $shipping_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
    if($order->shipping_addresses[0]->shipping_method == $shipping_method1)
    {
            $shipping_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
    }else if(substr($order->shipping_addresses[0]->shipping_method, 0, strlen($shipping_method2)) === $shipping_method2)
    {
        if(strpos($order->shipping_addresses[0]->shipping_method, $shipping_method2_2) !== false)
        {
            $shipping_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
        }else if(strpos($order->shipping_addresses[0]->shipping_method, $shipping_method2_3) !== false)
        {
            $shipping_service = 'Royal Mail International Business Mail Large Letter (IG1)';
        }

    }


     $billing_method1 = 'Free Shipping';
     $billing_method2 = 'Royal Mail';
     $billing_method2_2 = 'Next Day';
     $billing_method2_3 = 'International';
     $billing_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
    if($order->billing_address == $billing_method1)
    {
            $billing_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
    }else if(substr($order->billing_address, 0, strlen($billing_method2)) === $billing_method2)
    {
        if(strpos($order->billing_address, $billing_method2_2) !== false)
        {
            $billing_service = 'Royal Mail 48 Large Letter (RM48 -CRL)';
        }else if(strpos($order->billing_address, $billing_method2_3) !== false)
        {
            $billing_service = 'Royal Mail International Business Mail Large Letter (IG1)';
        }

    }




    $order_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org/\">  
        <SOAP-ENV:Body>
            <ns1:createOrder>
                <ns1:request>
                      <ns1:BrandID>422</ns1:BrandID>
                      <ns1:SecurityHash>166,3,183,196,194,4,128,186,201,103,155,115,48,20,127,218,3,161,9,122,175,126,12,118,81,153,183,221,201,176,189,7,162,115,24,127,5,175,87,1,199,131,155,223,238,178,26,186,163,218,62,121,182,185,192,80,134,233,9,138,147,165,9,130,27,94,190,240,195,236,100,127,76,141,136,168,61,254,56,11,169,125,175,50,185,0,129,98,145,245,44,84,137,55,39,80,194,27,2,155,135,5,113,194,23,83,162,157,197,92,169,197,229,223,0,95,154,220,136,63,166,80,50,233,203,5,20,235</ns1:SecurityHash>
                       <ns1:Content>        


                            <ns1:nCustomerID>".$customr_id."</ns1:nCustomerID>        
                            <ns1:ExternalReference>".$order->id."</ns1:ExternalReference> 
                            <ns1:Reference>".$order->id."</ns1:Reference> 
                            <ns1:Note>".$order->notes."</ns1:Note> 
                            <ns1:intBrandID>422</ns1:intBrandID>
                            <ns1:orderItems>";    


                  foreach($order->products as $product)
                    {       

                            $product_id = getProductId($product->sku);

                            $order_xml =    $order_xml . "<ns1:APIOrderItem>            

                            <ns1:ProductID>".$product_id."</ns1:ProductID>
                            <ns1:VatRateID>5</ns1:VatRateID>            
                            <ns1:Quantity>".$product->quantity."</ns1:Quantity>            
                            <ns1:Price>".$product->base_price."</ns1:Price>                       
                            <ns1:RowTotalNet>".$product->base_total."</ns1:RowTotalNet>            
                            <ns1:RowTotalVAT>".$product->total_tax."</ns1:RowTotalVAT>              
                            <ns1:RowTotalGross>".$product->total_inc_tax."</ns1:RowTotalGross>                                            
                            <ns1:UseNetPrice>true</ns1:UseNetPrice>            
                        </ns1:APIOrderItem>";
                     }           


                            $order_xml = $order_xml . "</ns1:orderItems>
                            **<ns1:ShippingService>".$shipping_service."</ns1:ShippingService>
                                <ns1:APIOrderBillingAddress>
                            <ns1:BillingAddress>

                                <ns1:BillingContactFirstName>".$order->billing_address->first_name."</ns1:BillingContactFirstName>
                                <ns1:BillingContactLastName>".$order->billing_address->last_name."</ns1:BillingContactLastName>
                                <ns1:BillingAddress1>".$order->billing_address->street_1."</ns1:BillingAddress1>
                                <ns1:BillingAddress2>".$order->billing_address->street_2."</ns1:BillingAddress2>
                                <ns1:BillingTown>".$order->billing_address->city."</ns1:BillingTown>
                                <ns1:BillingCountry>".$order->billing_address->country."</ns1:BillingCountry>
                                <ns1:BillingPostCode>".$order->billing_address->zip."</ns1:BillingPostCode>
                                <ns1:BillingTelephone>".$order->billing_address->phone."</ns1:BillingTelephone>
                                <ns1:BillingMobile>".$order->billing_address->phone."</ns1:BillingMobile>

                            </ns1:BillingAddress>
                                </ns1:APIOrderBillingAddress>

                                <ns1:APIOrderShippingAddress>
                            <ns1:ShippingAddress>
                                <ns1:ShippingContactFirstName>".$order->shipping_addresses[0]->first_name."</ns1:ShippingContactFirstName>

                                <ns1:ShippingContactLastName>".$order->shipping_addresses[0]->last_name."</ns1:ShippingContactLastName>
                                <ns1:ShippingAddress1>".$order->shipping_addresses[0]->street_1."</ns1:ShippingAddress1>
                                <ns1:ShippingAddress2>".$order->shipping_addresses[0]->street_2."</ns1:ShippingAddress2>
                                <ns1:ShippingTown>".$order->shipping_addresses[0]->city."</ns1:ShippingTown>
                                <ns1:ShippingCountry>".$order->shipping_addresses[0]->country."</ns1:ShippingCountry>
                                <ns1:ShippingPostCode>".$order->shipping_addresses[0]->zip."</ns1:ShippingPostCode>
                                <ns1:ShippingTelephone>".$order->shipping_addresses[0]->phone."</ns1:ShippingTelephone>
                            </ns1:ShippingAddress>        
                                </ns1:APIOrderShippingAddress>**

                        </ns1:Content>            
                     </ns1:request>            
                 </ns1:createOrder>            
            </SOAP-ENV:Body>            
        </SOAP-ENV:Envelope>";



    echo "<pre>";
    echo "<br/>" . $order_xml;
    echo "</pre>";


    return $order_xml;
}

这是我从BC向CCP发送订单时得到的结果。

结算地址:

[billing_address] => stdClass Object
                (
                    [first_name] => Anna
                    [last_name] => Jesson
                    [company] => 
                    [street_1] => 5 Swan Close
                    [street_2] => Cheslyn Hay
                    [city] => Walsall
                    [state] => 
                    [zip] => WS6 7LF
                    [country] => United Kingdom
                    [country_iso2] => GB
                    [phone] => 07736706986
                    [email] => n4rni4@yahoo.co.uk
                    [form_fields] => Array
                        (
                        )

                )

送货地址:

(
            [id] => 6245
            [company] => 
            [first_name] => Anna
            [last_name] => Jesson
            [email] => n4rni4@yahoo.co.uk
            [phone] => 07736706986
            [form_fields] => 
            [date_created] => Sat, 26 May 2018 01:25:26 +0000
            [date_modified] => Sat, 26 May 2018 01:25:27 +0000
            [store_credit] => 0.0000
            [registration_ip_address] => 2.220.66.19
            [customer_group_id] => 0
            [notes] => 
            [tax_exempt_category] => 
            [reset_pass_on_login] => 
            [accepts_marketing] => 1
            [addresses] => stdClass Object
                (
                    [url] => https://www.body4real.co.uk/api/v2/customers/6245/addresses.json
                    [resource] => /customers/6245/addresses
                )

        )

您的回答将会受到赞赏。 提前谢谢。

0 个答案:

没有答案