diff --git a/functions/data-request.php b/functions/data-request.php index 6dd24e1e..3992164f 100644 --- a/functions/data-request.php +++ b/functions/data-request.php @@ -813,7 +813,7 @@ function dolicart_request() { ]; if ($qty != $result['newqty']) { $response['modal'] = doliModalTemplate('CartInfos', __( 'Cart', 'doliconnect'), __( 'This item is not available in this quantity!', 'doliconnect'), ' '.__( 'Finalize the order', 'doliconnect').'', 'modal-lg'); } - elseif (doliCheckRelatedProducts($product->id)) { $response['modal'] = doliModalTemplate('CartInfos', __( 'Related products', 'doliconnect'), 'to do', '', 'modal-lg'); } + elseif (doliCheckRelatedProducts($product->id)) { $response['modal'] = doliModalTemplate('CartInfos', __( 'Related products', 'doliconnect'), doliRelatedProducts($product->id), '', 'modal-lg'); } wp_send_json_success($response); die(); } elseif (isset($_POST['modify']) && ($_POST['modify'] == "wish" || $_POST['modify'] == "unwish")) { diff --git a/functions/product.php b/functions/product.php index 16d661c5..4bac9cfa 100644 --- a/functions/product.php +++ b/functions/product.php @@ -19,6 +19,20 @@ function doliCheckRelatedProducts($id) { } } +function doliRelatedProducts($id) { + $request = "/relatedproducts/".$id; + $relatedproducts = callDoliApi("GET", $request, null, dolidelay('product', esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null))); + if ( !isset( $relatedproducts->error ) && $relatedproducts != null ) { + $related = null; + foreach ( $relatedproducts as $product ) { + $related .= apply_filters( 'doliproductlist', $product->id); + } + return $related; + } else { + return false; + } +} + function doliprice($object = null, $mode = "ttc", $currency = null) { global $current_user; if ( is_object($object) ) {