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