diff --git a/functions/data-request.php b/functions/data-request.php index 0f547531..ef08efd8 100644 --- a/functions/data-request.php +++ b/functions/data-request.php @@ -804,8 +804,8 @@ 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); + if (!empty(doliRequiredRelatedProducts($product->id, false))) { + $result2 = doliRequiredRelatedProducts($product->id, true); } $response = [ 'message' => dolialert('success', $result['message']), diff --git a/functions/product.php b/functions/product.php index 3f37d46f..953355ed 100644 --- a/functions/product.php +++ b/functions/product.php @@ -16,9 +16,14 @@ function doliRequiredRelatedProducts($id, $valid = false) { if (empty($valid)) { return true; } else { - foreach ( $relatedproducts as $product ) { - //$related = apply_filters( 'doliproductlist', $product); + foreach ( $relatedproducts as $product ) { + $qty = $product->qty; + $product = callDoliApi("GET", "/products/".$product->id."?includestockdata=1&includesubproducts=true&includetrans=true", null, dolidelay('product', true)); + $mstock = doliProductStock($product, false, true); + $price = doliProductPrice($product, $qty, false, true); + $related = doliaddtocart($product, $mstock, $qty, $price, null, null); } + return $related; } } else { return false;