Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ptibogxiv committed Nov 2, 2024
1 parent b6a30ee commit 5c8844b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
51 changes: 30 additions & 21 deletions functions/data-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,11 @@ function dolipaymentmethod_request(){

function dolicart_request() {
global $current_user;
if ( wp_verify_nonce( trim($_POST['dolicart-nonce']), 'dolicart-nonce')) {
if ( wp_verify_nonce( trim($_POST['dolicart-nonce']), 'dolicart-nonce') ) {
$thirdparty = doliConnect('thirdparty', $current_user);
if (isset($_POST['case']) && $_POST['case'] == "updateLine") {
$link = trim($_POST['dolicart-nonce']);
if ( isset($_POST['case']) && $_POST['case'] == "updateLine" && false === get_transient( $link ) ) {
set_transient( $link, true, 5);
$product = callDoliApi("GET", "/products/".trim($_POST['id'])."?includesubproducts=true&includetrans=true", null, dolidelay('product'));
$mstock = doliProductStock($product, true, true, isset($_POST['product-array'])?$_POST['product-array']:array());
if (isset($_POST['lineid']) && !empty($_POST['lineid'])) $mstock['lineid'] = trim($_POST['lineid']);
Expand All @@ -789,7 +791,7 @@ function dolicart_request() {
} else {
$productarray = array();
}
if (isset($_POST['modify']) && $_POST['modify'] == "delete") {
if ( isset($_POST['modify']) && $_POST['modify'] == "delete" ) {
$price = doliProductPrice($product, 0, false, true);
$result = doliaddtocart($product, $mstock, 0, $price, null, null);
$newqty = $result['newqty'];
Expand All @@ -801,7 +803,8 @@ function dolicart_request() {
'lines' => $result['lines'],
'total' => $result['total']
];
$response['newwish'] = doliProductCart($product, null, null);
$response['newwish'] = doliProductCart($product, null, null);
delete_transient( $link );
wp_send_json_success($response);
die();
} elseif (isset($_POST['modify']) && $_POST['modify'] == "membership") {
Expand All @@ -825,14 +828,16 @@ function dolicart_request() {
'items' => $result['items'],
'lines' => $result['lines'],
'total' => $result['total']
];
$response['newwish'] = doliProductCart($product, $result['line'], true, false, $productarray);
$object = doliConnect('order', $current_user);
$response['js'] = null;
$response['modal'] = doliModalTemplate('CartInfos', __( 'Cart', 'doliconnect'), doliline($object, false, false, false), doliCartButton($object), 'modal-lg');
];
$mstock = doliProductStock($product, true, true, $productarray);
$response['newwish'] = doliProductCart($product, $mstock['line'], true, true, $productarray);
$object = doliConnect('order', $current_user);
$response['js'] = null;
$response['modal'] = doliModalTemplate('CartInfos', __( 'Cart', 'doliconnect'), doliline($object, false, false, false), doliCartButton($object), 'modal-lg');
delete_transient( $link );
wp_send_json_success($response);
die();
} elseif (isset($_POST['modify']) && ($_POST['modify'] == "plus" || $_POST['modify'] == "minus" || $_POST['modify'] == "modify")) {
} elseif ( isset($_POST['modify']) && ($_POST['modify'] == "plus" || $_POST['modify'] == "minus" || $_POST['modify'] == "modify") ) {
if (!is_numeric(trim($_POST['qty']))) $_POST['qty'] = $mstock['qty'];
if ($_POST['modify'] == "plus") {
$qty = trim($_POST['qty'])+$mstock['step'];
Expand All @@ -853,17 +858,19 @@ function dolicart_request() {
'lines' => $result['lines'],
'total' => $result['total']
];
$response['newwish'] = doliProductCart($product, $result['line'], true, true, $productarray);
$mstock = doliProductStock($product, true, true, $productarray);
$response['newwish'] = doliProductCart($product, $mstock['line'], true, true, $productarray);
if (isset($_POST['DisplayCart']) && !empty($_POST['DisplayCart'])) {
$object = doliConnect('order', $current_user);
$response['js'] = null;
$response['modal'] = doliModalTemplate('CartInfos', __( 'Cart', 'doliconnect'), doliline($object, false, false, false), doliCartButton($object), 'modal-lg');
} elseif (doliCheckModules('relatedproducts') && doliCheckRelatedProducts($product->id)) {
$response['modal'] = doliModalTemplate('CartInfos', __( 'Related products', 'doliconnect'), doliRelatedProducts($product->id, true), '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'.__( "Close", "doliconnect").'</button>', 'modal-lg', null, 'p-0');
}
delete_transient( $link );
wp_send_json_success($response);
die();
} elseif (isset($_POST['modify']) && ($_POST['modify'] == "wish")) {
} elseif ( isset($_POST['modify']) && ($_POST['modify'] == "wish") ) {
$wish = doliWishlist($thirdparty->id, trim($_POST['id']), trim($_POST['lineid']), true, true);
if (empty($wish)) {
$data = [
Expand All @@ -874,22 +881,24 @@ function dolicart_request() {
];
$addwish = callDoliApi("POST", "/wishlist", $data, 0);
$wish = doliWishlist($thirdparty->id, trim($_POST['id']), trim($_POST['lineid']), true, false);
$mstock = doliProductStock($product, true, true);
$response['newwish'] = doliProductCart($product, $mstock['lineid'], true);
$mstock = doliProductStock($product, true, true, $productarray);
$response['newwish'] = doliProductCart($product, $mstock['line'], true, true, $productarray);
} elseif (!empty($wish)) {
$deletewish = callDoliApi("DELETE", "/wishlist/".$wish, null, 0);
$wish = doliWishlist($thirdparty->id, trim($_POST['id']), trim($_POST['lineid']), true, false);
$mstock = doliProductStock($product, true, true);
$response['newwish'] = doliProductCart($product, $mstock['lineid'], true);
$mstock = doliProductStock($product, true, true, $productarray);
$response['newwish'] = doliProductCart($product, $mstock['line'], true, true, $productarray);
}
delete_transient( $link );
wp_send_json_success($response);
die();
} else {
$response['modal'] = doliModalTemplate('CartInfos', __( 'Error', 'doliconnect'), __( "This action is not authorized", "doliconnect"), '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'.__( "Close", "doliconnect").'</button>');
delete_transient( $link );
wp_send_json_error($response);
die();
}
} elseif (isset($_POST['case']) && $_POST['case'] == "update") {
} elseif ( isset($_POST['case']) && $_POST['case'] == "update" && false === get_transient( $link ) ) {
if (isset($_POST['modify']) && $_POST['modify'] == "delete") {
$object = callDoliApi("GET", "/orders/".trim($_POST['id']), null, dolidelay('order', true));
if (!isset($object->error) && empty($object->statut)) {
Expand All @@ -911,7 +920,7 @@ function dolicart_request() {
wp_send_json_error( __( 'An error occured:', 'doliconnect').' '.$object->error->message);
}
}
} elseif (isset($_POST['case']) && $_POST['case'] == "purge_cart" && isset($_POST['module']) && isset($_POST['id'])) {
} elseif ( isset($_POST['case']) && $_POST['case'] == "purge_cart" && isset($_POST['module']) && isset($_POST['id']) && false === get_transient( $link ) ) {
$object = callDoliApi("GET", "/".trim($_POST['module'])."/".trim($_POST['id']), null, dolidelay('order', true));
if (!isset($object->error) && empty($object->statut)) {
$object = callDoliApi("DELETE", "/".trim($_POST['module'])."/".trim($_POST['id']), null);
Expand All @@ -931,7 +940,7 @@ function dolicart_request() {
} else {
wp_send_json_error( __( 'An error occured:', 'doliconnect').' '.$object->error->message);
}
} elseif ( isset($_POST['case']) && $_POST['case'] == "validate_cart" && isset($_POST['module']) && isset($_POST['id'])) {
} elseif ( isset($_POST['case']) && $_POST['case'] == "validate_cart" && isset($_POST['module']) && isset($_POST['id']) && false === get_transient( $link ) ) {
$data = [
'demand_reason_id' => 1,
'module_source' => 'doliconnect',
Expand All @@ -948,7 +957,7 @@ function dolicart_request() {
wp_send_json_error( __( 'An error occured:', 'doliconnect').' '.$object->error->message);
die();
}
} elseif ( isset($_POST['case']) && $_POST['case'] == "info_cart" && isset($_POST['module']) && isset($_POST['id'])) {
} elseif ( isset($_POST['case']) && $_POST['case'] == "info_cart" && isset($_POST['module']) && isset($_POST['id']) && false === get_transient( $link ) ) {
$data = [
'demand_reason_id' => 1,
'module_source' => 'doliconnect',
Expand Down Expand Up @@ -979,7 +988,7 @@ function dolicart_request() {
} else {
wp_send_json_error( __( 'An error occured:', 'doliconnect').' '.$object->error->message);
}
} elseif ( isset($_POST['case']) && $_POST['case'] == "pay_cart" && isset($_POST['module']) && isset($_POST['id'])) {
} elseif ( isset($_POST['case']) && $_POST['case'] == "pay_cart" && isset($_POST['module']) && isset($_POST['id']) && false === get_transient( $link ) ) {

$data = [
'paymentintent' => isset($_POST['paymentintent']) ? $_POST['paymentintent'] : null,
Expand Down
5 changes: 3 additions & 2 deletions functions/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function doliaddtocart($product, $mstock, $quantity, $price, $timestart = null,
$response['message'] = __( 'This item has been deleted to basket', 'doliconnect');
$response['items'] = doliconnect_countitems($order);
$response['lines'] = doliline($order);
$response['line'] = doliProductStock($product, true, true, $array_options)['line'];
$response['line'] = null;
if (empty($relatedproduct)) $response['newqty'] = $quantity;
$response['total'] = doliprice($order, 'ttc', isset($order->multicurrency_code) ? $order->multicurrency_code : null);
return $response;
Expand Down Expand Up @@ -336,7 +336,7 @@ function doliaddtocart($product, $mstock, $quantity, $price, $timestart = null,
$response['message'] = __( 'This item has been added to basket', 'doliconnect');
$response['items'] = doliconnect_countitems($order);
$response['lines'] = doliline($order);
$response['line'] = doliProductStock($product, true, true, $array_options)['line'];
$response['line'] = $addline;
if (empty($relatedproduct)) $response['newqty'] = $quantity;
$response['total'] = doliprice($order, 'ttc', isset($order->multicurrency_code) ? $order->multicurrency_code : null);
return $response;
Expand Down Expand Up @@ -385,6 +385,7 @@ function doliaddtocart($product, $mstock, $quantity, $price, $timestart = null,
$response['items'] = doliconnect_countitems($order);
$response['lines'] = doliline($order);
$response['line'] = doliProductStock($product, true, true, $array_options)['line'];
$response['line'] = $mstock['lineid'];
if (empty($relatedproduct)) $response['newqty'] = $quantity;
$response['total'] = doliprice($order, 'ttc', isset($order->multicurrency_code) ? $order->multicurrency_code : null);
return $response;
Expand Down

0 comments on commit 5c8844b

Please sign in to comment.