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

添加客户示例第一次工作正常,但在此之后,当我尝试添加另一个客户时,我在快速Web连接器中收到了“需要数据交换”消息,并且用户未添加到quickbook中.

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

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"?>

Muralidhar, LLC (' . mt_rand() . ')

Muralidhar, LLC

Muralidhar

Jampa

Muralidhar, LLC

134 Stonemill Road

NewYork

NY

06268

United States

860-634-1602

860-429-0021

860-429-5183

murarimaniram@gmail.com

Muralidhar Jampa

';

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"?>

Muralidhar Jampa

2014-04-14

9869

56 Cowles Road

Willington

CT

06279

United States

Test Item

Item 1 Description Goes Here

1

295

Test Item

Item 2 Description Goes Here

3

25

';

return $xml;

}

function _quickbooks_invoice_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)

{

return;

}

?>

解决方法:

如果您阅读示例文件中的注释,您将找到以下注释:

// 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.

以及此页面的链接:

哪个说:

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.

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.

You do your queueing using the QuickBooks_Queue class, and the

→enqueue() method.

所以基本上问题是你没有告诉它做任何事情.该示例仅向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.因此,不要在这个块中做任何事情 – 它不会再次运行.

标签:php,magento,web,quickbooks,qbxml

来源: https://codeday.me/bug/20191003/1847487.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐