From 149c0285170bb1e3c5f7bb1a5246985545e01071 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 1 Oct 2023 12:46:58 +0200 Subject: [PATCH] wip --- functions/data-request.php | 3 +++ functions/product.php | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) 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 = '
'; $mstock = doliProductStock($product, $refresh, true); if ( empty(doliconnectid('dolicart')) || empty(doliconnectid('dolicart')) ) { $button .= "".__( 'Contact us', 'doliconnect').''; } elseif ( is_user_logged_in() && doliCheckModules('commande', $refresh) && doliconnectid('dolicart') > 0 ) { - if ($mstock['fk_parent_line']) { + if (!empty($related) && $mstock['fk_parent_line']) { $button .= ''; } elseif ( $mstock['stock'] <= 0 || $mstock['m2'] < $mstock['step'] ) { $button .= '
'; @@ -655,7 +671,7 @@ function doliconnect_supplier($product, $refresh = false){ } // list of products filter -function doliproductlist($product) { +function doliproductlist($product, $related = null) { global $current_user; $wish = 0; @@ -705,13 +721,13 @@ function doliproductlist($product) { if ( ! empty(doliconnectid('dolicart')) ) { $list .= "
"; $list .= doliProductPrice($product, null, esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null)); -$list .= doliProductCart($product, esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null)); +$list .= doliProductCart($product, esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null), $related); $list .= "
"; } $list .= "
"; return $list; } -add_filter( 'doliproductlist', 'doliproductlist', 10, 1); +add_filter( 'doliproductlist', 'doliproductlist', 10, 2); // list of products filter function doliproductcard($product, $attributes) {