diff --git a/functions/data-request.php b/functions/data-request.php index 5d29b209..0f547531 100644 --- a/functions/data-request.php +++ b/functions/data-request.php @@ -804,6 +804,9 @@ function dolicart_request() { } $price = doliProductPrice($product, $qty, false, true); $result = doliaddtocart($product, $mstock, $qty, $price, isset($_POST['product-add-timestamp_start'])?trim($_POST['product-add-timestamp_start']):null, isset($_POST['product-add-timestamp_end'])?trim($_POST['product-add-timestamp_end']):null); + if (doliRequiredRelatedProducts($product->id, false)) { + doliRequiredRelatedProducts($product->id, true); + } $response = [ 'message' => dolialert('success', $result['message']), 'newqty' => $result['newqty'], diff --git a/functions/product.php b/functions/product.php index 564ebe3f..73182896 100644 --- a/functions/product.php +++ b/functions/product.php @@ -9,6 +9,22 @@ function doliproduct($object, $value) { } } +function doliRequiredRelatedProducts($id, $valid = false) { + $request = "/relatedproducts/".$id."?required=true"; + $relatedproducts = callDoliApi("GET", $request, null, dolidelay('product', esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null))); + if ( !isset( $relatedproducts->error ) && $relatedproducts != null ) { + if (empty($valid)) { + return true; + } else { + foreach ( $relatedproducts as $product ) { + //$related = apply_filters( 'doliproductlist', $product); + } + } + } else { + return false; + } +} + function doliCheckRelatedProducts($id) { $request = "/relatedproducts/".$id; $relatedproducts = callDoliApi("GET", $request, null, dolidelay('product', esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null))); @@ -26,7 +42,7 @@ function doliRelatedProducts($id) { $related = null; foreach ( $relatedproducts as $product ) { $related .= apply_filters( 'doliproductlist', $product); - } + } return $related; } else { return false; @@ -364,14 +380,14 @@ function doliaddtocart($product, $mstock, $quantity, $price, $timestart = null, } } -function doliProductCart($product, $refresh = null, $wishlist = true) { +function doliProductCart($product, $refresh = null, $wishlist = true, $related = null) { global $current_user; $button = '