Skip to content

Commit

Permalink
Merge pull request #35 from Eoxia/2.1.0
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
nicolas-eoxia authored Sep 29, 2020
2 parents 968a0c2 + 8c0f938 commit a28a2f9
Show file tree
Hide file tree
Showing 50 changed files with 2,469 additions and 795 deletions.
2 changes: 1 addition & 1 deletion core/asset/js/backend.min.js

Large diffs are not rendered by default.

Binary file modified core/asset/language/wpshop-fr_FR.mo
Binary file not shown.
1,431 changes: 739 additions & 692 deletions core/asset/language/wpshop-fr_FR.po

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions modules/cart/action/class-cart-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ public function callback_calculate_totals() {
public function callback_add_to_cart() {
check_ajax_referer( 'add_to_cart' );

$id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$qty = ! empty( $_POST['qty'] ) ? (int) $_POST['qty'] : 1;
$id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$qty = ! empty( $_POST['qty'] ) ? (int) $_POST['qty'] : 1;
$desc = ! empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : '';

if ( empty( $id ) ) {
wp_send_json_error();
}

$product = Product::g()->get( array( 'id' => $id ), true );

$added = Cart::g()->add_to_cart( $product, $qty );
$added = Cart::g()->add_to_cart( $product, $qty, $desc );

ob_start();
include( Template_Util::get_template_part( 'cart', 'link-cart' ) );
Expand Down
10 changes: 6 additions & 4 deletions modules/cart/class/class-cart.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.1.0
*/

namespace wpshop;
Expand Down Expand Up @@ -48,14 +48,14 @@ public function can_add_product() {
* Ajoute un produit dans le panier.
*
* @since 2.0.0
* @version 2.0.0
* @version 2.1.0
*
* @param Product $product Les données du produit.
* @param integer $qty La quantité à ajouter.
*
* @return boolean True si tout s'est bien passé.
*/
public function add_to_cart( $product, $qty = 1 ) {
public function add_to_cart( $product, $qty = 1, $desc = '' ) {
if ( ! $this->can_add_product() ) {
return;
}
Expand All @@ -71,7 +71,8 @@ public function add_to_cart( $product, $qty = 1 ) {

if ( ! empty( Cart_Session::g()->cart_contents ) ) {
foreach ( Cart_Session::g()->cart_contents as $key => $line ) {
if ( $line['id'] === $product->data['id'] ) {
$data['content'] = $desc;
if ( $line['id'] === $product->data['id'] && Settings::g()->split_product() == false ) {
$data['qty'] = $line['qty'] + $qty;
$index = $key;
break;
Expand All @@ -83,6 +84,7 @@ public function add_to_cart( $product, $qty = 1 ) {

if ( $can_add ) {
if ( -1 === $index ) {
$data['content'] = $desc;
Cart_Session::g()->add_product( $data );
} else {
Cart_Session::g()->update_product( $index, $data );
Expand Down
11 changes: 5 additions & 6 deletions modules/cart/view/frontend/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
/**
* Documentation des variables utilisées dans la vue.
*
* @var array $cart_contents Les données du panier.
* @var Product $product La donnée d'un produit.
* @var array $cart_contents Le tableau contenant toutes les données du panier.
*@var integer $key Le produit.
* @var Product $product Les données d'un produit.
* @var array $shipping_cost_option Les données de frais de livraison.
* @var integer $total_price_no_shipping Prix total sans frais de livraison.
* @var integer $tva_amount Montant de la TVA.
Expand All @@ -33,15 +34,13 @@

<div class="wpeo-gridlayout grid-3">
<div class="wps-list-product gridw-2">
<?php
if ( ! empty( $cart_contents ) ) :
<?php if ( ! empty( $cart_contents ) ) :
foreach ( $cart_contents as $key => $product ) :
if ( $shipping_cost_option['shipping_product_id'] !== $product['id'] ) :
include( Template_Util::get_template_part( 'products', 'wps-product-list-edit' ) );
endif;
endforeach;
endif;
?>
endif; ?>
<div data-parent="wps-cart" data-action="wps_update_cart"
class="wpeo-util-hidden update-cart wpeo-button action-input">
<?php esc_html_e( 'Update cart', 'wpshop' ); ?>
Expand Down
7 changes: 5 additions & 2 deletions modules/checkout/action/class-checkout-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.1.0
*/

namespace wpshop;
Expand Down Expand Up @@ -408,7 +408,9 @@ public function callback_checkout_proposal( $third_party, $contact ) {
* Créer la proposition commerciale lors du tunnel de vente.
*
* @since 2.0.0
* @version 2.0.0
* @version 2.1.0
*
* @todo mettre la langue de l'user API pour la génération du doc
*
* @param Third_Party $third_party Les données du tier.
* @param User $contact Les données du contact.
Expand Down Expand Up @@ -461,6 +463,7 @@ public function callback_checkout_doli_proposal( $third_party, $contact ) {
Request_Util::put( 'documents/builddoc', array(
'modulepart' => 'propal',
'original_file' => $doli_proposal->ref . '/' . $doli_proposal->ref . '.pdf',
'langcode' => 'fr_FR',
) );

Cart_Session::g()->add_external_data( 'doli_proposal_id', $doli_proposal_id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function load_associate_modal() {

$id = ! empty( $_POST['wp_id'] ) ? (int) $_POST['wp_id'] : 0;
$type = ! empty( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '';

$sync_info = Doli_Sync::g()->get_sync_infos( $type );
$entries = Request_Util::get( $sync_info['endpoint'] . '?limit=-1' );

Expand All @@ -59,24 +59,25 @@ public function load_associate_modal() {
}
}
}

ob_start();
View_Util::exec( 'wpshop', 'doli-associate', 'main', array(
'entries' => $entries,
'wp_id' => $id,
'type' => $type,
'label' => $sync_info['title'],
) );
$view = ob_get_clean();

ob_start();
View_Util::exec( 'wpshop', 'doli-associate', 'single-footer' );
$buttons_view = ob_get_clean();

wp_send_json_success( array(
'view' => $view,
'buttons_view' => $buttons_view,
) );
if ($type == 'wps-product') {
ob_start();
View_Util::exec( 'wpshop', 'doli-associate', 'main', array(
'entries' => $entries,
'wp_id' => $id,
'type' => $type,
'label' => $sync_info['title'],
) );
$view = ob_get_clean();

ob_start();
View_Util::exec( 'wpshop', 'doli-associate', 'single-footer' );
$buttons_view = ob_get_clean();

wp_send_json_success( array(
'view' => $view,
'buttons_view' => $buttons_view,
) );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/**
* La classe gérant les actions des catégories de Dolibarr.
*
* @package WPshop
* @author Eoxia <[email protected]>
* @copyright (c) 2011-2020 Eoxia <[email protected]>.
* @since 2.1.0
* @version 2.1.0
*/

namespace wpshop;

use eoxia\LOG_Util;
use eoxia\View_Util;
use stdClass;

defined( 'ABSPATH' ) || exit;

/**
* Doli Category Action Class.
*/
class Doli_Category_Action {

/**
* Définition des metaboxes sur la page.
*
* @since 2.1.0
* @version 2.1.0
*
* @var array
*/
public $metaboxes = null;

/**
* Le constructeur.
*
* @since 2.1.0
* @version 2.1.0
*/
public function __construct() {

add_action( 'admin_menu', array( $this, 'callback_admin_menu' ), 60 );

add_action( 'wps_checkout_create_category', array( $this, 'create_category' ), 10, 1 );
add_action( 'admin_post_wps_download_category', array( $this, 'download_category' ) );

}

/**
* Initialise la page "Catégories".
*
* @since 2.1.0
* @version 2.1.0
*/
public function callback_admin_menu() {
if ( Settings::g()->dolibarr_is_active() ) {
$hook = add_submenu_page( 'wpshop', __( 'Categories', 'wpshop' ), __( 'Categories', 'wpshop' ), 'manage_options', 'wps-product-cat', array( $this, 'callback_add_menu_page' ) );

if ( ! isset( $_GET['id'] ) ) {
add_action( 'load-' . $hook, array( $this, 'callback_add_screen_option' ) );
}
}
}

/**
* Affichage de la vue du menu.
*
* @since 2.1.0
* @version 2.1.0
*/
public function callback_add_menu_page() {
global $wpdb;
if ( isset( $_GET['id'] ) ) {
// Single page.
$id = ! empty( $_GET['id'] ) ? (int) $_GET['id'] : 0;

$doli_category = Request_Util::get( 'categories/' . $id );
$wp_category = Doli_Category::g()->get( array( 'schema' => true ), true );
$wp_category = Doli_Category::g()->doli_to_wp( $doli_category, $wp_category);

$wp_category->data['datec'] = \eoxia\Date_Util::g()->fill_date( $wp_category->data['datec'] );

$third_party = Third_Party::g()->get( array( 'id' => $wp_category->data['parent_id'] ), true );

View_Util::exec( 'wpshop', 'doli-categories', 'single', array(
'third_party' => $third_party,
'category' => $wp_category,
) );
} else {
// Listing page.
// @todo: Doublon avec Class Doli Category display() ?
$per_page = get_user_meta( get_current_user_id(), Doli_Category::g()->option_per_page, true );
$dolibarr_option = get_option( 'wps_dolibarr', Settings::g()->default_settings );
$dolibarr_url = $dolibarr_option['dolibarr_url'];

$dolibarr_create_category = 'categories/card.php?action=create&type=product&backtopage=%2Fdolibarr%2Fhtdocs%2Fcategories%2Findex.php%3Ftype%3Dproduct';

if ( empty( $per_page ) || 1 > $per_page ) {
$per_page = Doli_Category::g()->limit;
}

$s = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';

$count = Doli_Category::g()->search( $s, array(), true );
$number_page = ceil( $count / $per_page );
$current_page = isset( $_GET['current_page'] ) ? (int) $_GET['current_page'] : 1;

$base_url = admin_url( 'admin.php?page=wps-product-cat' );

$begin_url = $base_url . '&current_page=1';
$end_url = $base_url . '&current_page=' . $number_page;

$prev_url = $base_url . '&current_page=' . ( $current_page - 1 );
$next_url = $base_url . '&current_page=' . ( $current_page + 1 );

if ( ! empty( $s ) ) {
$begin_url .= '&s=' . $s;
$end_url .= '&s=' . $s;
$prev_url .= '&s=' . $s;
$next_url .= '&s=' . $s;
}

$wp_categories = Doli_Category::g()->get();

if ( ! empty($wp_categories)) {
foreach( $wp_categories as $wp_category) {
if (empty($wp_category->data['external_id'] )) {
wp_delete_term($wp_category->data['id'],'wps-product-cat');
}
}
}

View_Util::exec( 'wpshop', 'doli-categories', 'main', array(
'number_page' => $number_page,
'current_page' => $current_page,
'count' => $count,
'begin_url' => $begin_url,
'end_url' => $end_url,
'prev_url' => $prev_url,
'next_url' => $next_url,
's' => $s,
'wp_categories'=> $wp_categories,

'dolibarr_create_category' => $dolibarr_create_category,
'dolibarr_url' => $dolibarr_url,
) );
}
}

/**
* Ajoute le menu "Options de l'écran".
*
* @since 2.1.0
* @version 2.1.0
*/
public function callback_add_screen_option() {
add_screen_option(
'per_page',
array(
'label' => _x( 'Categories', 'Category per page', 'wpshop' ),
'default' => Doli_Category::g()->limit,
'option' => Doli_Category::g()->option_per_page,
)
);
}
}

new Doli_Category_Action();
2 changes: 2 additions & 0 deletions modules/dolibarr/doli-categories/action/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
Loading

0 comments on commit a28a2f9

Please sign in to comment.