Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ptibogxiv committed Oct 1, 2023
1 parent b0be645 commit 149c028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions functions/data-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
28 changes: 22 additions & 6 deletions functions/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -26,7 +42,7 @@ function doliRelatedProducts($id) {
$related = null;
foreach ( $relatedproducts as $product ) {
$related .= apply_filters( 'doliproductlist', $product);
}
}
return $related;
} else {
return false;
Expand Down Expand Up @@ -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 = '<div id="doliform-product-'.$product->id.'" class="d-grid gap-2">';
$mstock = doliProductStock($product, $refresh, true);
if ( empty(doliconnectid('dolicart')) || empty(doliconnectid('dolicart')) ) {
$button .= "<a class='btn btn-block btn-info' href='".doliconnecturl('dolicontact')."?type=COM' role='button' title='".__( 'Contact us', 'doliconnect')."'>".__( 'Contact us', 'doliconnect').'</a>';
} elseif ( is_user_logged_in() && doliCheckModules('commande', $refresh) && doliconnectid('dolicart') > 0 ) {
if ($mstock['fk_parent_line']) {
if (!empty($related) && $mstock['fk_parent_line']) {
$button .= '<input id="qty-prod-'.$product->id.'" type="text" class="form-control form-control-sm" value="'.__( 'Linked item', 'doliconnect').'" aria-label="'.__( 'Linked item', 'doliconnect').'" style="text-align:center;" disabled readonly>';
} elseif ( $mstock['stock'] <= 0 || $mstock['m2'] < $mstock['step'] ) {
$button .= '<div class="input-group">';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -705,13 +721,13 @@ function doliproductlist($product) {
if ( ! empty(doliconnectid('dolicart')) ) {
$list .= "<div class='col-12 col-md-4'><center>";
$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 .= "</center></div>";
}
$list .= "</div></td></tr></table></li>";
return $list;
}
add_filter( 'doliproductlist', 'doliproductlist', 10, 1);
add_filter( 'doliproductlist', 'doliproductlist', 10, 2);

// list of products filter
function doliproductcard($product, $attributes) {
Expand Down

0 comments on commit 149c028

Please sign in to comment.