我是quickbook的新手,我的客户希望将他的Magento订单与QuickBooks同步。他使用QuickBooks Enterprises桌面版来同步订单。我们正在使用PHP devkit Web连接器并尝试在doc中给出的示例示例来添加客户。
第一次添加客户示例工作正常,但在我尝试添加其他客户之后,我在快速Web连接器中收到了“需要数据交换”消息,并且用户未添加到quickbook中。
请帮我解决,并指导我如何将Magento订单添加到quickbook和客户。以下是我使用的代码:
<?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;
}
?>
答案 0 :(得分:3)
如果你阅读了示例文件中的注释,你会发现这个评论:
// 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连接器 这个框架使用'队列'概念。队列结束后 空的,没有别的事可做,你会得到那个消息。如果你 在队列中添加一些内容,然后它将处理这些项目 没有什么可做的,然后你会得到“没有数据 交换......“再次发出消息。
因此,例如,假设您希望每次都建立一个流程 客户是在您的商店内创建的,客户是在其中创建的 QuickBooks的。然后,您需要设置一个过程 客户是在您的商店中创建的,您排队添加的请求 客户到QuickBooks。
使用QuickBooks_Queue类进行排队 →enqueue()方法。
基本上问题是你没有告诉它做任何事情。该示例仅向QuickBooks添加一个客户。
如果您想添加更多客户,则需要将某些内容排队,以便尝试执行此操作。
当你排队时,请注意你必须在其他地方。不要在这个文件中加入错误(就像上面的评论所说的那样)。
因此,在您的应用中的其他位置,当您向应用数据库添加新客户时,您可能会有一些类似的代码:
// 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 ( ... )");
}
您应该修改您的应用代码,然后看起来像这样:
// 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);
}
作为旁注,请注意此块中的任何内容:
if (!QuickBooks_Utilities::initialized($dsn))
{
仅运行ONCE。因此,不要在这个块中做任何事情 - 它不会再次运行。