Neu JTL WooCommerce Connector Daten abgreifen und verwerten

Oqqi2009

Aktives Mitglied
7. Oktober 2019
8
2
We are trying to find what is the correct way to intercept the data sent from JTL to WooCommerce for a product.
We have a PHP Class which converts the data into an object with the correct attributes we need, but our issue is that we casn't seem to reliably intercept the request.
Sometimes the request gets intercepted and saved, sometimes not.
The issue is sometimes the \App\DB::insert() throws an error because the query did not insert, so is the issue perhaps related to some attributes causing an SQL error?
Or in either case, why do neither of these 2 variations below work? (keeping in mind we overrode "wp-content/plugins/woo-jtl-connector/includes/JtlConnector.php" as a testing measure - and that we removed irrelevant code):Alternative 1:


18:11 Uhr
public static function capture_request() {
global $wp; if (!empty($wp->request) && ($wp->request === 'jtlconnector' || $wp->request === 'index.php/jtlconnector')) { if (!get_magic_quotes_gpc()) {
self::unslash_gpc();
} $data = json_decode(file_get_contents('php://input'));
$parsedReq = NULL;
$isProductReq = $data && isset($data->params) && $data->method === 'product.push'; if ($isProductReq) {
$parsedReq = new \Ruuga\Integrations\JTL\ParsedRequest($data->params);
\App\DB::insert('wp_ruuga_jtl_postprocess', ['parsedrequest' => esc_sql(serialize($parsedReq))], FALSE);
} }
}

18:11 Uhr
Alternative 2:

18:12 Uhr
public static function capture_request() {
global $wp; if (!empty($wp->request) && ($wp->request === 'jtlconnector' || $wp->request === 'index.php/jtlconnector')) { if (!get_magic_quotes_gpc()) {
self::unslash_gpc();
} $data = json_decode($_POST['jtlrpc']);
$parsedReq = NULL;
$isProductReq = $data && isset($data->params) && $data->method === 'product.push'; if ($isProductReq) {
$parsedReq = new \Ruuga\Integrations\JTL\ParsedRequest($data->params);
\App\DB::insert('wp_ruuga_jtl_postprocess', ['parsedrequest' => esc_sql(serialize($parsedReq))], FALSE);
} }
}

18:12 Uhr
The main differentiator being:
$data = json_decode(file_get_contents('php://input'));
vs
$data = json_decode($_POST['jtlrpc']);

18:12 Uhr
//end
 

Achim L.

Sehr aktives Mitglied
3. Juli 2017
577
138
Hello Ouguang Fu,

best way to capture request will be to use plugin and events. Please take a look at our documentation describing plugins here: https://jtl-devguide.readthedocs.io/projects/jtl-connector/en/latest/plugins/introduction.html
and here https://github.com/jtl-software/connector-core/tree/2.7/src/Event where you can find various events that you can use.

In https://github.com/jtl-software/connector-plugin-rpcviewer repository you can find example of plugin that capture all receiving and sending rpc events. To use it clone in to woo-jtl-connector/plugins/rpcview and then visit http://yourwordpress.domanin/wp-content/plugins/jtl-woo-connector/plugins/rpcview/index.html
 
  • Gefällt mir
Reaktionen: Oqqi2009

Ähnliche Themen