diff --git a/functions/data-request.php b/functions/data-request.php index ef08efd8..fa32e844 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 (!empty(doliRequiredRelatedProducts($product->id, false))) { - $result2 = doliRequiredRelatedProducts($product->id, true); + if (!empty(doliRequiredRelatedProducts($product->id, null, false))) { + $result2 = doliRequiredRelatedProducts($product->id, $qty, true); } $response = [ 'message' => dolialert('success', $result['message']), diff --git a/functions/product.php b/functions/product.php index 953355ed..1c6a7bbd 100644 --- a/functions/product.php +++ b/functions/product.php @@ -9,7 +9,7 @@ function doliproduct($object, $value) { } } -function doliRequiredRelatedProducts($id, $valid = false) { +function doliRequiredRelatedProducts($id, $qty = null, $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 ) { @@ -17,7 +17,7 @@ function doliRequiredRelatedProducts($id, $valid = false) { return true; } else { foreach ( $relatedproducts as $product ) { - $qty = $product->qty; + $qty2 = $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);