“不需要数据交换"; [英] "no data exchange required"

查看:77
本文介绍了“不需要数据交换";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Quickbook的新手,我的客户希望将他的Magento订单与QuickBooks同步.他使用QuickBooks Enterprises桌面版来同步订单.我们正在使用PHP devkit Web连接器,并尝试使用文档中给出的示例示例来添加客户.

I am new to quickbook and my client wants to sync his Magento orders with QuickBooks. He uses QuickBooks Enterprises desktop edition to sync the orders. We are using PHP devkit web connector and trying sample example given in the doc to add customer.

第一次添加客户示例运行良好,但是此后,当我尝试添加另一个客户时,我在快速Web连接器中收到需要数据交换"消息,并且未将用户添加到quickbook中.

For the first time the add customer example worked fine but after that when I tried to add another customer, I got 'Data Exchange Required' message in quick web connector and the user was not added to quickbook.

请帮助我解决该问题,并指导我如何将Magento订单添加到Quickbook和客户.以下是我使用的代码:

Please help me to solve it and guide me how to add the Magento order to quickbook and customers. Below is the code I was using:

    <?php

    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', true);

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

    require_once '../QuickBooks.php';

    $user = 'quickbooks';
    $pass = 'password';

    $map = array(
        QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
        QUICKBOOKS_ADD_INVOICE => array( '_quickbooks_invoice_add_request', '_quickbooks_invoice_add_response' )
        );

    $errmap = array();
    $hooks = array();

    $log_level = QUICKBOOKS_LOG_DEVELOP;        

    $dsn = 'mysql://root:root@localhost/quickbooks_server';

    if (!QuickBooks_Utilities::initialized($dsn))
    {
        QuickBooks_Utilities::initialize($dsn);
        QuickBooks_Utilities::createUser($dsn, $user, $pass);

        $primary_key_of_your_customer = 5;
        $Queue = new QuickBooks_WebConnector_Queue($dsn);
        $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
        $Queue->enqueue(QUICKBOOKS_ADD_INVOICE, $primary_key_of_your_customer);
    }

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

    function _quickbooks_customer_add_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="2.0"?>
            <QBXML>
                <QBXMLMsgsRq onError="stopOnError">
                    <CustomerAddRq requestID="' . $requestID . '">
                        <CustomerAdd>
                            <Name>Muralidhar, LLC (' . mt_rand() . ')</Name>
                            <CompanyName>Muralidhar, LLC</CompanyName>
                            <FirstName>Muralidhar</FirstName>
                            <LastName>Jampa</LastName>
                            <BillAddress>
                                <Addr1>Muralidhar, LLC</Addr1>
                                <Addr2>134 Stonemill Road</Addr2>
                                <City>NewYork</City>
                                <State>NY</State>
                                <PostalCode>06268</PostalCode>
                                <Country>United States</Country>
                            </BillAddress>
                            <Phone>860-634-1602</Phone>
                            <AltPhone>860-429-0021</AltPhone>
                            <Fax>860-429-5183</Fax>
                            <Email>murarimaniram@gmail.com</Email>
                            <Contact>Muralidhar Jampa</Contact>
                        </CustomerAdd>
                    </CustomerAddRq>
                </QBXMLMsgsRq>
            </QBXML>';

        return $xml;
    }


    function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
    {
        return; 
    }

    function _quickbooks_invoice_add_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="2.0"?>
                <QBXML>
                  <QBXMLMsgsRq onError="stopOnError">
                    <InvoiceAddRq requestID="' . $requestID . '">
                      <InvoiceAdd>
                        <CustomerRef>
                          <FullName>Muralidhar Jampa</FullName>
                        </CustomerRef>
                        <TxnDate>2014-04-14</TxnDate>
                        <RefNumber>9869</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)
    {
        return; 
    }
    ?>

推荐答案

如果您阅读示例文件中的注释,则会发现以下注释:

If you read the comments in the example file, you'll find this comment:

    // IMPORTANT NOTE: This particular example of queueing something up will 
    //  only ever happen *once* when these scripts are first run/used. After 
    //  this initial test, you MUST do your queueing in another script. DO NOT 
    //  DO YOUR OWN QUEUEING IN THIS FILE! See 
    //  docs/example_web_connector_queueing.php for more details and examples 
    //  of queueing things up.

以及此页面的链接:

哪个说:

没有数据可交换.没事做Web连接器 并且此框架使用队列"概念进行工作.一旦队列是 空的,无事可做,您会收到该消息.如果你 在队列中添加一些东西,然后它将处理这些项目,直到 没什么可做的,然后您将获得无数据" 再次交换..."消息.

There's no data to exchange. There's nothing to do. The Web Connector and this framework work using a 'queue' concept. Once the queue is empty, there's nothing else to do, and you'll get that message. If you add something to the queue, then it will process those items until there's nothing left to do, and then you'll get the "No Data Exchange…" message again.

例如,假设您要建立一个流程,每次 客户是在您的商店中创建的,客户是在以下位置创建的 QuickBooks.然后,您想建立一个流程, 客户在您的商店中创建,您将添加请求排队 客户使用QuickBooks.

So, for instance, say you want to build a process whereby every time a customer is created within your store, the customer gets created in QuickBooks. You'd then want to set up a process where when that customer is created within your store, you queue up a request to add the customer to QuickBooks.

您可以使用QuickBooks_Queue类进行排队,并且 →enqueue()方法.

You do your queueing using the QuickBooks_Queue class, and the →enqueue() method.

所以本质上问题是您还没有告诉它做任何事情.该示例仅将一个客户添加到QuickBooks.

So essentially the problem is you haven't told it to do anything. The example only adds ONE customer to QuickBooks.

如果要添加更多客户,则需要排队,以便它尝试这样做.

If you want to add more customers, you need to queue something up so that it tries to do that.

排队时,请注意,您必须在其他地方这样做.不要在此文件中排队(就像上面的评论一样).

When you queue something up, note that you must do that somewhere else. DO NOT QUEUE STUFF UP IN THIS FILE (just like the comments above say).

因此,在应用程序中的其他位置,当您向应用程序数据库中添加新客户时,您可能会有类似以下的代码:

So somewhere else in your app, you probably have some code like this for when you add a new customer to your app database:

// end-user submitted a form, let's save the customer to our database
if ($_POST['customer_name'])
{
  mysql_query("INSERT INTO my_customer_table ( ... ) VALUES ( ... )");
}

您应该修改您的应用程序代码,以使它看起来像这样:

You should modify your app code to then look something like this:

// end-user submitted a form, let's save the customer to our database
if ($_POST['customer_name'])
{
  mysql_query("INSERT INTO my_customer_table ( ... ) VALUES ( ... )");

  // ... and queue them up to be added to QB
  $primary_key_of_your_customer = mysql_insert_id();
  $Queue = new QuickBooks_WebConnector_Queue($dsn);
  $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}

请注意,此块中的所有内容:

As a side note, note that anything in this block:

if (!QuickBooks_Utilities::initialized($dsn))
{

仅运行一次.因此,在此块中不要执行任何操作-它永远不会再运行.

Only runs ONCE. So don't do anything in this block - it won't ever run again.

这篇关于“不需要数据交换";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆