Php 查询客户并在未退出时将客户添加到quickbook的示例

Php 查询客户并在未退出时将客户添加到quickbook的示例,php,magento,quickbooks,qbxml,Php,Magento,Quickbooks,Qbxml,请提供一个示例,说明如何查询客户是否退出quickbooks,如果客户不退出,则需要将该客户添加到quickbook 同步客户订单和销售订单时出现另一个错误 Message: No data exchange required Description: No data to exchange for this application. Job ending. 在分别测试quickbooks示例后,我将代码集成到magento站点中,这些示例运行良好,没有错误。

请提供一个示例,说明如何查询客户是否退出quickbooks,如果客户不退出,则需要将该客户添加到quickbook

同步客户订单和销售订单时出现另一个错误

    Message:
    No data exchange required

    Description:
    No data to exchange for this application. Job ending.
在分别测试quickbooks示例后,我将代码集成到magento站点中,这些示例运行良好,没有错误。但是在集成到magento中之后,我收到一条消息“此应用程序无需交换数据。作业结束。”

在magento控制器文件中写入的代码

    public function syncAction() {    

        $orderid =  $id    = $this->getRequest()->getParam('order_id');
        $orderdetails = Mage::getModel('sales/order')->load($id);
        // Get the id of the orders shipping address

        $realorderid = $orderdetails->getRealOrderId();
        $orderdate = $orderdetails->getCreatedAtDate();
        $customerid = $orderdetails->getCustomerId();
        $shippingId = $orderdetails->getShippingAddress()->getId();
        $billingId = $orderdetails->getBillingAddress()->getId();

        $items = $orderdetails->getAllItems();
        $itemcount=count($items);
        $order=array();
        foreach ($items as $itemId => $item) {
            $order['items']['name'][] = $item->getName();
            $order['items']['unitPrice'][]=$item->getPrice();
            $order['items']['sku'][]=$item->getSku();
            $order['items']['qty'][]=$item->getQtyToInvoice();
        }

        // Get shipping address data using the id
        $customer = Mage::getModel('customer/customer')->load($customerid);
        $saddress = Mage::getModel('sales/order_address')->load($shippingId);
        $baddress = Mage::getModel('sales/order_address')->load($billingId);


        foreach ($customer->getAddresses() as $address){
        }               

        $customers['id'] = $customer->getId();
        $customers['name'] = $customer->getName();
        $customers['firstname'] = $customer->getFirstname();
        $customers['lastname']  = $customer->getLastname();
        $customers['email']  = $customer->getEmail();   
        $customers['company'] = $customer->getCompany();            
        $customers['address1']   = $address->getStreet(-1);
        $customers['address2']   = '';
        $customers['postal_code'] = $address->getPostcode();
        $customers['city']        = $address->getCity();
        $customers['state']        = $address->getState();
        $customers['country']     = $address->getCountryModel()->getIso3Code();
        $customers['phone_number'] = $address->getTelephone();
        $customers['altphone']   = '';
        $customers['fax_number'] = $address->getFax();

        $order['customer'] = $customerid;
        $order['customername'] = $customer->getName();
        $order['order_id'] = $orderid;
        $order['realorder_id'] = $realorderid;
        $order['orderdate'] = $orderdate;
        $order['shipaddress']['firstname'] = $saddress->getFirstname();
        $order['shipaddress']['lastname']  = $saddress->getLastname();
        $order['shipaddress']['address1']   = $saddress->getStreet(-1);
        $order['shipaddress']['address2']   = $saddress->getStreet(1);
        $order['shipaddress']['postal_code'] = $saddress->getPostcode();
        $order['shipaddress']['city']        = $saddress->getCity();
        $order['shipaddress']['state']        = $baddress->getState();
        $order['shipaddress']['country']     = $saddress->getCountryModel()->getIso3Code();
        $order['shipaddress']['phone_number'] = $saddress->getTelephone();

        $order['billaddress']['firstname'] = $baddress->getFirstname();
        $order['billaddress']['lastname']  = $baddress->getLastname();
        $order['billaddress']['address1']   = $baddress->getStreet(-1);
        $order['billaddress']['address2']   = $baddress->getStreet(1);
        $order['billaddress']['postal_code'] = $baddress->getPostcode();
        $order['billaddress']['city']        = $baddress->getCity();
        $order['billaddress']['state']        = $baddress->getState();
        $order['billaddress']['country']     = $baddress->getCountryModel()->getIso3Code();
        $order['billaddress']['phone_number'] = $baddress->getTelephone();


        // Display the shipping address data array on screen
        //var_dump($address);
        require_once Mage::getBaseDir().'/wscabinertyqb/config.php';
        $Queue = new QuickBooks_WebConnector_Queue($dsn);
        $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER,$customerid,'', $customers);
        $Queue->enqueue(QUICKBOOKS_ADD_SALESORDER,$realorderid,'', $order);
        //print_r($orderdetails);
        $this->_redirect('*/*/');
        //echo "Working";
    }
qwc文件代码

    <?xml version="1.0"?>
    <QBWCXML>
        <AppName>Wholesale Cabinetry LLC</AppName>
        <AppID></AppID>
        <AppURL>https://mysiteurl.com/store/wscabinertyqb/wscabinertyqb.php</AppURL>
        <AppDescription></AppDescription>
        <AppSupport>https://mysiteurl.com/store/wscabinertyqb/wscabinertyqb.php?support=1</AppSupport>
        <UserName>wscabinetry</UserName>
        <OwnerID>{90A44FB7-33D9-4818-AC85-AC86A7E7D1EE}</OwnerID>
        <FileID>{57F3B9B6-86F1-4FCE-B1FF-967DE1813D22}</FileID>
        <QBType>QBFS</QBType>
        <Scheduler>
            <RunEveryNMinutes>60</RunEveryNMinutes>
        </Scheduler>
        <IsReadOnly>false</IsReadOnly>
    </QBWCXML>

批发橱柜有限公司
https://mysiteurl.com/store/wscabinertyqb/wscabinertyqb.php
https://mysiteurl.com/store/wscabinertyqb/wscabinertyqb.php?support=1
家具
{90A44FB7-33D9-4818-AC85-AC86A7E7D1EE}
{57F3B9B6-86F1-4FCE-B1FF-967DE1813D22}
QBFS
60
假的
webconnector文件wscabinertyqb.php

    <?php
    require_once 'config.php';
    require_once 'functions.php';

    // Map QuickBooks actions to handler functions
    $map = array(
        QUICKBOOKS_QUERY_CUSTOMER => array( '_quickbooks_customer_query_request', '_quickbooks_customer_query_response', '_quickbooks_error_handler' ),
        QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
        QUICKBOOKS_ADD_SALESORDER => array( '_quickbooks_salesorder_add_request', '_quickbooks_salesorder_add_response' ),
        );

    $errmap = array(
                3070 =>  '_quickbooks_error_stringtoolong',
                3140 => '_quickbooks_reference_error',
                '*' => '_quickbooks_error_handler',
            );

    /*$hooks = array(
        QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess',     // call this whenever a successful login occurs
        );*/

    $hooks = array();
    $log_level = QUICKBOOKS_LOG_DEVELOP;
    $soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
    $soap_options = array();
    $handler_options = array(
                'deny_concurrent_logins' => false, 
                'deny_reallyfast_logins' => false, 
            );      
    $soap_options = array();
    $driver_options = array();
    $callback_options = array();    

    // Create a new server and tell it to handle the requests
    // __construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
    $Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);

    $response = $Server->handle(true, true);

quickbooks web connector基于队列系统(先进先出)的方式,因此您当前的实现将无法有效工作,您必须在执行
quickbooks\u QUERY\u CUSTOMER
后在magento中存储
列表ID
全名是quickbooks向magento Web服务器发出的单独请求

更好的方法是在magento中存储
\u quickbooks\u customer\u add\u response
方法中的客户
列表ID
全名

然后

\u quickbooks\u salesorder\u add\u request
方法中,根据订单号或客户id查找
ListID
FullName


如果有人在quickbooks中删除客户,您也可能会遇到问题,您可以只在quickbooks中添加客户,然后在magento中添加更新
全名

谢谢R.S.的回复,您能帮我修复问题中提到的错误吗
    <?php
    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', 1);

    if (function_exists('date_default_timezone_set')){  
        date_default_timezone_set('America/New_York'); 
    }

    require_once 'QuickBooks.php';
    //require_once '../app/Mage.php';

    $user = 'wscabinetry';
    $pass = 'wscabinetry@123';


    $dsn = 'mysql://user:root#@localhost/wholecab';

    define('QB_QUICKBOOKS_DSN', $dsn);

    if (!QuickBooks_Utilities::initialized($dsn)){
        // Initialize creates the neccessary database schema for queueing up requests and logging
        QuickBooks_Utilities::initialize($dsn);

        // This creates a username and password which is used by the Web Connector to authenticate
        QuickBooks_Utilities::createUser($dsn, $user, $pass);   
    }

    QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
    <?php

    function _quickbooks_salesorder_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){

        mysql_query("INSERT INTO quickbooks_salesorder (customer_id,order_id,realorder_id) VALUES ('".$order['customer']."','".$order['order_id']."','".$order['realorder_id']."')");
        $order = $extra;

        // We're just testing, so we'll just use a static test request:
        $xml = '<?xml version="1.0" encoding="utf-8"?>
            <?qbxml version="5.0"?>
            <QBXML>
                <QBXMLMsgsRq onError="stopOnError">
                    <SalesOrderAddRq requestID="'.$requestID.'">
                        <SalesOrderAdd>
                            <CustomerRef>
                                <FullName>'.$order['customername'].'</FullName>
                            </CustomerRef>
                            <TxnDate>'.$order['orderdate'].'</TxnDate>
                            <RefNumber>'.$order['realorder_id'].'</RefNumber>
                            <BillAddress>
                                <Addr1>'.$order['billaddress']['address1'].'</Addr1>
                                <Addr2>'.$order['billaddress']['address2'].'</Addr2>
                                <City>'.$order['billaddress']['city'].'</City>
                                <State>'.$order['billaddress']['state'].'</State>
                                <PostalCode>'.$order['billaddress']['postal_code'].'</PostalCode>
                                <Country>'.$order['billaddress']['country'].'</Country>
                            </BillAddress>
                            <ShipAddress>
                                <Addr1>'.$order['shipaddress']['address1'].'</Addr1>
                                <Addr2>'.$order['shipaddress']['address2'].'</Addr2>
                                <City>'.$order['shipaddress']['city'].'</City>
                                <State>'.$order['shipaddress']['state'].'</State>
                                <PostalCode>'.$order['shipaddress']['postal_code'].'</PostalCode>
                                <Country>'.$order['shipaddress']['country'].'</Country>
                            </ShipAddress>                      
                            <Memo></Memo>';

                        for($i=0;$i < count($order['items']);$i++){

                        $xml .= '<SalesOrderLineAdd>
                                        <ItemRef>
                                        <FullName>'.$order['items']['sku'][$i].'</FullName>
                                        </ItemRef>
                                        <Desc>'.$order['items']['name'][$i].'</Desc>
                                        <Quantity>'.$order['items']['qty'][$i].'</Quantity>
                                        <Amount>'.$order['items']['unitPrice'][$i].'</Amount>
                                </SalesOrderLineAdd>';
                        }


                $xml .= '   </SalesOrderAdd>
                    </SalesOrderAddRq>
                </QBXMLMsgsRq>
            </QBXML>';
        echo $xml;
        exit;
        return $xml;
    }

    function _quickbooks_salesorder_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents){
        mysql_query("
                UPDATE 
                    quickbooks_salesorder 
                SET 
                    quickbooks_listid = '" . mysql_real_escape_string($idents['ListID']) . "', 
                    quickbooks_editsequence = '" . mysql_real_escape_string($idents['EditSequence']) . "'
                WHERE 
                    id = " . (int) $ID);

        $content = "##########################################################";
        $content .= $idents;
        $content .= "##########################################################";
        $content .= $xml;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","a");
        fwrite($fp,$content);
        fclose($fp);
        return; 
    }

    function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){


        mysql_query("INSERT INTO quickbooks_customers (customer_id) VALUES ('".$customer['id']."')");
        $customer = $extra;
        // We're just testing, so we'll just use a static test request:  
        $xml = '<?xml version="1.0" encoding="utf-8"?>
            <?qbxml version="5.0"?>
            <QBXML>
                <QBXMLMsgsRq onError="stopOnError">
                    <CustomerAddRq requestID="' . $requestID . '">
                        <CustomerAdd>
                            <Name>'.$customer['name'].'</Name>
                            <CompanyName>'.$customer['company'].'</CompanyName>
                            <FirstName>'.$customer['firstname'].'</FirstName>
                            <LastName>'.$customer['lastname'].'</LastName>
                            <BillAddress>
                                <Addr1>'.$customer['address1'].'</Addr1>
                                <Addr2>'.$customer['address2'].'</Addr2>
                                <City>'.$customer['city'].'</City>
                                <State>'.$customer['state'].'</State>
                                <PostalCode>'.$customer['postal_code'].'</PostalCode>
                                <Country>'.$customer['country'].'</Country>
                            </BillAddress>
                            <Phone>'.$customer['phone_number'].'</Phone>
                            <AltPhone>'.$customer['altphone'].'</AltPhone>
                            <Fax>'.$customer['fax_number'].'</Fax>
                            <Email>'.$customer['email'].'</Email>
                            <Contact>'.$customer['name'].'</Contact>
                        </CustomerAdd>
                    </CustomerAddRq>
                </QBXMLMsgsRq>
            </QBXML>';

        return $xml;
    }

    /**
     * Receive a response from QuickBooks 
     */
    function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents){

        mysql_query("
                UPDATE 
                    quickbooks_customers 
                SET 
                    quickbooks_listid = '" . mysql_real_escape_string($idents['ListID']) . "', 
                    quickbooks_editsequence = '" . mysql_real_escape_string($idents['EditSequence']) . "'
                WHERE 
                    id = " . (int) $ID);

        $content = "##########################################################";
        $content .= $idents;
        $content .= "##########################################################";
        $content .= $xml;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","a");
        fwrite($fp,$content);
        fclose($fp);
        return; 
    }

    function _quickbooks_customer_query_request($requestID , $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){
        /*$xml = '<?xml version="1.0" encoding="utf-8"?>
            <?qbxml version="5.0"?>
            <QBXML>
              <QBXMLMsgsRq onError="continueOnError">
                <CustomerQueryRq>
                  <MaxReturned>5</MaxReturned>
                  <FromModifiedDate>1984-01-29T22:03:19</FromModifiedDate>
                  <OwnerID>0</OwnerID>
                </CustomerQueryRq>
              </QBXMLMsgsRq>
            </QBXML>';*/
            $xml = '<?xml version="1.0" encoding="utf-8"?>
                    <?qbxml version="5.0"?>
                    <QBXML>
                        <QBXMLMsgsRq onError="continueOnError">
                            <CustomerQueryRq requestID="' . $requestID . '" iterator="Start">
                                <FullName>'.$extra[''].'</FullName>
                            </CustomerQueryRq>
                        </QBXMLMsgsRq>
                    </QBXML>';
        return $xml;
    }

    function _quickbooks_customer_query_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents){ 
        $content = $xml;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","wb");
        fwrite($fp,$content);
        fclose($fp);
    }

    function _quickbooks_error_handler($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg){
        $content = "##########################################################";
        $content .= $idents;
        $content .= "##########################################################";
        $content .= $xml;
        $content .= "##########################################################";
        $content .= $errmsg;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","a");
        fwrite($fp,$content);
        fclose($fp);
    }

    function _quickbooks_reference_error($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg){
        $content = "##########################################################";
        $content .= $idents;
        $content .= "##########################################################";
        $content .= $xml;
        $content .= "##########################################################";
        $content .= $errmsg;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","a");
        fwrite($fp,$content);
        fclose($fp);
    }

    function _quickbooks_invoice_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){
        // We're just testing, so we'll just use a static test request:
        $xml = '<?xml version="1.0" encoding="utf-8"?>
            <?qbxml version="5.0"?>
            <QBXML>
              <QBXMLMsgsRq onError="stopOnError">
                <InvoiceAddRq requestID="'.$requestID.'">
                  <InvoiceAdd>
                    <CustomerRef>
                      <FullName>Muralidhar, LLC (1249573828)</FullName>
                    </CustomerRef>
                    <TxnDate>2014-04-23</TxnDate>
                    <RefNumber>9668</RefNumber>
                    <BillAddress>
                      <Addr1>56 Cowles Road</Addr1>
                      <City>Willington</City>
                      <State>CT</State>
                      <PostalCode>06279</PostalCode>
                      <Country>United States</Country>
                    </BillAddress>
                    <PONumber></PONumber>
                    <Memo></Memo>

                    <InvoiceLineAdd>
                      <ItemRef>
                        <FullName>Test Item</FullName>
                      </ItemRef>
                      <Desc>Item 1 Description Goes Here</Desc>
                      <Quantity>1</Quantity>
                      <Rate>295</Rate>
                    </InvoiceLineAdd>

                    <InvoiceLineAdd>
                      <ItemRef>
                        <FullName>Test Item</FullName>
                      </ItemRef>
                      <Desc>Item 2 Description Goes Here</Desc>
                      <Quantity>3</Quantity>
                      <Rate>25</Rate>
                    </InvoiceLineAdd>

                  </InvoiceAdd>
                </InvoiceAddRq>
              </QBXMLMsgsRq>
            </QBXML>';

        return $xml;
    }

    function _quickbooks_invoice_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents){
        $content = "##########################################################";
        $content .= $idents;
        $content .= "##########################################################";
        $content .= $xml;
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/store/qbsdkm/docs/myText.txt","wb");
        fwrite($fp,$content);
        fclose($fp);
        return; 
    }
if(ListID or FullName)
  QUICKBOOKS_ADD_SALESORDER
else
  QUICKBOOKS_ADD_CUSTOMER
  QUICKBOOKS_ADD_SALESORDER