Skip to content

Commit

Permalink
Merge pull request #104 from Eoxia/2.5.0
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
nicolas-eoxia authored Sep 6, 2021
2 parents d409f2a + 6e4d499 commit a49553a
Show file tree
Hide file tree
Showing 38 changed files with 322 additions and 1,021 deletions.
Binary file modified core/asset/language/wpshop-fr_FR.mo
Binary file not shown.
255 changes: 120 additions & 135 deletions core/asset/language/wpshop-fr_FR.po

Large diffs are not rendered by default.

148 changes: 87 additions & 61 deletions modules/api/action/class-api-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Eoxia <[email protected]>
* @copyright (c) 2011-2020 Eoxia <[email protected]>.
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*/

namespace wpshop;
Expand Down Expand Up @@ -74,7 +74,7 @@ public function check_cap( $cap, $request ) {
* Initialise les routes de l'API.
*
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*/
public function callback_rest_api_init() {
register_rest_route( 'wpshop/v2', '/statut', array(
Expand All @@ -85,19 +85,12 @@ public function callback_rest_api_init() {
},
) );

register_rest_route( 'wpshop/v2', '/wps_gateway_paypal', array(
'methods' => array( 'GET', 'POST' ),
'callback' => array( $this, 'callback_wps_gateway_paypal' ),
) );

register_rest_route( 'wpshop/v2', '/wps_gateway_stripe', array(
'methods' => array( 'GET', 'POST' ),
'callback' => array( $this, 'callback_wps_gateway_stripe' ),
) );

register_rest_route( 'wpshop/v2', '/product/search', array(
'methods' => array( 'GET' ),
'callback' => array( $this, 'callback_search' ),
'permission_callback' => function( $request ) {
return Rest_Class::g()->check_cap( 'get', $request );
},
) );

register_rest_route( 'wpshop/v2', '/create/order', array(
Expand Down Expand Up @@ -139,6 +132,22 @@ public function callback_rest_api_init() {
return Rest_Class::g()->check_cap( 'get', $request );
},
) );

register_rest_route( 'wpshop/v2', '/wpml_insert_data', array(
'methods' => array( 'POST' ),
'callback' => array( $this, 'callback_wpml_insert_data' ),
'permission_callback' => function( $request ) {
return Rest_Class::g()->check_cap( 'get', $request );
},
) );

register_rest_route( 'wpshop/v2', '/wpml_delete_data', array(
'methods' => array( 'POST' ),
'callback' => array( $this, 'callback_wpml_delete_data' ),
'permission_callback' => function( $request ) {
return Rest_Class::g()->check_cap( 'get', $request );
},
) );
}

/**
Expand Down Expand Up @@ -208,55 +217,6 @@ public function check_statut( $request ) {
return new \WP_REST_Response( true );
}

/**
* Gestion de la route Paypal.
* Data is validated in wps_gateway_paypal
*
* @since 2.0.0
* @version 2.0.0
*
* @param WP_Request $request L'objet contenant les informations de la requête.
*/
public function callback_wps_gateway_paypal( $request ) {
$data = $request->get_body_params();

// translators: Paypal Gateway data: {json_data}.
LOG_Util::log( sprintf( 'Paypal Gateway data: %s', json_encode( $data ) ), 'wpshop2' );

$txn_id = get_post_meta( $data['custom'], 'payment_txn_id', true );

if ( $txn_id !== $data['txn_id'] ) {
// @todo: Pensé différement, envoyé vers dolibarr ?
update_post_meta( $data['custom'], 'payment_data', $data );
update_post_meta( $data['custom'], 'payment_txn_id', $data['txn_id'] );
update_post_meta( $data['custom'], 'payment_method', 'paypal' );

do_action( 'wps_gateway_paypal', $data );
}
}

/**
* Gestion de la route Stripe.
*
* @since 2.0.0
* @version 2.0.0
*
* @todo: Validate data request
*
* @param WP_Request $request L'objet contenant les informations de la requête.
*/
public function callback_wps_gateway_stripe( $request ) {
$param = json_decode( $request->get_body(), true );

// translators: Stripe Gateway data: {json_data}.
LOG_Util::log( sprintf( 'Stripe Gateway data: %s', json_encode( $param ) ), 'wpshop2' );
LOG_Util::log( sprintf( 'Stripe Gateway found dolibarr order id: %s', $param['data']['object']['metadata']['order_id'] ), 'wpshop2' );

$param['custom'] = $param['data']['object']['metadata']['order_id'];

do_action( 'wps_gateway_stripe', $param );
}

/**
* Recherche un produit depuis l'API.
*
Expand Down Expand Up @@ -477,6 +437,72 @@ public function callback_create_payment( $request ) {

return $propal;
}

/**
* Gestion de la route pour insérer un post traduit par WPML.
*
* @since 2.5.0
* @version 2.5.0
*
* @param WP_REST_Request $request L'objet contenant les informations de la requête.
*
* @return integer l'ID du post crée.
*/
public function callback_wpml_insert_data( $request ) {
$param = $request->get_params();

// Create post object
$my_post = array(
'post_title' => $param['label'],
'post_content' => $param['description'],
'post_type' => 'wps-product',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(2)
);

$output = wp_insert_post($my_post);

if ( $output ) {
// https://wpml.org/wpml-hook/wpml_element_type/
$wpml_element_type = apply_filters( 'wpml_element_type', 'wps-product' );

// get the language info of the original post
// https://wpml.org/wpml-hook/wpml_element_language_details/
$get_language_args = array('element_id' => $param['wpshop_id'], 'element_type' => 'wps-product' );
$original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );

$set_language_args = array(
'element_id' => $output,
'element_type' => 'post_wps-product',
'trid' => $original_post_language_info->trid,
'language_code' => $param['language_code'],
'source_language_code' => $original_post_language_info->language_code
);

do_action( 'wpml_set_element_language_details', $set_language_args );
}

return $output;
}

/**
* Gestion de la route pour supprimer un post WPML.
*
* @since 2.5.0
* @version 2.5.0
*
* @param WP_REST_Request $request L'objet contenant les informations de la requête.
*
* @return integer L'id du post supprimé.
*/
public function callback_wpml_delete_data( $request ) {
$param = $request->get_params();

$output = wp_delete_post($param['id']);

return $output;
}
}

new API_Action();
8 changes: 4 additions & 4 deletions modules/cart/action/class-cart-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Eoxia <[email protected]>
* @copyright (c) 2011-2020 Eoxia <[email protected]>.
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*/

namespace wpshop;
Expand Down Expand Up @@ -47,7 +47,7 @@ public function __construct() {
* @Todo bouger dans class-cart.php
*
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*/
public function callback_calculate_totals() {
$shipping_cost_option = get_option( 'wps_shipping_cost', Settings::g()->shipping_cost_default_settings );
Expand All @@ -71,10 +71,10 @@ public function callback_calculate_totals() {
if ( $shipping_cost_option['shipping_product_id'] !== $line['id'] ) {
if ( $dolibarr_option['price_min'] > ( $line['price_ttc'] * $line['qty'] ) ) {
$tva_amount += $dolibarr_option['price_min'] * $line['tva_tx'] / 100;
$price_no_shipping += $dolibarr_option['price_min'] - $tva_amount;
$price_no_shipping = $price;
} else {
$tva_amount += $line['tva_amount'] * $line['qty'];
$price_no_shipping += $line['price'] * $line['qty'];
$price_no_shipping = $price;
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions modules/checkout/action/class-checkout-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,27 @@ public function callback_checkout_doli_proposal( $third_party, $contact ) {
}
}

$doli_proposal = Request_Util::get( 'proposals/' . (int) $doli_proposal_id );
// $doli_proposal->total = number_format((float)Cart_Session::g()->total_price_ttc,8,'.',',');
// $doli_proposal->multicurrency_total_ht = number_format((float)Cart_Session::g()->total_price,8,'.',',');
// $doli_proposal->multicurrency_total_tva = number_format((float)Cart_Session::g()->tva_amount,8,'.',',');
// $doli_proposal->multicurrency_total_ttc = number_format((float)Cart_Session::g()->total_price_ttc,8,'.',',');
// $doli_proposal->total_ht = number_format((float)Cart_Session::g()->total_price,8,'.',',');
// $doli_proposal->total_tva = number_format((float)Cart_Session::g()->tva_amount,8,'.',',');
// $doli_proposal->total_ttc = number_format((float)Cart_Session::g()->total_price_ttc,8,'.',',');
//
// $proposal_data = array(
// 'total' => $doli_proposal->total,
// 'multicurrency_total_ht' => $doli_proposal->multicurrency_total_ht,
// 'multicurrency_total_tva' => $doli_proposal->multicurrency_total_tva,
// 'multicurrency_total_ttc' => $doli_proposal->multicurrency_total_ttc,
// 'total_ht' => $doli_proposal->total_ht,
// 'total_tva' => $doli_proposal->total_tva,
// 'total_ttc' => $doli_proposal->total_ttc,
// );
//
// $doli_proposal = Request_Util::put( 'proposals/' . (int) $doli_proposal_id, $proposal_data);

$doli_proposal = Request_Util::post( 'proposals/' . (int) $doli_proposal_id . '/validate', array(
'notrigger' => 1,
) );
Expand Down
27 changes: 7 additions & 20 deletions modules/checkout/class/class-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Eoxia <[email protected]>
* @copyright (c) 2011-2020 Eoxia <[email protected]>.
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*/

namespace wpshop;
Expand Down Expand Up @@ -181,7 +181,7 @@ public function validate_checkout( &$data, &$errors ) {
* Procède au paiement.
*
* @since 2.0.0
* @version 2.0.0
* @version 2.5.0
*
* @param Order $order Les données de la commande.
*/
Expand All @@ -200,33 +200,20 @@ public function process_order_payment( $order ) {
'url' => Pages::g()->get_checkout_link() . '/received/order/' . $order->data['external_id'] . '/',
) );
break;
case 'paypal':
$result = Paypal::g()->process_payment( $order );
case 'online_payment':
$result = Request_Util::g()->get( 'doliwpshop/getOnlinePaymentUrl?doli_id=' . $order->data['external_id'] );

Cart_Session::g()->destroy();
if ( ! empty( $result['url'] ) ) {
if ( ! empty( $result ) ) {
wp_send_json_success( array(
'namespace' => 'wpshopFrontend',
'module' => 'checkout',
'callback_success' => 'redirectToPayment',
'url' => $result['url'],
) );
}
break;
case 'stripe':
$result = Stripe::g()->process_payment( $order );
Cart_Session::g()->destroy();

if ( ! empty( $result['id'] ) ) {
wp_send_json_success( array(
'namespace' => 'wpshopFrontend',
'module' => 'stripe',
'callback_success' => 'redirectToPayment',
'id' => $result['id'],
'url' => $result,
) );
}
break;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Eoxia <[email protected]>
* @copyright (c) 2011-2020 Eoxia <[email protected]>.
* @since 2.1.0
* @version 2.1.0
* @version 2.5.0
*/

namespace wpshop;
Expand Down Expand Up @@ -80,7 +80,7 @@ class Doli_Category extends Term_Class {
*
* @var integer
*/
public $limit = 10;
public $limit = 1000;

/**
* Le nom de l'option pour la limite par page.
Expand Down Expand Up @@ -120,6 +120,7 @@ public function display() {

$doli_categories = Request_Util::get( $route );


foreach ( $doli_categories as $key => $doli_category ) {
if ( $doli_category->array_options->options__wps_id == 0 ) {
unset( $doli_categories[$key] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function meta_box_product( $invoice ) {
*
* @todo mettre la langue de l'user API pour la génération du doc
*
* @param array $data Data from PayPal.
* @param array $data Data order.
*/
public function create_invoice( $data ) {
$doli_order = Request_Util::get( 'orders/' . (int) $data['custom'] );
Expand Down
20 changes: 16 additions & 4 deletions modules/dolibarr/doli-order/action/class-doli-order-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function metabox_order_related_object( $order ) {
* Création d'une commande sur la base d'une proposition commerciale lors du tunnel de vente.
*
* @since 2.0.0
* @version 2.1.0
* @version 2.5.0
*
* @todo mettre la langue de l'user API pour la génération du doc
*
Expand All @@ -395,6 +395,18 @@ public function metabox_order_related_object( $order ) {
public function create_order( $proposal ) {
LOG_Util::log( sprintf( 'Dolibarr call POST /orders/createfromproposal/ with data %s', $proposal->id ), 'wpshop2' );
$doli_order = Request_Util::post( 'orders/createfromproposal/' . $proposal->id );

// $order_data = array(
// 'multicurrency_total_ht' => $proposal->multicurrency_total_ht,
// 'multicurrency_total_tva' => $proposal->multicurrency_total_tva,
// 'multicurrency_total_ttc' => $proposal->multicurrency_total_ttc,
// 'total_ht' => $proposal->total_ht,
// 'total_tva' => $proposal->total_tva,
// 'total_ttc' => $proposal->total_ttc,
// );
//
// $doli_order = Request_Util::put( 'orders/' . (int) $doli_order->id, $order_data);

LOG_Util::log( sprintf( 'Dolibarr call POST /orders/createfromproposal/ response %s', json_encode( $doli_order ) ), 'wpshop2' );


Expand All @@ -412,13 +424,13 @@ public function create_order( $proposal ) {

$current_user = wp_get_current_user();

Emails::g()->send_mail( $third_party[0]->data['email'], 'customer_current_order', array(
Emails::g()->send_mail( $third_party->data['email'], 'customer_current_order', array(
'order' => $doli_order,
'third_party' => $third_party[0]->data,
'third_party' => $third_party->data,
) );

// translators: Create order 00001 for the third party Eoxia.
LOG_Util::log( sprintf( 'Create order %s for the third party %s', $doli_order->ref, $third_party[0]->data['title'] ), 'wpshop2' );
LOG_Util::log( sprintf( 'Create order %s for the third party %s', $doli_order->ref, $third_party->data['title'] ), 'wpshop2' );

$wp_order = Doli_Order::g()->get( array( 'schema' => true ), true );
$wp_order = Doli_Order::g()->doli_to_wp( $doli_order, $wp_order, true );
Expand Down
Loading

0 comments on commit a49553a

Please sign in to comment.