@@ -1,15 +1,15 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | ?> |
| 3 | 3 | <div class="wps-table-content wps-table-row"> |
| 4 | - <div class="wps-table-cell"><?php echo mysql2date( get_option('date_format'), $posted_opinion->opinion_date, true ); ?></div> |
|
| 5 | - <div class="wps-table-cell"><a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank"><?php echo get_the_post_thumbnail( $posted_opinion->opinion_post_ID, 'thumbnail', array( 'class' => 'wps-circlerounded') ); ?></a></div> |
|
| 4 | + <div class="wps-table-cell"><?php echo mysql2date(get_option('date_format'), $posted_opinion->opinion_date, true); ?></div> |
|
| 5 | + <div class="wps-table-cell"><a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank"><?php echo get_the_post_thumbnail($posted_opinion->opinion_post_ID, 'thumbnail', array('class' => 'wps-circlerounded')); ?></a></div> |
|
| 6 | 6 | <div class="wps-table-cell"> |
| 7 | 7 | <a href="<?php echo get_permalink($posted_opinion->opinion_post_ID); ?>" target="_blank"> |
| 8 | 8 | <?php |
| 9 | - $product = get_post( $posted_opinion->opinion_post_ID ); |
|
| 10 | - if( !empty($product) && !empty($product->post_type) ) : |
|
| 11 | - if( $product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) : |
|
| 12 | - $product = get_post( $product->post_parent ); |
|
| 9 | + $product = get_post($posted_opinion->opinion_post_ID); |
|
| 10 | + if (!empty($product) && !empty($product->post_type)) : |
|
| 11 | + if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) : |
|
| 12 | + $product = get_post($product->post_parent); |
|
| 13 | 13 | endif; |
| 14 | 14 | endif; |
| 15 | 15 | echo $product->post_title; |
@@ -17,5 +17,5 @@ discard block |
||
| 17 | 17 | </a> |
| 18 | 18 | </div> |
| 19 | 19 | <div class="wps-table-cell"><?php echo $posted_opinion->opinion_content; ?></div> |
| 20 | - <div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars( $posted_opinion->opinion_rate ); ?></div> |
|
| 20 | + <div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars($posted_opinion->opinion_rate); ?></div> |
|
| 21 | 21 | </div> |
@@ -1,23 +1,23 @@ |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 2 | - if( !empty($posted_opinions) ) : ?> |
|
| 3 | -<span class="wps-h5"><?php _e( 'My opinions', 'wpshop'); ?></span> |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | + if (!empty($posted_opinions)) : ?> |
|
| 3 | +<span class="wps-h5"><?php _e('My opinions', 'wpshop'); ?></span> |
|
| 4 | 4 | <div class="wps-table"> |
| 5 | 5 | <div class="wps-table-header wps-table-row"> |
| 6 | - <div class="wps-table-cell"><?php _e( 'Date', 'wps_opinion'); ?></div> |
|
| 7 | - <div class="wps-table-cell"><?php _e( 'Picture', 'wps_opinion'); ?></div> |
|
| 8 | - <div class="wps-table-cell"><?php _e( 'Product', 'wps_opinion'); ?></div> |
|
| 9 | - <div class="wps-table-cell"><?php _e( 'Opinion', 'wps_opinion'); ?></div> |
|
| 10 | - <div class="wps-table-cell"><?php _e( 'Rate', 'wps_opinion'); ?></div> |
|
| 6 | + <div class="wps-table-cell"><?php _e('Date', 'wps_opinion'); ?></div> |
|
| 7 | + <div class="wps-table-cell"><?php _e('Picture', 'wps_opinion'); ?></div> |
|
| 8 | + <div class="wps-table-cell"><?php _e('Product', 'wps_opinion'); ?></div> |
|
| 9 | + <div class="wps-table-cell"><?php _e('Opinion', 'wps_opinion'); ?></div> |
|
| 10 | + <div class="wps-table-cell"><?php _e('Rate', 'wps_opinion'); ?></div> |
|
| 11 | 11 | </div> |
| 12 | 12 | |
| 13 | 13 | <?php |
| 14 | - if( !empty($posted_opinions) ) : |
|
| 15 | - foreach( $posted_opinions as $posted_opinion ) : |
|
| 16 | - require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir,"frontend", "posted_opinion") ); |
|
| 14 | + if (!empty($posted_opinions)) : |
|
| 15 | + foreach ($posted_opinions as $posted_opinion) : |
|
| 16 | + require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "posted_opinion")); |
|
| 17 | 17 | endforeach; |
| 18 | 18 | endif; |
| 19 | 19 | ?> |
| 20 | 20 | </div> |
| 21 | 21 | <?php else : ?> |
| 22 | -<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop'); ?></div> |
|
| 22 | +<div class="wps-alert-info"><?php _e('You never posted an opinion on a product', 'wpshop'); ?></div> |
|
| 23 | 23 | <?php endif; ?> |
@@ -1,22 +1,22 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 2 | -$permalink_option = get_option( 'permalink_structure' ); |
|
| 3 | -$account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' ) ); |
|
| 4 | -$account_dashboard_part = !empty( $_GET['account_dashboard_part'] ) ? sanitize_text_field( $_GET['account_dashboard_part'] ) : ''; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | +$permalink_option = get_option('permalink_structure'); |
|
| 3 | +$account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
| 4 | +$account_dashboard_part = !empty($_GET['account_dashboard_part']) ? sanitize_text_field($_GET['account_dashboard_part']) : ''; |
|
| 5 | 5 | ?> |
| 6 | 6 | |
| 7 | 7 | <?php $user_ID = get_current_user_id(); ?> |
| 8 | 8 | |
| 9 | -<?php if ( 0 !== $user_ID ) : ?> |
|
| 9 | +<?php if (0 !== $user_ID) : ?> |
|
| 10 | 10 | <div class="wps-user-dashboard"> |
| 11 | - <?php $account_user = get_userdata( $user_ID ); ?> |
|
| 11 | + <?php $account_user = get_userdata($user_ID); ?> |
|
| 12 | 12 | <span class="wps-user-name"> |
| 13 | - <?php _e( 'Hello', 'wpshop' ); ?> |
|
| 13 | + <?php _e('Hello', 'wpshop'); ?> |
|
| 14 | 14 | <strong><?php echo $account_user->data->user_login; ?></strong> |
| 15 | 15 | </span> |
| 16 | 16 | <span class="wps-user-thumbnail"> |
| 17 | - <?php echo get_avatar( $user_ID, 40 ); ?> |
|
| 17 | + <?php echo get_avatar($user_ID, 40); ?> |
|
| 18 | 18 | </span> |
| 19 | - <a href="<?php echo wp_logout_url( site_url() ); ?>" class="" title="<?php _e( 'Log out', 'wpshop' ); ?>"> |
|
| 19 | + <a href="<?php echo wp_logout_url(site_url()); ?>" class="" title="<?php _e('Log out', 'wpshop'); ?>"> |
|
| 20 | 20 | <i class="wps-icon-power"></i> |
| 21 | 21 | </a> |
| 22 | 22 | </div> |
@@ -25,50 +25,50 @@ discard block |
||
| 25 | 25 | <section class="wps-section-account"> |
| 26 | 26 | <div class="wps-section-taskbar"> |
| 27 | 27 | <ul> |
| 28 | - <li class="<?php echo ( ( empty($account_dashboard_part) || ( !empty($account_dashboard_part) && $account_dashboard_part == 'account' ) ) ? 'wps-activ' : '' ); ?>"> |
|
| 29 | - <a data-target="menu1" href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=account' ); ?>" title="" class=""> |
|
| 28 | + <li class="<?php echo ((empty($account_dashboard_part) || (!empty($account_dashboard_part) && $account_dashboard_part == 'account')) ? 'wps-activ' : ''); ?>"> |
|
| 29 | + <a data-target="menu1" href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=account'); ?>" title="" class=""> |
|
| 30 | 30 | <i class="wps-icon-user"></i> |
| 31 | - <span><?php _e( 'Account', 'wpshop'); ?></span> |
|
| 31 | + <span><?php _e('Account', 'wpshop'); ?></span> |
|
| 32 | 32 | </a> |
| 33 | 33 | </li> |
| 34 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : '' ); ?>"> |
|
| 35 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=address' ); ?>" title="" class=""> |
|
| 34 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : ''); ?>"> |
|
| 35 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=address'); ?>" title="" class=""> |
|
| 36 | 36 | <i class="wps-icon-address"></i> |
| 37 | - <span><?php _e( 'Addresses', 'wpshop'); ?></span> |
|
| 37 | + <span><?php _e('Addresses', 'wpshop'); ?></span> |
|
| 38 | 38 | </a> |
| 39 | 39 | </li> |
| 40 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : '' ); ?>"> |
|
| 41 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=order' ); ?>" title="" class=""> |
|
| 40 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : ''); ?>"> |
|
| 41 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=order'); ?>" title="" class=""> |
|
| 42 | 42 | <i class="wps-icon-truck"></i> |
| 43 | - <span><?php _e( 'Orders', 'wpshop'); ?></span> |
|
| 43 | + <span><?php _e('Orders', 'wpshop'); ?></span> |
|
| 44 | 44 | </a> |
| 45 | 45 | </li> |
| 46 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : '' ); ?>"> |
|
| 47 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=coupon' ); ?>" title="" class=""> |
|
| 46 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : ''); ?>"> |
|
| 47 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=coupon'); ?>" title="" class=""> |
|
| 48 | 48 | <i class="wps-icon-promo"></i> |
| 49 | - <span><?php _e( 'Coupons', 'wpshop'); ?></span> |
|
| 49 | + <span><?php _e('Coupons', 'wpshop'); ?></span> |
|
| 50 | 50 | </a> |
| 51 | 51 | </li> |
| 52 | - <?php $opinion_option = get_option( 'wps_opinion' ); |
|
| 53 | - if( !empty($opinion_option) && !empty($opinion_option['active']) ) : ?> |
|
| 54 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : '' ); ?>"> |
|
| 55 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=opinion' ); ?>" title="" class=""> |
|
| 52 | + <?php $opinion_option = get_option('wps_opinion'); |
|
| 53 | + if (!empty($opinion_option) && !empty($opinion_option['active'])) : ?> |
|
| 54 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : ''); ?>"> |
|
| 55 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=opinion'); ?>" title="" class=""> |
|
| 56 | 56 | <i class="wps-icon-chat"></i> |
| 57 | - <span><?php _e( 'Opinions', 'wpshop'); ?></span> |
|
| 57 | + <span><?php _e('Opinions', 'wpshop'); ?></span> |
|
| 58 | 58 | </a> |
| 59 | 59 | </li> |
| 60 | 60 | <?php endif; ?> |
| 61 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : '' ); ?>"> |
|
| 62 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=messages' ); ?>" title="" class=""> |
|
| 61 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : ''); ?>"> |
|
| 62 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=messages'); ?>" title="" class=""> |
|
| 63 | 63 | <i class="wps-icon-email"></i> |
| 64 | - <span><?php _e( 'Messages', 'wpshop' ); ?></span> |
|
| 64 | + <span><?php _e('Messages', 'wpshop'); ?></span> |
|
| 65 | 65 | </a> |
| 66 | 66 | </li> |
| 67 | 67 | <?php echo apply_filters('wps_my_account_extra_part_menu', ''); ?> |
| 68 | 68 | </ul> |
| 69 | 69 | </div> |
| 70 | 70 | <div class="wps-section-content"> |
| 71 | - <div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce( 'wps_refresh_add_opinion_list' ); ?>"> |
|
| 71 | + <div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce('wps_refresh_add_opinion_list'); ?>"> |
|
| 72 | 72 | <?php echo $content; ?> |
| 73 | 73 | </div> |
| 74 | 74 | </div> |
@@ -1,48 +1,48 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_cart { |
| 3 | 3 | |
| 4 | 4 | function __construct() { |
| 5 | 5 | /** WPShop Cart Shortcode **/ |
| 6 | - add_shortcode( 'wps_cart', array( &$this, 'display_cart' ) ); |
|
| 7 | - add_shortcode( 'wpshop_cart', array( &$this, 'display_cart' ) ); |
|
| 6 | + add_shortcode('wps_cart', array(&$this, 'display_cart')); |
|
| 7 | + add_shortcode('wpshop_cart', array(&$this, 'display_cart')); |
|
| 8 | 8 | /** WPShop Mini Cart Shortcode **/ |
| 9 | - add_shortcode( 'wps_mini_cart', array( &$this, 'display_mini_cart' ) ); |
|
| 10 | - add_shortcode( 'wpshop_mini_cart', array( &$this, 'display_mini_cart' ) ); |
|
| 9 | + add_shortcode('wps_mini_cart', array(&$this, 'display_mini_cart')); |
|
| 10 | + add_shortcode('wpshop_mini_cart', array(&$this, 'display_mini_cart')); |
|
| 11 | 11 | /** WPShop Resume Cart Shorcode **/ |
| 12 | - add_shortcode( 'wps_resume_cart', array( &$this, 'display_resume_cart' ) ); |
|
| 13 | - add_shortcode( 'wpshop_resume_cart', array( &$this, 'display_resume_cart' ) ); |
|
| 12 | + add_shortcode('wps_resume_cart', array(&$this, 'display_resume_cart')); |
|
| 13 | + add_shortcode('wpshop_resume_cart', array(&$this, 'display_resume_cart')); |
|
| 14 | 14 | /** Apply Coupon Interface **/ |
| 15 | - add_shortcode( 'wps_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) ); |
|
| 16 | - add_shortcode( 'wpshop_apply_coupon', array( &$this, 'display_apply_coupon_interface' ) ); |
|
| 15 | + add_shortcode('wps_apply_coupon', array(&$this, 'display_apply_coupon_interface')); |
|
| 16 | + add_shortcode('wpshop_apply_coupon', array(&$this, 'display_apply_coupon_interface')); |
|
| 17 | 17 | /** NUmeration Cart **/ |
| 18 | - add_shortcode( 'wps-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) ); |
|
| 19 | - add_shortcode( 'wpshop-numeration-cart', array( &$this, 'display_wps_numeration_cart' ) ); |
|
| 18 | + add_shortcode('wps-numeration-cart', array(&$this, 'display_wps_numeration_cart')); |
|
| 19 | + add_shortcode('wpshop-numeration-cart', array(&$this, 'display_wps_numeration_cart')); |
|
| 20 | 20 | /** Button add to cart */ |
| 21 | - add_shortcode( 'wpshop_button_add_to_cart', array( &$this, 'display_button_add_to_cart' ) ); |
|
| 21 | + add_shortcode('wpshop_button_add_to_cart', array(&$this, 'display_button_add_to_cart')); |
|
| 22 | 22 | |
| 23 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) ); |
|
| 24 | - add_action( 'init', array( $this, 'load_cart_from_db' ) ); |
|
| 23 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 24 | + add_action('init', array($this, 'load_cart_from_db')); |
|
| 25 | 25 | |
| 26 | 26 | /** Ajax Actions **/ |
| 27 | - add_action( 'wp_ajax_wps_reload_cart', array( $this, 'wps_reload_cart' ) ); |
|
| 28 | - add_action( 'wp_ajax_nopriv_wps_reload_cart', array( $this, 'wps_reload_cart' ) ); |
|
| 27 | + add_action('wp_ajax_wps_reload_cart', array($this, 'wps_reload_cart')); |
|
| 28 | + add_action('wp_ajax_nopriv_wps_reload_cart', array($this, 'wps_reload_cart')); |
|
| 29 | 29 | |
| 30 | - add_action( 'wp_ajax_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) ); |
|
| 31 | - add_action( 'wp_ajax_nopriv_wps_reload_mini_cart', array( &$this, 'wps_reload_mini_cart' ) ); |
|
| 30 | + add_action('wp_ajax_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart')); |
|
| 31 | + add_action('wp_ajax_nopriv_wps_reload_mini_cart', array(&$this, 'wps_reload_mini_cart')); |
|
| 32 | 32 | |
| 33 | - add_action( 'wp_ajax_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) ); |
|
| 34 | - add_action( 'wp_ajax_nopriv_wps_reload_summary_cart', array( &$this, 'wps_reload_summary_cart' ) ); |
|
| 33 | + add_action('wp_ajax_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart')); |
|
| 34 | + add_action('wp_ajax_nopriv_wps_reload_summary_cart', array(&$this, 'wps_reload_summary_cart')); |
|
| 35 | 35 | |
| 36 | - add_action( 'wp_ajax_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) ); |
|
| 37 | - add_action( 'wp_ajax_nopriv_wps_apply_coupon', array( &$this, 'wps_apply_coupon' ) ); |
|
| 36 | + add_action('wp_ajax_wps_apply_coupon', array(&$this, 'wps_apply_coupon')); |
|
| 37 | + add_action('wp_ajax_nopriv_wps_apply_coupon', array(&$this, 'wps_apply_coupon')); |
|
| 38 | 38 | |
| 39 | - add_action( 'wp_ajax_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) ); |
|
| 40 | - add_action( 'wp_ajax_nopriv_wps_cart_pass_to_step_two', array( &$this, 'wps_cart_pass_to_step_two' ) ); |
|
| 39 | + add_action('wp_ajax_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two')); |
|
| 40 | + add_action('wp_ajax_nopriv_wps_cart_pass_to_step_two', array(&$this, 'wps_cart_pass_to_step_two')); |
|
| 41 | 41 | |
| 42 | - add_action( 'wp_ajax_wps_empty_cart', array( &$this, 'wps_empty_cart' ) ); |
|
| 43 | - add_action( 'wp_ajax_nopriv_wps_empty_cart', array( &$this, 'wps_empty_cart' ) ); |
|
| 42 | + add_action('wp_ajax_wps_empty_cart', array(&$this, 'wps_empty_cart')); |
|
| 43 | + add_action('wp_ajax_nopriv_wps_empty_cart', array(&$this, 'wps_empty_cart')); |
|
| 44 | 44 | |
| 45 | - add_action( 'wsphop_options', array(&$this, 'declare_options' ), 8); |
|
| 45 | + add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function add_scripts() { |
| 52 | 52 | wp_enqueue_script('jquery'); |
| 53 | - wp_enqueue_script( 'wps_cart_js', WPS_CART_URL . WPS_CART_DIR.'/assets/frontend/js/wps_cart.js' ); |
|
| 53 | + wp_enqueue_script('wps_cart_js', WPS_CART_URL . WPS_CART_DIR . '/assets/frontend/js/wps_cart.js'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Declare Cart Options |
| 58 | 58 | */ |
| 59 | - public static function declare_options () { |
|
| 60 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) { |
|
| 61 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
| 62 | - $old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
| 59 | + public static function declare_options() { |
|
| 60 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 61 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 62 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 63 | 63 | |
| 64 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
| 65 | - && ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) { |
|
| 64 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 65 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 66 | 66 | /** Add module option to wpshop general options */ |
| 67 | 67 | register_setting('wpshop_options', 'wpshop_cart_option', array('wps_cart', 'wpshop_options_validate_cart_type')); |
| 68 | 68 | add_settings_field('wpshop_cart_type', __('Which type of cart do you want to display', 'wpshop'), array('wps_cart', 'wpshop_cart_type_field'), 'wpshop_cart_info', 'wpshop_cart_info'); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param unknown_type $input |
| 76 | 76 | * @return unknown |
| 77 | 77 | */ |
| 78 | - public static function wpshop_options_validate_cart_type( $input ) { |
|
| 78 | + public static function wpshop_options_validate_cart_type($input) { |
|
| 79 | 79 | return $input; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -83,22 +83,22 @@ discard block |
||
| 83 | 83 | * Cart Options Fields |
| 84 | 84 | */ |
| 85 | 85 | public static function wpshop_cart_type_field() { |
| 86 | - $cart_option = get_option( 'wpshop_cart_option' ); |
|
| 86 | + $cart_option = get_option('wpshop_cart_option'); |
|
| 87 | 87 | |
| 88 | 88 | $output = '<select name="wpshop_cart_option[cart_type]">'; |
| 89 | - $output .= '<option value="simplified_ati" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ATI', 'wpshop'). '</option>'; |
|
| 90 | - $output .= '<option value="simplified_et" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et' ) ? 'selected="selected"' : ''). ' >' .__( 'Simplified cart ET', 'wpshop'). '</option>'; |
|
| 91 | - $output .= '<option value="full_cart" ' .( ( !empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart' ) ? 'selected="selected"' : ''). ' >' .__( 'Full cart', 'wpshop'). '</option>'; |
|
| 89 | + $output .= '<option value="simplified_ati" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_ati') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ATI', 'wpshop') . '</option>'; |
|
| 90 | + $output .= '<option value="simplified_et" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'simplified_et') ? 'selected="selected"' : '') . ' >' . __('Simplified cart ET', 'wpshop') . '</option>'; |
|
| 91 | + $output .= '<option value="full_cart" ' . ((!empty($cart_option) && !empty($cart_option['cart_type']) && $cart_option['cart_type'] == 'full_cart') ? 'selected="selected"' : '') . ' >' . __('Full cart', 'wpshop') . '</option>'; |
|
| 92 | 92 | $output .= '</select>'; |
| 93 | 93 | |
| 94 | 94 | echo $output; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** Display Cart **/ |
| 98 | - function display_cart( $args ) { |
|
| 99 | - $cart_type = ( !empty($args) && !empty($args['cart_type']) ) ? $args['cart_type']: ''; |
|
| 100 | - $oid = ( !empty($args) && !empty($args['oid']) ) ? $args['oid'] : ''; |
|
| 101 | - $output = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce( 'wps_reload_cart' ) . '" class="wps-bloc-loader wps-cart-wrapper">'; |
|
| 98 | + function display_cart($args) { |
|
| 99 | + $cart_type = (!empty($args) && !empty($args['cart_type'])) ? $args['cart_type'] : ''; |
|
| 100 | + $oid = (!empty($args) && !empty($args['oid'])) ? $args['oid'] : ''; |
|
| 101 | + $output = '<div id="wps_cart_container" data-nonce="' . wp_create_nonce('wps_reload_cart') . '" class="wps-bloc-loader wps-cart-wrapper">'; |
|
| 102 | 102 | $output .= self::cart_content($cart_type, $oid); |
| 103 | 103 | $output .= '</div>'; |
| 104 | 104 | |
@@ -106,84 +106,84 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** Cart Content **/ |
| 109 | - public static function cart_content( $cart_type = '', $oid = '' ) { |
|
| 109 | + public static function cart_content($cart_type = '', $oid = '') { |
|
| 110 | 110 | global $wpdb; |
| 111 | 111 | $output = ''; |
| 112 | 112 | $account_origin = false; |
| 113 | - $cart_option = get_option( 'wpshop_cart_option' ); |
|
| 114 | - $cart_option = ( !empty($cart_option) && !empty($cart_option['cart_type']) ) ? $cart_option['cart_type'] : 'simplified_ati'; |
|
| 113 | + $cart_option = get_option('wpshop_cart_option'); |
|
| 114 | + $cart_option = (!empty($cart_option) && !empty($cart_option['cart_type'])) ? $cart_option['cart_type'] : 'simplified_ati'; |
|
| 115 | 115 | |
| 116 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 116 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 117 | 117 | |
| 118 | 118 | $coupon_title = $coupon_value = ''; |
| 119 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
| 120 | - if( !empty($oid) ) { |
|
| 119 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
| 120 | + if (!empty($oid)) { |
|
| 121 | 121 | $account_origin = true; |
| 122 | - $cart_content = get_post_meta( $oid, '_order_postmeta', true); |
|
| 122 | + $cart_content = get_post_meta($oid, '_order_postmeta', true); |
|
| 123 | 123 | } |
| 124 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
| 124 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
| 125 | 125 | |
| 126 | - if ( !empty($cart_content) ) { |
|
| 127 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
| 126 | + if (!empty($cart_content)) { |
|
| 127 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
| 128 | 128 | |
| 129 | - if ( !empty($cart_content['coupon_id']) ) { |
|
| 130 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
| 131 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
| 129 | + if (!empty($cart_content['coupon_id'])) { |
|
| 130 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
| 131 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if ( !empty($cart_items) ) { |
|
| 134 | + if (!empty($cart_items)) { |
|
| 135 | 135 | /** Total values **/ |
| 136 | - $shipping_cost_et = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? ( $cart_content['order_shipping_cost'] / ( 1 + ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) ) : $cart_content['order_shipping_cost'] ) : 0; |
|
| 137 | - $shipping_cost_vat = ( !empty( $shipping_cost_et) ) ? ( $shipping_cost_et * ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) ) : 0; |
|
| 138 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? ( (!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat ) : 0; |
|
| 139 | - $total_et = ( !empty( $cart_content['order_total_ht']) ) ? $cart_content['order_total_ht'] : 0; |
|
| 140 | - $order_totla_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 141 | - $order_amount_to_pay_now = wpshop_tools::formate_number( $cart_content['order_amount_to_pay_now'] ); |
|
| 142 | - $total_ati = ( !empty( $order_amount_to_pay_now ) && !empty($oid) && $order_amount_to_pay_now > 0 ) ? $cart_content['order_amount_to_pay_now'] : ( (!empty($cart_content['order_grand_total']) ) ? $cart_content['order_grand_total'] : 0 ); |
|
| 136 | + $shipping_cost_et = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? ($cart_content['order_shipping_cost'] / (1 + (WPSHOP_VAT_ON_SHIPPING_COST / 100))) : $cart_content['order_shipping_cost']) : 0; |
|
| 137 | + $shipping_cost_vat = (!empty($shipping_cost_et)) ? ($shipping_cost_et * (WPSHOP_VAT_ON_SHIPPING_COST / 100)) : 0; |
|
| 138 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? ((!empty($price_piloting) && $price_piloting != 'HT') ? $cart_content['order_shipping_cost'] : $cart_content['order_shipping_cost'] + $shipping_cost_vat) : 0; |
|
| 139 | + $total_et = (!empty($cart_content['order_total_ht'])) ? $cart_content['order_total_ht'] : 0; |
|
| 140 | + $order_totla_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 141 | + $order_amount_to_pay_now = wpshop_tools::formate_number($cart_content['order_amount_to_pay_now']); |
|
| 142 | + $total_ati = (!empty($order_amount_to_pay_now) && !empty($oid) && $order_amount_to_pay_now > 0) ? $cart_content['order_amount_to_pay_now'] : ((!empty($cart_content['order_grand_total'])) ? $cart_content['order_grand_total'] : 0); |
|
| 143 | 143 | unset($tracking); |
| 144 | - if( !empty($cart_content['order_trackingNumber']) ) { |
|
| 144 | + if (!empty($cart_content['order_trackingNumber'])) { |
|
| 145 | 145 | $tracking['number'] = $cart_content['order_trackingNumber']; |
| 146 | 146 | } |
| 147 | - if( !empty($cart_content['order_trackingLink']) ) { |
|
| 147 | + if (!empty($cart_content['order_trackingLink'])) { |
|
| 148 | 148 | $tracking['link'] = $cart_content['order_trackingLink']; |
| 149 | 149 | } |
| 150 | 150 | ob_start(); |
| 151 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart") ); |
|
| 151 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/cart")); |
|
| 152 | 152 | $output = ob_get_contents(); |
| 153 | 153 | ob_end_clean(); |
| 154 | 154 | } |
| 155 | 155 | else { |
| 156 | - return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
|
| 156 | + return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ; |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | else { |
| 160 | - return '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>';; |
|
| 160 | + return '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; ; |
|
| 161 | 161 | } |
| 162 | 162 | return $output; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** Display mini cart **/ |
| 166 | - function display_mini_cart( $args ) { |
|
| 166 | + function display_mini_cart($args) { |
|
| 167 | 167 | $total_cart_item = 0; |
| 168 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
| 169 | - $type = ( !empty($args) && !empty($args['type']) ) ? $args['type'] : ''; |
|
| 168 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
| 169 | + $type = (!empty($args) && !empty($args['type'])) ? $args['type'] : ''; |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - if ( !empty($cart_content) ) { |
|
| 173 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
| 172 | + if (!empty($cart_content)) { |
|
| 173 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
| 174 | 174 | /** Count items **/ |
| 175 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
| 176 | - $mini_cart_body = self::mini_cart_content( $type ); |
|
| 175 | + $total_cart_item = self::total_cart_items($cart_items); |
|
| 176 | + $mini_cart_body = self::mini_cart_content($type); |
|
| 177 | 177 | } |
| 178 | 178 | else { |
| 179 | 179 | $mini_cart_body = self::mini_cart_content(); |
| 180 | 180 | } |
| 181 | 181 | ob_start(); |
| 182 | - if( !empty($type) && $type == 'fixed' ) { |
|
| 183 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart") ); |
|
| 182 | + if (!empty($type) && $type == 'fixed') { |
|
| 183 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart")); |
|
| 184 | 184 | } |
| 185 | 185 | else { |
| 186 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart") ); |
|
| 186 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart")); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $output = ob_get_contents(); |
@@ -192,37 +192,37 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** Mini cart Content **/ |
| 195 | - public static function mini_cart_content( $type = '') { |
|
| 196 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
| 197 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
| 195 | + public static function mini_cart_content($type = '') { |
|
| 196 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
| 197 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
| 198 | 198 | $output = ''; |
| 199 | - if ( !empty($cart_content) ) { |
|
| 200 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
| 201 | - if ( !empty($cart_items) ) { |
|
| 202 | - if ( !empty($cart_content['coupon_id']) ) { |
|
| 203 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
| 204 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
| 199 | + if (!empty($cart_content)) { |
|
| 200 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
| 201 | + if (!empty($cart_items)) { |
|
| 202 | + if (!empty($cart_content['coupon_id'])) { |
|
| 203 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
| 204 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
| 205 | 205 | } |
| 206 | - $order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 207 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0; |
|
| 208 | - $total_ati = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
| 206 | + $order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 207 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0; |
|
| 208 | + $total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
| 209 | 209 | |
| 210 | 210 | ob_start(); |
| 211 | - if( !empty($type) && $type == 'fixed' ) { |
|
| 212 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content") ); |
|
| 211 | + if (!empty($type) && $type == 'fixed') { |
|
| 212 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/fixed-mini-cart", "content")); |
|
| 213 | 213 | } |
| 214 | 214 | else { |
| 215 | - require( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content") ); |
|
| 215 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "mini-cart/mini-cart", "content")); |
|
| 216 | 216 | } |
| 217 | 217 | $output = ob_get_contents(); |
| 218 | 218 | ob_end_clean(); |
| 219 | 219 | } |
| 220 | 220 | else { |
| 221 | - $output = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
| 221 | + $output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | else { |
| 225 | - $output = '<div class="wps-alert-info">' . __( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
| 225 | + $output = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
| 226 | 226 | } |
| 227 | 227 | return $output; |
| 228 | 228 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | function display_resume_cart() { |
| 232 | 232 | $cart_summary_content = self::resume_cart_content(); |
| 233 | 233 | ob_start(); |
| 234 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart") ); |
|
| 234 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart")); |
|
| 235 | 235 | $output = ob_get_contents(); |
| 236 | 236 | ob_end_clean(); |
| 237 | 237 | return $output; |
@@ -240,29 +240,29 @@ discard block |
||
| 240 | 240 | /** Resume cart Content **/ |
| 241 | 241 | public static function resume_cart_content() { |
| 242 | 242 | $output = ''; |
| 243 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
| 244 | - $cart_content = ( !empty($_SESSION) && !empty($_SESSION['cart']) ) ? $_SESSION['cart'] : array(); |
|
| 245 | - if ( !empty($cart_content) ) { |
|
| 246 | - $cart_items = ( !empty($cart_content['order_items']) ) ? $cart_content['order_items'] : array(); |
|
| 247 | - if ( !empty($cart_items) ) { |
|
| 248 | - if ( !empty($cart_content['coupon_id']) ) { |
|
| 249 | - $coupon_title = get_the_title( $cart_content['coupon_id']); |
|
| 250 | - $coupon_value = wpshop_tools::formate_number( $cart_content['order_discount_amount_total_cart'] ); |
|
| 243 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
| 244 | + $cart_content = (!empty($_SESSION) && !empty($_SESSION['cart'])) ? $_SESSION['cart'] : array(); |
|
| 245 | + if (!empty($cart_content)) { |
|
| 246 | + $cart_items = (!empty($cart_content['order_items'])) ? $cart_content['order_items'] : array(); |
|
| 247 | + if (!empty($cart_items)) { |
|
| 248 | + if (!empty($cart_content['coupon_id'])) { |
|
| 249 | + $coupon_title = get_the_title($cart_content['coupon_id']); |
|
| 250 | + $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); |
|
| 251 | 251 | } |
| 252 | - $order_total_before_discount = ( !empty($cart_content['order_grand_total_before_discount']) ) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 253 | - $shipping_cost_ati = ( !empty($cart_content['order_shipping_cost']) ) ? $cart_content['order_shipping_cost'] : 0; |
|
| 254 | - $total_ati = $total_cart = ( !empty($cart_content['order_amount_to_pay_now']) ) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
| 252 | + $order_total_before_discount = (!empty($cart_content['order_grand_total_before_discount'])) ? $cart_content['order_grand_total_before_discount'] : 0; |
|
| 253 | + $shipping_cost_ati = (!empty($cart_content['order_shipping_cost'])) ? $cart_content['order_shipping_cost'] : 0; |
|
| 254 | + $total_ati = $total_cart = (!empty($cart_content['order_amount_to_pay_now'])) ? $cart_content['order_amount_to_pay_now'] : 0; |
|
| 255 | 255 | ob_start(); |
| 256 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content") ); |
|
| 256 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content")); |
|
| 257 | 257 | $output = ob_get_contents(); |
| 258 | 258 | ob_end_clean(); |
| 259 | 259 | } |
| 260 | 260 | else { |
| 261 | - $resume_cart_body = '<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
| 261 | + $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | else { |
| 265 | - $resume_cart_body ='<div class="wps-alert-info">' .__( 'Your cart is empty', 'wpshop' ).'</div>'; |
|
| 265 | + $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; |
|
| 266 | 266 | } |
| 267 | 267 | return $output; |
| 268 | 268 | } |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | * @param array cart |
| 273 | 273 | * @return int total items |
| 274 | 274 | */ |
| 275 | - public static function total_cart_items( $cart_items ) { |
|
| 275 | + public static function total_cart_items($cart_items) { |
|
| 276 | 276 | $count = 0; |
| 277 | - if( !empty($cart_items) && is_array( $cart_items )) { |
|
| 278 | - foreach( $cart_items as $cart_item ) { |
|
| 277 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
| 278 | + foreach ($cart_items as $cart_item) { |
|
| 279 | 279 | $count += $cart_item['item_qty']; |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * Reload Persistent cart for logged user and if a persistent cart exists |
| 287 | 287 | */ |
| 288 | 288 | function load_cart_from_db() { |
| 289 | - if(empty($_SESSION['cart']) && get_current_user_id() ) { |
|
| 289 | + if (empty($_SESSION['cart']) && get_current_user_id()) { |
|
| 290 | 290 | $cart = $this->get_persistent_cart(); |
| 291 | 291 | $_SESSION['cart'] = $cart; |
| 292 | 292 | $_SESSION['coupon'] = 0; |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @return array() |
| 299 | 299 | */ |
| 300 | 300 | function get_persistent_cart() { |
| 301 | - if(get_current_user_id()) |
|
| 301 | + if (get_current_user_id()) |
|
| 302 | 302 | $cart = get_user_meta(get_current_user_id(), '_wpshop_persistent_cart', true); |
| 303 | 303 | return empty($cart) ? array() : $cart; |
| 304 | 304 | } |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | * Save the persistent cart when updated |
| 315 | 315 | */ |
| 316 | 316 | function persistent_cart_update() { |
| 317 | - if(get_current_user_id()) |
|
| 318 | - update_user_meta( get_current_user_id(), '_wpshop_persistent_cart', array( |
|
| 317 | + if (get_current_user_id()) |
|
| 318 | + update_user_meta(get_current_user_id(), '_wpshop_persistent_cart', array( |
|
| 319 | 319 | 'cart' => $_SESSION['cart'], |
| 320 | 320 | )); |
| 321 | 321 | } |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * Delete the persistent cart |
| 325 | 325 | */ |
| 326 | 326 | function persistent_cart_destroy() { |
| 327 | - delete_user_meta( get_current_user_id(), '_wpshop_persistent_cart' ); |
|
| 327 | + delete_user_meta(get_current_user_id(), '_wpshop_persistent_cart'); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -344,60 +344,60 @@ discard block |
||
| 344 | 344 | * |
| 345 | 345 | * @return mixed If an error occured return a alert message. In the other case if the quantity is correctly set return true |
| 346 | 346 | */ |
| 347 | - function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '' ) { |
|
| 347 | + function set_product_qty($product_id, $quantity, $combined_variation_id = '', $cart = array(), $from_admin = '', $order_id = '') { |
|
| 348 | 348 | // Init Cart var |
| 349 | - $cart = ( !empty($cart) ) ? $cart : $_SESSION['cart']; |
|
| 350 | - $wpshop_cart_type = ( !empty($cart) && !empty($cart['cart_type']) ) ? $cart['cart_type'] : 'normal'; |
|
| 349 | + $cart = (!empty($cart)) ? $cart : $_SESSION['cart']; |
|
| 350 | + $wpshop_cart_type = (!empty($cart) && !empty($cart['cart_type'])) ? $cart['cart_type'] : 'normal'; |
|
| 351 | 351 | $parent_product_id = $product_id; |
| 352 | 352 | $selected_variations = array(); |
| 353 | 353 | |
| 354 | 354 | // Test if Product exists |
| 355 | - if( !empty($product_id) && !empty($cart['order_items']) && !empty( $cart['order_items'][ $product_id ] ) ) { |
|
| 355 | + if (!empty($product_id) && !empty($cart['order_items']) && !empty($cart['order_items'][$product_id])) { |
|
| 356 | 356 | // Test if is composed product ID |
| 357 | 357 | $pid = $product_id; |
| 358 | - if (strpos($pid,'__') !== false) { |
|
| 359 | - $product_data_id = explode( '__', $pid ); |
|
| 360 | - $pid = ( !empty( $product_data_id ) && !empty( $product_data_id[1] ) ) ? $product_data_id[1] : $cart['order_items'][ $product_id ]['item_id']; |
|
| 358 | + if (strpos($pid, '__') !== false) { |
|
| 359 | + $product_data_id = explode('__', $pid); |
|
| 360 | + $pid = (!empty($product_data_id) && !empty($product_data_id[1])) ? $product_data_id[1] : $cart['order_items'][$product_id]['item_id']; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // Checking stock |
| 364 | 364 | $wps_product_ctr = new wps_product_ctr(); |
| 365 | - $return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id ); |
|
| 366 | - if( $return !== true) { |
|
| 365 | + $return = $wps_product_ctr->check_stock($pid, $quantity, $combined_variation_id); |
|
| 366 | + if ($return !== true) { |
|
| 367 | 367 | return $return; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // Check Variations to construct product to add to cart |
| 371 | - if( !empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 371 | + if (!empty($product_data_id) || get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 372 | 372 | // Check Parent ID |
| 373 | - if( get_post_type($cart['order_items'][ $product_id ]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
|
| 374 | - $parent_product_id = $cart['order_items'][ $product_id ]['item_id']; |
|
| 373 | + if (get_post_type($cart['order_items'][$product_id]['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 374 | + $parent_product_id = $cart['order_items'][$product_id]['item_id']; |
|
| 375 | 375 | } |
| 376 | 376 | else { |
| 377 | - $parent_data = wpshop_products::get_parent_variation( $cart['order_items'][ $product_id ]['item_id'] ); |
|
| 377 | + $parent_data = wpshop_products::get_parent_variation($cart['order_items'][$product_id]['item_id']); |
|
| 378 | 378 | $parent_post = $parent_data['parent_post']; |
| 379 | 379 | $parent_product_id = $parent_post->ID; |
| 380 | 380 | } |
| 381 | - if( !empty($product_data_id) ) { |
|
| 382 | - unset( $product_data_id[0] ); |
|
| 383 | - if( !empty($product_data_id) ) { |
|
| 384 | - foreach( $product_data_id as $i ) { |
|
| 385 | - $mtdt = get_post_meta( $i, '_wpshop_variations_attribute_def', true ); |
|
| 386 | - if( !empty($mtdt) && is_array($mtdt) ) { |
|
| 387 | - $selected_variations = array_merge( $selected_variations, $mtdt ); |
|
| 381 | + if (!empty($product_data_id)) { |
|
| 382 | + unset($product_data_id[0]); |
|
| 383 | + if (!empty($product_data_id)) { |
|
| 384 | + foreach ($product_data_id as $i) { |
|
| 385 | + $mtdt = get_post_meta($i, '_wpshop_variations_attribute_def', true); |
|
| 386 | + if (!empty($mtdt) && is_array($mtdt)) { |
|
| 387 | + $selected_variations = array_merge($selected_variations, $mtdt); |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | else { |
| 393 | - $selected_variations = get_post_meta( $product_id, '_wpshop_variations_attribute_def', true ); |
|
| 393 | + $selected_variations = get_post_meta($product_id, '_wpshop_variations_attribute_def', true); |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - $formatted_product = $this->prepare_product_to_add_to_cart( $parent_product_id, $quantity, $selected_variations ); |
|
| 397 | + $formatted_product = $this->prepare_product_to_add_to_cart($parent_product_id, $quantity, $selected_variations); |
|
| 398 | 398 | $product_to_add_to_cart = $formatted_product[0]; |
| 399 | 399 | $new_pid = $product_id; |
| 400 | - $return = $this->add_to_cart( $product_to_add_to_cart, array( $new_pid => $quantity ), $wpshop_cart_type, array(), $from_admin, $cart, $order_id ); |
|
| 400 | + $return = $this->add_to_cart($product_to_add_to_cart, array($new_pid => $quantity), $wpshop_cart_type, array(), $from_admin, $cart, $order_id); |
|
| 401 | 401 | return $return; |
| 402 | 402 | } |
| 403 | 403 | else { |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | * @param string product_id contains the id of the product to add to the cart |
| 411 | 411 | * @param string quantity contains the quantity of the item to add |
| 412 | 412 | */ |
| 413 | - function add_to_cart( $product_list, $quantity, $type='normal', $extra_params=array(), $from_admin = '', $order_meta = '', $order_id = '' ) { |
|
| 413 | + function add_to_cart($product_list, $quantity, $type = 'normal', $extra_params = array(), $from_admin = '', $order_meta = '', $order_id = '') { |
|
| 414 | 414 | global $wpdb; |
| 415 | 415 | /** Check if a cart already exist. If there is already a cart that is not the same type (could be a cart or a quotation) */ |
| 416 | - if ( empty( $from_admin ) ){ |
|
| 417 | - if(isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type'] ) { |
|
| 416 | + if (empty($from_admin)) { |
|
| 417 | + if (isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type']) { |
|
| 418 | 418 | return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop'); |
| 419 | 419 | } |
| 420 | 420 | else { |
@@ -427,19 +427,19 @@ discard block |
||
| 427 | 427 | $order_items = array(); |
| 428 | 428 | |
| 429 | 429 | foreach ($product_list as $pid => $product_more_content) { |
| 430 | - if ( count($product_list) == 1 ) { |
|
| 431 | - if ( !isset( $quantity[$pid] ) ) $quantity[$pid] = 1; |
|
| 430 | + if (count($product_list) == 1) { |
|
| 431 | + if (!isset($quantity[$pid])) $quantity[$pid] = 1; |
|
| 432 | 432 | $product = wpshop_products::get_product_data($product_more_content['id'], false, '"publish", "free_product"'); |
| 433 | 433 | /** Check if the selected product exist */ |
| 434 | - if ( $product === false ) return __('This product does not exist', 'wpshop'); |
|
| 434 | + if ($product === false) return __('This product does not exist', 'wpshop'); |
|
| 435 | 435 | |
| 436 | 436 | /** Get information about the product price */ |
| 437 | 437 | $product_price_check = wpshop_prices::get_product_price($product, 'check_only'); |
| 438 | - if ( $product_price_check !== true ) return $product_price_check; |
|
| 438 | + if ($product_price_check !== true) return $product_price_check; |
|
| 439 | 439 | |
| 440 | 440 | $the_quantity = 1; |
| 441 | 441 | |
| 442 | - if ( !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) ) { |
|
| 442 | + if (!empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0])) { |
|
| 443 | 443 | /** Get the asked quantity for each product and check if there is enough stock */ |
| 444 | 444 | $the_quantity = $quantity[$pid]; |
| 445 | 445 | } |
@@ -451,14 +451,14 @@ discard block |
||
| 451 | 451 | //$quantity[$pid] = $the_quantity; |
| 452 | 452 | |
| 453 | 453 | $variation_id = 0; |
| 454 | - if ( !empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' ){ |
|
| 454 | + if (!empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined') { |
|
| 455 | 455 | $variation_id = $product_more_content['variations'][0]; |
| 456 | 456 | } |
| 457 | 457 | //$quantity_to_check = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$pid]) && !empty($_SESSION['cart']['order_items'][$pid]['item_qty']) ) ? $_SESSION['cart']['order_items'][$pid]['item_qty'] : $the_quantity; |
| 458 | 458 | |
| 459 | 459 | $wps_product_ctr = new wps_product_ctr(); |
| 460 | - $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id ); |
|
| 461 | - if ( $product_stock !== true ) { |
|
| 460 | + $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $the_quantity, $variation_id); |
|
| 461 | + if ($product_stock !== true) { |
|
| 462 | 462 | return $product_stock; |
| 463 | 463 | } |
| 464 | 464 | } |
@@ -467,99 +467,99 @@ discard block |
||
| 467 | 467 | $order_items[$pid]['product_qty'] = $the_quantity; |
| 468 | 468 | |
| 469 | 469 | /** For product with variation */ |
| 470 | - $order_items[$pid]['product_variation_type'] = !empty( $product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 470 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 471 | 471 | $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
| 472 | 472 | $order_items[$pid]['product_variation'] = ''; |
| 473 | - if ( !empty($product_more_content['variations']) ) { |
|
| 474 | - foreach ( $product_more_content['variations'] as $variation_id) { |
|
| 473 | + if (!empty($product_more_content['variations'])) { |
|
| 474 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 475 | 475 | $order_items[$pid]['product_variation'][] = $variation_id; |
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - $current_cart = ( !empty( $order_meta )) ? $order_meta : array(); |
|
| 481 | - $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart ); |
|
| 480 | + $current_cart = (!empty($order_meta)) ? $order_meta : array(); |
|
| 481 | + $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart); |
|
| 482 | 482 | |
| 483 | - if( empty($from_admin) ) { |
|
| 483 | + if (empty($from_admin)) { |
|
| 484 | 484 | self::store_cart_in_session($order); |
| 485 | 485 | /** Store the cart into database for connected user */ |
| 486 | - if ( get_current_user_id() ) { |
|
| 486 | + if (get_current_user_id()) { |
|
| 487 | 487 | $this->persistent_cart_update(); |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | else { |
| 491 | - update_post_meta($order_id, '_order_postmeta', $order ); |
|
| 491 | + update_post_meta($order_id, '_order_postmeta', $order); |
|
| 492 | 492 | |
| 493 | 493 | } |
| 494 | 494 | return 'success'; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - function prepare_product_to_add_to_cart( $product_id, $product_qty, $wpshop_variation_selected = array() ) { |
|
| 497 | + function prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected = array()) { |
|
| 498 | 498 | $product_price = ''; |
| 499 | 499 | $product_data = wpshop_products::get_product_data($product_id); |
| 500 | 500 | |
| 501 | 501 | // Free vars |
| 502 | - if ( !empty($wpshop_variation_selected['free']) ){ |
|
| 502 | + if (!empty($wpshop_variation_selected['free'])) { |
|
| 503 | 503 | $free_variations = $wpshop_variation_selected['free']; |
| 504 | 504 | unset($wpshop_variation_selected['free']); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // If product have many variations |
| 508 | - if ( count($wpshop_variation_selected ) > 1 ) { |
|
| 509 | - if ( !empty($wpshop_variation_selected) ) { |
|
| 510 | - $product_with_variation = wpshop_products::get_variation_by_priority( $wpshop_variation_selected, $product_id, true ); |
|
| 508 | + if (count($wpshop_variation_selected) > 1) { |
|
| 509 | + if (!empty($wpshop_variation_selected)) { |
|
| 510 | + $product_with_variation = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - if ( !empty($product_with_variation[$product_id]['variations']) ) { |
|
| 513 | + if (!empty($product_with_variation[$product_id]['variations'])) { |
|
| 514 | 514 | $product = $product_data; |
| 515 | 515 | $has_variation = true; |
| 516 | 516 | $head_product_id = $product_id; |
| 517 | 517 | |
| 518 | - if ( !empty($product_with_variation[$product_id]['variations']) && ( count($product_with_variation[$product_id]['variations']) == 1 ) && ($product_with_variation[$product_id]['variation_priority'] != 'single') ) { |
|
| 518 | + if (!empty($product_with_variation[$product_id]['variations']) && (count($product_with_variation[$product_id]['variations']) == 1) && ($product_with_variation[$product_id]['variation_priority'] != 'single')) { |
|
| 519 | 519 | $product_id = $product_with_variation[$product_id]['variations'][0]; |
| 520 | 520 | } |
| 521 | 521 | $product = wpshop_products::get_product_data($product_id, true); |
| 522 | 522 | |
| 523 | - $the_product = array_merge( array( |
|
| 523 | + $the_product = array_merge(array( |
|
| 524 | 524 | 'product_id' => $product_id, |
| 525 | 525 | 'product_qty' => $product_qty |
| 526 | 526 | ), $product); |
| 527 | 527 | |
| 528 | 528 | /* Add variation to product into cart for storage */ |
| 529 | - if ( !empty($product_with_variation[$head_product_id]['variations']) ) { |
|
| 530 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority']) ); |
|
| 529 | + if (!empty($product_with_variation[$head_product_id]['variations'])) { |
|
| 530 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_with_variation[$head_product_id]['variations'], $head_product_id, array('type' => $product_with_variation[$head_product_id]['variation_priority'])); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $product_data = $the_product; |
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - $product_to_add_to_cart = array( $product_id => array( 'id' => $product_id, 'product_qty' => $product_qty ) ); |
|
| 537 | + $product_to_add_to_cart = array($product_id => array('id' => $product_id, 'product_qty' => $product_qty)); |
|
| 538 | 538 | |
| 539 | - if ( !empty( $wpshop_variation_selected ) ) { |
|
| 540 | - $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true ); |
|
| 541 | - if ( !empty($variation_calculator[$product_id]) ) { |
|
| 539 | + if (!empty($wpshop_variation_selected)) { |
|
| 540 | + $variation_calculator = wpshop_products::get_variation_by_priority($wpshop_variation_selected, $product_id, true); |
|
| 541 | + if (!empty($variation_calculator[$product_id])) { |
|
| 542 | 542 | $product_to_add_to_cart[$product_id] = array_merge($product_to_add_to_cart[$product_id], $variation_calculator[$product_id]); |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | $new_pid = $product_id; |
| 547 | 547 | //Create custom ID on single variations Product |
| 548 | - if( !empty($product_to_add_to_cart[$product_id]['variations']) && count( $product_to_add_to_cart[$product_id]['variations'] ) && !empty( $product_to_add_to_cart[$product_id]['variation_priority'] ) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single' ) { |
|
| 548 | + if (!empty($product_to_add_to_cart[$product_id]['variations']) && count($product_to_add_to_cart[$product_id]['variations']) && !empty($product_to_add_to_cart[$product_id]['variation_priority']) && $product_to_add_to_cart[$product_id]['variation_priority'] == 'single') { |
|
| 549 | 549 | $tmp_obj = $product_to_add_to_cart[$product_id]; |
| 550 | - unset( $product_to_add_to_cart[$product_id] ); |
|
| 550 | + unset($product_to_add_to_cart[$product_id]); |
|
| 551 | 551 | $key = $product_id; |
| 552 | - foreach( $tmp_obj['variations'] as $variation_key) { |
|
| 553 | - $key.= '__'. $variation_key; |
|
| 552 | + foreach ($tmp_obj['variations'] as $variation_key) { |
|
| 553 | + $key .= '__' . $variation_key; |
|
| 554 | 554 | } |
| 555 | 555 | $product_to_add_to_cart[$key] = $tmp_obj; |
| 556 | 556 | $new_pid = $key; |
| 557 | 557 | } |
| 558 | 558 | // Add free variations |
| 559 | - if( !empty($free_variations) ) { |
|
| 559 | + if (!empty($free_variations)) { |
|
| 560 | 560 | $product_to_add_to_cart[$new_pid]['free_variation'] = $free_variations; |
| 561 | 561 | } |
| 562 | - return array( $product_to_add_to_cart, $new_pid ); |
|
| 562 | + return array($product_to_add_to_cart, $new_pid); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -570,67 +570,67 @@ discard block |
||
| 570 | 570 | * @param boolean $from_admin |
| 571 | 571 | * @return array |
| 572 | 572 | */ |
| 573 | - function calcul_cart_information( $product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false ) { |
|
| 573 | + function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) { |
|
| 574 | 574 | // Price piloting option |
| 575 | - $price_piloting = get_option( 'wpshop_shop_price_piloting' ); |
|
| 575 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 576 | 576 | |
| 577 | 577 | // Init vars |
| 578 | - $cart_infos = ( !empty($current_cart) ) ? $current_cart : ( ( !empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ) ? $_SESSION['cart'] : array() ); |
|
| 579 | - $cart_items = ( !empty($current_cart) && !empty($current_cart['order_items']) ) ? $current_cart['order_items'] : array(); |
|
| 580 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 578 | + $cart_infos = (!empty($current_cart)) ? $current_cart : ((!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin) ? $_SESSION['cart'] : array()); |
|
| 579 | + $cart_items = (!empty($current_cart) && !empty($current_cart['order_items'])) ? $current_cart['order_items'] : array(); |
|
| 580 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin) ? $_SESSION['cart']['order_items'] : $cart_items; |
|
| 581 | 581 | $order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array(); |
| 582 | 582 | $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0; |
| 583 | 583 | $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0; |
| 584 | 584 | $cart_infos['order_amount_to_pay_now'] = 0; |
| 585 | 585 | |
| 586 | 586 | // If Product list is not empty, add products to order |
| 587 | - if( !empty($product_list) ) { |
|
| 588 | - foreach ( $product_list as $product_id => $d ) { |
|
| 587 | + if (!empty($product_list)) { |
|
| 588 | + foreach ($product_list as $product_id => $d) { |
|
| 589 | 589 | $product_key = $product_id; |
| 590 | - if( isset( $d['product_qty']) ) { |
|
| 590 | + if (isset($d['product_qty'])) { |
|
| 591 | 591 | // Formate datas |
| 592 | 592 | $product_id = $head_product_id = $d['product_id']; |
| 593 | 593 | $product_qty = $d['product_qty']; |
| 594 | 594 | $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
| 595 | 595 | |
| 596 | 596 | // If product is a single variation product |
| 597 | - if ( !empty($product_variation) && ( count($product_variation) == 1 ) ) { |
|
| 597 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 598 | 598 | $product_id = $product_variation[0]; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | // Construct final product |
| 602 | 602 | $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"'); |
| 603 | - $the_product = array_merge( array('product_id' => $d['product_id'], 'product_qty' => $product_qty ), $product); |
|
| 603 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product); |
|
| 604 | 604 | |
| 605 | 605 | // Add variation to product into cart for storage |
| 606 | - if ( !empty($product_variation) ) { |
|
| 607 | - $the_product = wpshop_products::get_variation_price_behaviour( $the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']) ); |
|
| 606 | + if (!empty($product_variation)) { |
|
| 607 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | // Free Variations Checking |
| 611 | - if ( !empty( $d['free_variation'] ) ) { |
|
| 611 | + if (!empty($d['free_variation'])) { |
|
| 612 | 612 | $the_product['item_meta']['free_variation'] = $d['free_variation']; |
| 613 | 613 | $head_product_id = $the_product['product_id']; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // If product is a variation, we check parent product general |
| 617 | - if( get_post_type( $the_product['product_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 618 | - $parent_def = wpshop_products::get_parent_variation( $the_product['product_id'] ); |
|
| 619 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 620 | - $variation_def = get_post_meta( $parent_def['parent_post']->ID, '_wpshop_variation_defining', true ); |
|
| 617 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 618 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 619 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 620 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 621 | 621 | $parent_meta = $parent_def['parent_post_meta']; |
| 622 | - if( !empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority'] ) && !empty($variation_def['options']['price_behaviour']) && in_array( 'addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1 ) { |
|
| 623 | - $the_product['product_price'] += number_format( str_replace( ',', '.', $parent_meta['product_price'] ), 2, '.', '' ); |
|
| 624 | - $the_product['price_ht'] += number_format( str_replace( ',', '.',$parent_meta['price_ht']) , 2, '.', '' ); |
|
| 625 | - $the_product['tva'] += number_format( str_replace( ',', '.', $parent_meta['tva']) , 2, '.', '' ); |
|
| 622 | + if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) { |
|
| 623 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 624 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 625 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | // Delete product if its qty is equals to zero, else add this product to order |
| 631 | - if( empty( $d['product_qty'] ) ) { |
|
| 632 | - unset( $cart_items[$product_key] ); |
|
| 633 | - unset( $cart_infos['order_items'][$product_key] ); |
|
| 631 | + if (empty($d['product_qty'])) { |
|
| 632 | + unset($cart_items[$product_key]); |
|
| 633 | + unset($cart_infos['order_items'][$product_key]); |
|
| 634 | 634 | } |
| 635 | 635 | else { |
| 636 | 636 | $wps_orders = new wps_orders_ctr(); |
@@ -641,16 +641,16 @@ discard block |
||
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Add automaticaly Add-to-cart Products |
| 644 | - $cart_items = $this->add_automaticaly_product_to_cart( $cart_items ); |
|
| 644 | + $cart_items = $this->add_automaticaly_product_to_cart($cart_items); |
|
| 645 | 645 | |
| 646 | 646 | // Calcul Cart Informations |
| 647 | 647 | $cart_has_special_product = false; |
| 648 | - if( !empty($cart_items) && is_array($cart_items) ) { |
|
| 649 | - foreach( $cart_items as $item_id => $item ) { |
|
| 648 | + if (!empty($cart_items) && is_array($cart_items)) { |
|
| 649 | + foreach ($cart_items as $item_id => $item) { |
|
| 650 | 650 | |
| 651 | - if ( !empty( $item[ 'item_amount_to_pay_now' ] ) ) { |
|
| 651 | + if (!empty($item['item_amount_to_pay_now'])) { |
|
| 652 | 652 | $cart_has_special_product = true; |
| 653 | - $cart_infos['order_amount_to_pay_now'] += ( $item[ 'item_amount_to_pay_now' ] * $item[ 'item_qty' ] ); |
|
| 653 | + $cart_infos['order_amount_to_pay_now'] += ($item['item_amount_to_pay_now'] * $item['item_qty']); |
|
| 654 | 654 | } |
| 655 | 655 | else { |
| 656 | 656 | $cart_infos['order_amount_to_pay_now'] += $item['item_total_ttc']; |
@@ -659,11 +659,11 @@ discard block |
||
| 659 | 659 | $order_total_ht += $item['item_total_ht']; |
| 660 | 660 | $order_total_ttc += $item['item_total_ttc']; |
| 661 | 661 | // VAT |
| 662 | - if( !empty($order_tva[ $item['item_tva_rate'] ]) ) { |
|
| 663 | - $order_tva[ $item['item_tva_rate'] ] += $item['item_tva_total_amount']; |
|
| 662 | + if (!empty($order_tva[$item['item_tva_rate']])) { |
|
| 663 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 664 | 664 | } |
| 665 | 665 | else { |
| 666 | - $order_tva[ $item['item_tva_rate'] ] = $item['item_tva_total_amount']; |
|
| 666 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } |
@@ -677,13 +677,13 @@ discard block |
||
| 677 | 677 | $cart_infos['order_total_ttc'] = $order_total_ttc; |
| 678 | 678 | |
| 679 | 679 | // Calcul Shipping cost |
| 680 | - if( !$from_admin && empty( $cart_infos['order_shipping_cost_fixe'] ) && empty($_SESSION[ 'wps-pos-addon' ]) ) { |
|
| 680 | + if (!$from_admin && empty($cart_infos['order_shipping_cost_fixe']) && empty($_SESSION['wps-pos-addon'])) { |
|
| 681 | 681 | $wps_shipping = new wps_shipping(); |
| 682 | - $total_cart_ht_or_ttc_regarding_config = ( !empty($price_piloting) && $price_piloting == 'HT' ) ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 683 | - $cart_weight = $wps_shipping->calcul_cart_weight( $cart_infos['order_items'] ); |
|
| 684 | - $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost( $cart_infos['order_items'] ); |
|
| 685 | - foreach( $cart_infos['order_items'] as $item ) { |
|
| 686 | - if( !empty($item['item_is_downloadable_']) && ( __( $item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __( $item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
| 682 | + $total_cart_ht_or_ttc_regarding_config = (!empty($price_piloting) && $price_piloting == 'HT') ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; |
|
| 683 | + $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']); |
|
| 684 | + $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']); |
|
| 685 | + foreach ($cart_infos['order_items'] as $item) { |
|
| 686 | + if (!empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
| 687 | 687 | $is_downloadable_products = 'is_downloadable_'; |
| 688 | 688 | } else { |
| 689 | 689 | $is_downloadable_products = ''; |
@@ -695,39 +695,39 @@ discard block |
||
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | // If Price piloting is ET, calcul VAT on Shipping cost |
| 698 | - if ( !empty($price_piloting) && $price_piloting == 'HT') { |
|
| 699 | - $shipping_cost_vat = ( !empty($cart_infos['order_shipping_cost']) ) ? ( WPSHOP_VAT_ON_SHIPPING_COST / 100 ) * number_format( $cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 698 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 699 | + $shipping_cost_vat = (!empty($cart_infos['order_shipping_cost'])) ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0; |
|
| 700 | 700 | $order_tva['VAT_shipping_cost'] = $shipping_cost_vat; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // Calcul VAT Total |
| 704 | - if( !empty($order_tva) ) { |
|
| 705 | - foreach( $order_tva as $vat_rate => $vat_value ) { |
|
| 704 | + if (!empty($order_tva)) { |
|
| 705 | + foreach ($order_tva as $vat_rate => $vat_value) { |
|
| 706 | 706 | $total_vat += $vat_value; |
| 707 | 707 | } |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | // Recap totals |
| 711 | - $cart_infos['order_total_ttc'] = ( $cart_infos['order_total_ht'] + ( !empty( $cart_infos ) && !empty( $cart_infos[ 'order_shipping_cost' ] ) ? $cart_infos['order_shipping_cost'] : 0 ) + $total_vat ); |
|
| 711 | + $cart_infos['order_total_ttc'] = ($cart_infos['order_total_ht'] + (!empty($cart_infos) && !empty($cart_infos['order_shipping_cost']) ? $cart_infos['order_shipping_cost'] : 0) + $total_vat); |
|
| 712 | 712 | $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc']; |
| 713 | 713 | |
| 714 | 714 | // Total to pay now |
| 715 | 715 | $total_received = 0; |
| 716 | - if( !empty( $cart_infos['order_payment']['received'] ) ) { |
|
| 717 | - foreach( $cart_infos['order_payment']['received'] as $received ) { |
|
| 718 | - $total_received += ( ( !empty($received['status']) && ( $received['status'] == 'payment_received') && !empty($received['received_amount']) ) ? $received['received_amount'] : 0 ); |
|
| 716 | + if (!empty($cart_infos['order_payment']['received'])) { |
|
| 717 | + foreach ($cart_infos['order_payment']['received'] as $received) { |
|
| 718 | + $total_received += ((!empty($received['status']) && ($received['status'] == 'payment_received') && !empty($received['received_amount'])) ? $received['received_amount'] : 0); |
|
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] - $total_received; |
| 722 | 722 | |
| 723 | 723 | // Apply cart rules |
| 724 | - $cart_rule = wpshop_cart_rules::get_cart_rule( $cart_infos['order_grand_total'] ); |
|
| 725 | - if( $cart_rule['cart_rule_exist'] ) { |
|
| 726 | - if ( !empty( $cart_rule['cart_rule_info']['discount_type'] ) ) { |
|
| 727 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount' ) { |
|
| 724 | + $cart_rule = wpshop_cart_rules::get_cart_rule($cart_infos['order_grand_total']); |
|
| 725 | + if ($cart_rule['cart_rule_exist']) { |
|
| 726 | + if (!empty($cart_rule['cart_rule_info']['discount_type'])) { |
|
| 727 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'absolute_discount') { |
|
| 728 | 728 | $cart_infos['order_discount_type'] = 'amount'; |
| 729 | 729 | } |
| 730 | - if ( $cart_rule['cart_rule_info']['discount_type'] == 'percent_discount' ) { |
|
| 730 | + if ($cart_rule['cart_rule_info']['discount_type'] == 'percent_discount') { |
|
| 731 | 731 | $cart_infos['order_discount_type'] = 'percent'; |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -735,15 +735,15 @@ discard block |
||
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // Apply coupons |
| 738 | - if( !empty( $_SESSION['cart']) && !$from_admin ) { |
|
| 739 | - if( !empty($_SESSION['cart']['coupon_id']) ) { |
|
| 738 | + if (!empty($_SESSION['cart']) && !$from_admin) { |
|
| 739 | + if (!empty($_SESSION['cart']['coupon_id'])) { |
|
| 740 | 740 | $wps_coupon_mdl = new wps_coupon_model(); |
| 741 | - $coupon = $wps_coupon_mdl->get_coupon_data( $_SESSION['cart']['coupon_id'] ); |
|
| 742 | - if( !empty($coupon) && !empty($coupon['wpshop_coupon_code']) ) { |
|
| 741 | + $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']); |
|
| 742 | + if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) { |
|
| 743 | 743 | $wps_coupon = new wps_coupon_ctr(); |
| 744 | - $coupon_checking = $wps_coupon->applyCoupon( $coupon['wpshop_coupon_code'] ); |
|
| 744 | + $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']); |
|
| 745 | 745 | // If Coupon conditions are Ok |
| 746 | - if( !empty($coupon_checking) && !empty( $coupon_checking['status'] ) && ( true == $coupon_checking['status'] ) ) { |
|
| 746 | + if (!empty($coupon_checking) && !empty($coupon_checking['status']) && (true == $coupon_checking['status'])) { |
|
| 747 | 747 | $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type']; |
| 748 | 748 | $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value']; |
| 749 | 749 | } |
@@ -752,51 +752,51 @@ discard block |
||
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // Checking Discounts |
| 755 | - if( !empty($cart_infos['order_discount_type']) && isset( $cart_infos['order_discount_value'] ) ) { |
|
| 755 | + if (!empty($cart_infos['order_discount_type']) && isset($cart_infos['order_discount_value'])) { |
|
| 756 | 756 | // Calcul discount on Order |
| 757 | 757 | switch ($cart_infos['order_discount_type']) { |
| 758 | 758 | case 'amount': |
| 759 | - $cart_infos['order_discount_amount_total_cart'] = number_format( str_replace( ',', '.', $cart_infos['order_discount_value'] ), 2, '.', ''); |
|
| 759 | + $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', ''); |
|
| 760 | 760 | break; |
| 761 | 761 | case 'percent': |
| 762 | - $cart_infos['order_discount_amount_total_cart'] = number_format( $cart_infos['order_grand_total'], 2, '.', '') * ( number_format( str_replace( ',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100); |
|
| 762 | + $cart_infos['order_discount_amount_total_cart'] = number_format($cart_infos['order_grand_total'], 2, '.', '') * (number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100); |
|
| 763 | 763 | break; |
| 764 | 764 | } |
| 765 | - if ( number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format( $cart_infos['order_grand_total'], 2, '.', '') ) { |
|
| 765 | + if (number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '') > number_format($cart_infos['order_grand_total'], 2, '.', '')) { |
|
| 766 | 766 | $cart_infos['order_grand_total'] = 0; |
| 767 | 767 | } |
| 768 | 768 | else { |
| 769 | - $cart_infos['order_grand_total'] -= number_format( $cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 769 | + $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', ''); |
|
| 770 | 770 | } |
| 771 | - $cart_infos['order_amount_to_pay_now'] = number_format( $cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 771 | + $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'] - $total_received, 2, '.', ''); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | // Apply Partial Payments |
| 775 | 775 | $wpshop_payment = new wpshop_payment(); |
| 776 | - if( !empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation' ) { |
|
| 777 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'], 'for_quotation' ); |
|
| 776 | + if (!empty($cart_infos['cart_type']) && $cart_infos['cart_type'] == 'quotation') { |
|
| 777 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total'], 'for_quotation'); |
|
| 778 | 778 | } |
| 779 | 779 | else { |
| 780 | - $partial_payment = $wpshop_payment->partial_payment_calcul( $cart_infos['order_grand_total'] ); |
|
| 780 | + $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']); |
|
| 781 | 781 | } |
| 782 | - if ( !empty($partial_payment['amount_to_pay']) && ( empty( $cart_infos['order_status'] ) || $cart_infos['order_status'] == 'awaiting_payment' ) && ( empty( $product_partial_payment_amount ) ) ) { |
|
| 782 | + if (!empty($partial_payment['amount_to_pay']) && (empty($cart_infos['order_status']) || $cart_infos['order_status'] == 'awaiting_payment') && (empty($product_partial_payment_amount))) { |
|
| 783 | 783 | unset($partial_payment['display']); |
| 784 | - $cart_infos['order_partial_payment'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 785 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $partial_payment['amount_to_pay'] ), 2, '.', ''); |
|
| 784 | + $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 785 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); |
|
| 786 | 786 | } |
| 787 | 787 | // Apply Partial Payments : Subscription part. |
| 788 | - elseif ( ! empty( $cart_has_special_product ) ) { |
|
| 789 | - $cart_infos['order_amount_to_pay_now'] = number_format( str_replace( ',', '.', $cart_infos['order_amount_to_pay_now'] ), 2, '.', ''); |
|
| 788 | + elseif (!empty($cart_has_special_product)) { |
|
| 789 | + $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $cart_infos['order_amount_to_pay_now']), 2, '.', ''); |
|
| 790 | 790 | $cart_infos['order_product_partial_payment'] = 'subscription'; |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Cart Type |
| 794 | - if ( isset( $_SESSION['cart']['cart_type'] ) ) { |
|
| 794 | + if (isset($_SESSION['cart']['cart_type'])) { |
|
| 795 | 795 | $cart_infos['cart_type'] = $_SESSION['cart']['cart_type']; |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | // Apply Extra actions on cart infos |
| 799 | - $cart_infos = apply_filters( 'wps_extra_calcul_in_cart', $cart_infos, $_SESSION ); |
|
| 799 | + $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION); |
|
| 800 | 800 | |
| 801 | 801 | return $cart_infos; |
| 802 | 802 | } |
@@ -806,18 +806,18 @@ discard block |
||
| 806 | 806 | * @param array $cart_items |
| 807 | 807 | * @return array |
| 808 | 808 | */ |
| 809 | - function add_automaticaly_product_to_cart( $cart_items ) { |
|
| 809 | + function add_automaticaly_product_to_cart($cart_items) { |
|
| 810 | 810 | global $wpdb; |
| 811 | 811 | // Recovery all products with options |
| 812 | 812 | $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
| 813 | 813 | $post_list_with_options = $wpdb->get_results($query); |
| 814 | 814 | $wps_orders = new wps_orders_ctr(); |
| 815 | - if ( !empty($post_list_with_options) && !empty($cart_items) ) { |
|
| 816 | - foreach ( $post_list_with_options as $product_info) { |
|
| 815 | + if (!empty($post_list_with_options) && !empty($cart_items)) { |
|
| 816 | + foreach ($post_list_with_options as $product_info) { |
|
| 817 | 817 | $product_meta = unserialize($product_info->meta_value); |
| 818 | - if ( !empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id]) ) { |
|
| 818 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes') && empty($cart_items[$product_info->post_id])) { |
|
| 819 | 819 | $product = wpshop_products::get_product_data($product_info->post_id, true, '"draft", "publish"'); |
| 820 | - $the_product = array_merge( array( |
|
| 820 | + $the_product = array_merge(array( |
|
| 821 | 821 | 'product_id' => $product_info->post_id, |
| 822 | 822 | 'product_qty' => 1 |
| 823 | 823 | ), $product); |
@@ -831,28 +831,28 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | /** Ajax action to reload cart **/ |
| 833 | 833 | public static function wps_reload_cart() { |
| 834 | - check_ajax_referer( 'wps_reload_cart' ); |
|
| 834 | + check_ajax_referer('wps_reload_cart'); |
|
| 835 | 835 | |
| 836 | 836 | $wps_cart = new wps_cart(); |
| 837 | 837 | $result = $wps_cart->cart_content(); |
| 838 | 838 | |
| 839 | - wp_die( json_encode( array( 'response' => $result) ) ); |
|
| 839 | + wp_die(json_encode(array('response' => $result))); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | |
| 843 | 843 | /** Ajax action to reload mini cart */ |
| 844 | 844 | public function wps_reload_mini_cart() { |
| 845 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 845 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 846 | 846 | |
| 847 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_mini_cart' ) ) |
|
| 847 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_mini_cart')) |
|
| 848 | 848 | wp_die(); |
| 849 | 849 | |
| 850 | 850 | $wps_cart = new wps_cart(); |
| 851 | - $result = $wps_cart->mini_cart_content( sanitize_title( $_POST['type']) ); |
|
| 852 | - $count_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $wps_cart->total_cart_items( $_SESSION['cart']['order_items'] ) : 0; |
|
| 851 | + $result = $wps_cart->mini_cart_content(sanitize_title($_POST['type'])); |
|
| 852 | + $count_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0; |
|
| 853 | 853 | $free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert'); |
| 854 | 854 | |
| 855 | - echo json_encode( array( 'response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert) ); |
|
| 855 | + echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert)); |
|
| 856 | 856 | die(); |
| 857 | 857 | } |
| 858 | 858 | |
@@ -862,35 +862,35 @@ discard block |
||
| 862 | 862 | * @return string |
| 863 | 863 | */ |
| 864 | 864 | function display_wps_numeration_cart() { |
| 865 | - $cart_items = ( !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) ? $_SESSION['cart']['order_items'] : array(); |
|
| 866 | - $total_cart_item = self::total_cart_items( $cart_items ); |
|
| 865 | + $cart_items = (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) ? $_SESSION['cart']['order_items'] : array(); |
|
| 866 | + $total_cart_item = self::total_cart_items($cart_items); |
|
| 867 | 867 | |
| 868 | 868 | ob_start(); |
| 869 | - require(wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart") ); |
|
| 869 | + require(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "cart/numeration-cart")); |
|
| 870 | 870 | $output = ob_get_contents(); |
| 871 | 871 | ob_end_clean(); |
| 872 | 872 | return $output; |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - public function display_button_add_to_cart( $args ) { |
|
| 876 | - $button_text = __( 'Add to cart', 'wpshop' ); |
|
| 875 | + public function display_button_add_to_cart($args) { |
|
| 876 | + $button_text = __('Add to cart', 'wpshop'); |
|
| 877 | 877 | $use_button = true; |
| 878 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
| 878 | + $output = __('No product has been found.', 'wpshop'); |
|
| 879 | 879 | |
| 880 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 880 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 881 | 881 | |
| 882 | 882 | /** The user send the text in argument */ |
| 883 | - if ( !empty( $args['text' ] ) ) { |
|
| 883 | + if (!empty($args['text'])) { |
|
| 884 | 884 | $button_text = $args['text']; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** The user send use input */ |
| 888 | - if ( !empty( $args['use_button'] ) && 'false' == $args['use_button'] ) { |
|
| 888 | + if (!empty($args['use_button']) && 'false' == $args['use_button']) { |
|
| 889 | 889 | $use_button = false; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | ob_start(); |
| 893 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart' ) ); |
|
| 893 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, 'frontend/cart', 'button', 'add-to-cart')); |
|
| 894 | 894 | $output = ob_get_clean(); |
| 895 | 895 | } |
| 896 | 896 | |
@@ -899,21 +899,21 @@ discard block |
||
| 899 | 899 | |
| 900 | 900 | /** Ajax action to reload summary cart */ |
| 901 | 901 | public static function wps_reload_summary_cart() { |
| 902 | - check_ajax_referer( 'wps_reload_summary_cart' ); |
|
| 902 | + check_ajax_referer('wps_reload_summary_cart'); |
|
| 903 | 903 | |
| 904 | 904 | $wps_cart = new wps_cart(); |
| 905 | 905 | $result = $wps_cart->resume_cart_content(); |
| 906 | 906 | |
| 907 | - wp_die( json_encode( array( 'response' => $result, ) ) ); |
|
| 907 | + wp_die(json_encode(array('response' => $result,))); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
| 911 | 911 | /** Display Apply Coupon Interface **/ |
| 912 | 912 | function display_apply_coupon_interface() { |
| 913 | 913 | $output = ''; |
| 914 | - if ( !empty( $_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ) { |
|
| 914 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 915 | 915 | ob_start(); |
| 916 | - require_once( wpshop_tools::get_template_part( WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon") ); |
|
| 916 | + require_once(wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "coupon/apply_coupon")); |
|
| 917 | 917 | $output = ob_get_contents(); |
| 918 | 918 | ob_end_clean(); |
| 919 | 919 | } |
@@ -923,30 +923,30 @@ discard block |
||
| 923 | 923 | |
| 924 | 924 | /** AJAX - action to apply coupon **/ |
| 925 | 925 | function wps_apply_coupon() { |
| 926 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 926 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 927 | 927 | |
| 928 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_apply_coupon' ) ) |
|
| 928 | + if (!wp_verify_nonce($_wpnonce, 'wps_apply_coupon')) |
|
| 929 | 929 | wp_die(); |
| 930 | 930 | |
| 931 | 931 | $status = false; $response = ''; |
| 932 | - $coupon = ( !empty($_POST['coupon_code']) ) ? wpshop_tools::varSanitizer( $_POST['coupon_code']) : null; |
|
| 933 | - if( !empty($coupon) ) { |
|
| 932 | + $coupon = (!empty($_POST['coupon_code'])) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null; |
|
| 933 | + if (!empty($coupon)) { |
|
| 934 | 934 | $wps_coupon_ctr = new wps_coupon_ctr(); |
| 935 | 935 | $result = $wps_coupon_ctr->applyCoupon($coupon); |
| 936 | - if ($result['status']===true) { |
|
| 936 | + if ($result['status'] === true) { |
|
| 937 | 937 | $order = $this->calcul_cart_information(array()); |
| 938 | 938 | $this->store_cart_in_session($order); |
| 939 | 939 | $status = true; |
| 940 | - $response = '<div class="wps-alert-success">' .__( 'The coupon has been applied', 'wpshop' ). '</div>'; |
|
| 940 | + $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>'; |
|
| 941 | 941 | } |
| 942 | 942 | else { |
| 943 | - $response = '<div class="wps-alert-error">' .$result['message']. '</div>'; |
|
| 943 | + $response = '<div class="wps-alert-error">' . $result['message'] . '</div>'; |
|
| 944 | 944 | } |
| 945 | 945 | } |
| 946 | 946 | else { |
| 947 | - $response = '<div class="wps-alert-error">'.__( 'A coupon code is required', 'wpshop'). '</div>'; |
|
| 947 | + $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>'; |
|
| 948 | 948 | } |
| 949 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 949 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 950 | 950 | die(); |
| 951 | 951 | } |
| 952 | 952 | |
@@ -955,24 +955,24 @@ discard block |
||
| 955 | 955 | * AJAX - Pass to step two in the Checkout tunnel |
| 956 | 956 | */ |
| 957 | 957 | public static function wps_cart_pass_to_step_two() { |
| 958 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 958 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 959 | 959 | |
| 960 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_cart_pass_to_step_two' ) ) |
|
| 960 | + if (!wp_verify_nonce($_wpnonce, 'wps_cart_pass_to_step_two')) |
|
| 961 | 961 | wp_die(); |
| 962 | 962 | |
| 963 | 963 | $status = false; $response = ''; |
| 964 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 965 | - if( !empty($checkout_page_id) ) { |
|
| 966 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 967 | - $step = ( get_current_user_id() != 0 ) ? 3 : 2; |
|
| 968 | - $response = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step='.$step; |
|
| 964 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 965 | + if (!empty($checkout_page_id)) { |
|
| 966 | + $permalink_option = get_option('permalink_structure'); |
|
| 967 | + $step = (get_current_user_id() != 0) ? 3 : 2; |
|
| 968 | + $response = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=' . $step; |
|
| 969 | 969 | $response = apply_filters('wps_extra_signup_actions', $response); |
| 970 | 970 | $status = true; |
| 971 | 971 | } |
| 972 | 972 | else { |
| 973 | - $response = '<div class="wps-alert-error">' .__( 'An error was occured, please retry later or contact the website administrator', 'wpshop' ). '</div>'; |
|
| 973 | + $response = '<div class="wps-alert-error">' . __('An error was occured, please retry later or contact the website administrator', 'wpshop') . '</div>'; |
|
| 974 | 974 | } |
| 975 | - echo json_encode( array( 'status' => $status, 'response' => $response)); |
|
| 975 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 976 | 976 | die(); |
| 977 | 977 | } |
| 978 | 978 | |
@@ -981,14 +981,14 @@ discard block |
||
| 981 | 981 | * AJAX - Empty the cart |
| 982 | 982 | */ |
| 983 | 983 | function wps_empty_cart() { |
| 984 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 984 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 985 | 985 | |
| 986 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_empty_cart' ) ) |
|
| 986 | + if (!wp_verify_nonce($_wpnonce, 'wps_empty_cart')) |
|
| 987 | 987 | wp_die(); |
| 988 | 988 | |
| 989 | 989 | |
| 990 | 990 | $this->empty_cart(); |
| 991 | - echo json_encode( array( 'status' => true) ); |
|
| 991 | + echo json_encode(array('status' => true)); |
|
| 992 | 992 | die(); |
| 993 | 993 | } |
| 994 | 994 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * WPSHOP Prices bootstrap file |
@@ -9,17 +9,17 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
| 13 | - die( __("You are not allowed to use this service.", 'wpshop') ); |
|
| 12 | +if (!defined('WPSHOP_VERSION')) { |
|
| 13 | + die(__("You are not allowed to use this service.", 'wpshop')); |
|
| 14 | 14 | } |
| 15 | -if ( !class_exists("wpshop_prices") ) { |
|
| 15 | +if (!class_exists("wpshop_prices")) { |
|
| 16 | 16 | class wpshop_prices { |
| 17 | 17 | |
| 18 | 18 | function __construct() { |
| 19 | 19 | add_action('wsphop_options', array('wpshop_prices', 'declare_options')); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function declare_options () { |
|
| 22 | + public static function declare_options() { |
|
| 23 | 23 | register_setting('wpshop_options', 'wpshop_catalog_product_option', array('wpshop_prices', 'wpshop_options_validate_prices')); |
| 24 | 24 | add_settings_field('wpshop_catalog_product_option_discount', __('Activate the discount on products', 'wpshop'), array('wpshop_prices', 'wpshop_activate_discount_prices_field'), 'wpshop_catalog_product_option', 'wpshop_catalog_product_section'); |
| 25 | 25 | } |
@@ -29,37 +29,37 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | /** Price attribute Def **/ |
| 31 | 31 | $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
| 32 | - $price_attribute_def = wpshop_attributes::getElement( ( (!empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? 'price_ht' : 'product_price' ), "'valid'", 'code'); |
|
| 32 | + $price_attribute_def = wpshop_attributes::getElement(((!empty($price_piloting_option) && $price_piloting_option == 'HT') ? 'price_ht' : 'product_price'), "'valid'", 'code'); |
|
| 33 | 33 | |
| 34 | 34 | /** Discount attributes **/ |
| 35 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s OR code = %s OR code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to' ); |
|
| 35 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s OR code = %s OR code = %s OR code = %s', 'discount_amount', 'discount_rate', 'special_price', 'special_from', 'special_to'); |
|
| 36 | 36 | $discount_attributes = $wpdb->get_results($query); |
| 37 | 37 | |
| 38 | 38 | /** Check if discount is actived **/ |
| 39 | - if ( !empty( $input) && !empty($input['discount']) ) { |
|
| 39 | + if (!empty($input) && !empty($input['discount'])) { |
|
| 40 | 40 | /** Activate the attributes **/ |
| 41 | - if ( !empty($discount_attributes) ) { |
|
| 42 | - foreach ( $discount_attributes as $discount_attribute ) { |
|
| 43 | - $update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "valid" WHERE code = %s', $discount_attribute->code); |
|
| 41 | + if (!empty($discount_attributes)) { |
|
| 42 | + foreach ($discount_attributes as $discount_attribute) { |
|
| 43 | + $update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "valid" WHERE code = %s', $discount_attribute->code); |
|
| 44 | 44 | $wpdb->query($update); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** Affect discount attributes to All Attributes Set section where there is a Price attribute **/ |
| 49 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id); |
|
| 50 | - $attributes_sections = $wpdb->get_results( $query ); |
|
| 51 | - if ( !empty($attributes_sections) ) { |
|
| 52 | - foreach ( $attributes_sections as $attributes_section ) { |
|
| 49 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id); |
|
| 50 | + $attributes_sections = $wpdb->get_results($query); |
|
| 51 | + if (!empty($attributes_sections)) { |
|
| 52 | + foreach ($attributes_sections as $attributes_section) { |
|
| 53 | 53 | /** Check the Max Position for the Attribute section */ |
| 54 | - $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id); |
|
| 55 | - $max_position = $wpdb->get_var( $query ); |
|
| 56 | - $max_position = ( !empty($max_position) ) ? $max_position : 0; |
|
| 54 | + $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id); |
|
| 55 | + $max_position = $wpdb->get_var($query); |
|
| 56 | + $max_position = (!empty($max_position)) ? $max_position : 0; |
|
| 57 | 57 | /** Affect the discount attributes **/ |
| 58 | - foreach ( $discount_attributes as $discount_attribute) { |
|
| 59 | - $query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id); |
|
| 60 | - $count_attribute_affectation = $wpdb->get_row( $query ); |
|
| 61 | - if ( !empty($count_attribute_affectation) && ( empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0 ) ) { |
|
| 62 | - $result = $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position) ); |
|
| 58 | + foreach ($discount_attributes as $discount_attribute) { |
|
| 59 | + $query = $wpdb->prepare(' SELECT COUNT(*) AS count_attributes_affect FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_group_id = %d AND entity_type_id = %s AND attribute_id = %d', $attributes_section->attribute_set_id, $attributes_section->attribute_group_id, $attributes_section->entity_type_id, $discount_attribute->id); |
|
| 60 | + $count_attribute_affectation = $wpdb->get_row($query); |
|
| 61 | + if (!empty($count_attribute_affectation) && (empty($count_attribute_affectation->count_attributes_affect) || $count_attribute_affectation->count_attributes_affect == 0)) { |
|
| 62 | + $result = $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id, 'position' => $max_position)); |
|
| 63 | 63 | $max_position += 1; |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -68,21 +68,21 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | else { |
| 70 | 70 | /** Desactivate Discount Attributes **/ |
| 71 | - if ( !empty($discount_attributes) ) { |
|
| 72 | - foreach ( $discount_attributes as $discount_attribute ) { |
|
| 73 | - $update = $wpdb->prepare('UPDATE ' .WPSHOP_DBT_ATTRIBUTE. ' SET status = "notused" WHERE code = %s', $discount_attribute->code); |
|
| 71 | + if (!empty($discount_attributes)) { |
|
| 72 | + foreach ($discount_attributes as $discount_attribute) { |
|
| 73 | + $update = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET status = "notused" WHERE code = %s', $discount_attribute->code); |
|
| 74 | 74 | $wpdb->query($update); |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** Delete the Price attribute set section affectation **/ |
| 79 | - $query = $wpdb->prepare('SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE attribute_id = %d', $price_attribute_def->id); |
|
| 80 | - $attributes_sections = $wpdb->get_results( $query ); |
|
| 81 | - if ( !empty($attributes_sections) ) { |
|
| 82 | - foreach ( $attributes_sections as $attributes_section ) { |
|
| 79 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %d', $price_attribute_def->id); |
|
| 80 | + $attributes_sections = $wpdb->get_results($query); |
|
| 81 | + if (!empty($attributes_sections)) { |
|
| 82 | + foreach ($attributes_sections as $attributes_section) { |
|
| 83 | 83 | /** Affect the discount attributes **/ |
| 84 | - foreach ( $discount_attributes as $discount_attribute) { |
|
| 85 | - $wpdb->delete( WPSHOP_DBT_ATTRIBUTE_DETAILS, array( 'entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id ) ); |
|
| 84 | + foreach ($discount_attributes as $discount_attribute) { |
|
| 85 | + $wpdb->delete(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $attributes_section->entity_type_id, 'attribute_set_id' => $attributes_section->attribute_set_id, 'attribute_group_id' => $attributes_section->attribute_group_id, 'attribute_id' => $discount_attribute->id)); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -94,72 +94,72 @@ discard block |
||
| 94 | 94 | public static function wpshop_activate_discount_prices_field() { |
| 95 | 95 | $product_discount_option = get_option('wpshop_catalog_product_option'); |
| 96 | 96 | |
| 97 | - $output = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' .( (!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '' ). ' />'; |
|
| 98 | - $output .= '<a class="wpshop_infobulle_marker" title="' .__('Activate the possibility to create discount on products', 'wpshop'). '" href="#">?</a>'; |
|
| 97 | + $output = '<input type="checkbox" id="wpshop_catalog_product_option_discount" name="wpshop_catalog_product_option[discount]" ' . ((!empty($product_discount_option) && !empty($product_discount_option['discount'])) ? 'checked="checked"' : '') . ' />'; |
|
| 98 | + $output .= '<a class="wpshop_infobulle_marker" title="' . __('Activate the possibility to create discount on products', 'wpshop') . '" href="#">?</a>'; |
|
| 99 | 99 | echo $output; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public static function check_product_price( $product, $cart = false ) { |
|
| 102 | + public static function check_product_price($product, $cart = false) { |
|
| 103 | 103 | $price_infos = array(); |
| 104 | 104 | $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
| 105 | - if ( !empty($product) ) { |
|
| 106 | - if ( $cart ) { |
|
| 107 | - $discount_config = self::check_discount_for_product($product['product_id'] ); |
|
| 108 | - if ( !empty($discount_config) ) { |
|
| 105 | + if (!empty($product)) { |
|
| 106 | + if ($cart) { |
|
| 107 | + $discount_config = self::check_discount_for_product($product['product_id']); |
|
| 108 | + if (!empty($discount_config)) { |
|
| 109 | 109 | $product['price_ttc_before_discount'] = $product['product_price']; |
| 110 | 110 | $product['price_ht_before_discount'] = $product['price_ht']; |
| 111 | 111 | |
| 112 | - if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) { |
|
| 113 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100); |
|
| 114 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value']; |
|
| 115 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 112 | + if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') { |
|
| 113 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100); |
|
| 114 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value']; |
|
| 115 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 116 | 116 | } |
| 117 | - elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) { |
|
| 118 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 119 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value']; |
|
| 120 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 117 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') { |
|
| 118 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100)); |
|
| 119 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value']; |
|
| 120 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | - elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 124 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 - $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 125 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) ); |
|
| 126 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 123 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 124 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100)); |
|
| 125 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100)); |
|
| 126 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 127 | 127 | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| 131 | - $price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', ''); |
|
| 132 | - $price_infos['et'] = ( !empty($product['price_ht_before_discount'] ) ) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', ''); |
|
| 133 | - $price_infos['tva'] = $price_infos['et'] * ( $product['tx_tva'] / 100); |
|
| 131 | + $price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 2, '.', '') : number_format((float)$product['product_price'], 2, '.', ''); |
|
| 132 | + $price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 2, '.', '') : number_format((float)$product['price_ht'], 2, '.', ''); |
|
| 133 | + $price_infos['tva'] = $price_infos['et'] * ($product['tx_tva'] / 100); |
|
| 134 | 134 | |
| 135 | - $price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'] ) ) ? true : false; |
|
| 136 | - $price_infos['discount']['discount_ati_price'] = ( !empty($product['price_ttc_before_discount']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0; |
|
| 137 | - $price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht_before_discount']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0; |
|
| 138 | - $price_infos['discount']['discount_tva'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount']) ) ? number_format( ($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0; |
|
| 135 | + $price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false; |
|
| 136 | + $price_infos['discount']['discount_ati_price'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0; |
|
| 137 | + $price_infos['discount']['discount_et_price'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0; |
|
| 138 | + $price_infos['discount']['discount_tva'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? number_format(($price_infos['discount']['discount_ati_price'] - $price_infos['discount']['discount_et_price']), 2, '.', '') : 0; |
|
| 139 | 139 | } |
| 140 | 140 | else { |
| 141 | - $price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0; |
|
| 142 | - $price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0; |
|
| 143 | - $price_infos['tva'] = ( !empty($product['tva'] ) ) ? $product['tva'] : 0; |
|
| 141 | + $price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0; |
|
| 142 | + $price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0; |
|
| 143 | + $price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | else { |
| 149 | - if ( !empty( $product['price_ttc_before_discount']) && !empty( $product['price_ht_before_discount'] ) ) { |
|
| 150 | - $price_infos['discount']['discount_exist'] = ( !empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'] ) ) ? true : false; |
|
| 151 | - $price_infos['discount']['discount_ati_price'] = ( !empty($product['product_price']) ) ? number_format((float)$product['product_price'], 2, '.', '') : 0; |
|
| 152 | - $price_infos['discount']['discount_et_price'] = ( !empty($product['price_ht']) ) ? number_format( (float)$product['price_ht'], 2, '.', '' ) : 0; |
|
| 153 | - $price_infos['discount']['discount_tva'] = ( !empty($product['tva']) ) ? $product['tva'] : 0; |
|
| 154 | - |
|
| 155 | - $price_infos['ati'] = ( !empty($product['price_ttc_before_discount'] )) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0; |
|
| 156 | - $price_infos['et'] = ( !empty($product['price_ht_before_discount']) ) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0; |
|
| 157 | - $price_infos['tva'] = $price_infos['ati'] - $price_infos['et']; |
|
| 149 | + if (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) { |
|
| 150 | + $price_infos['discount']['discount_exist'] = (!empty($product['price_ttc_before_discount']) && !empty($product['price_ht_before_discount'])) ? true : false; |
|
| 151 | + $price_infos['discount']['discount_ati_price'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 2, '.', '') : 0; |
|
| 152 | + $price_infos['discount']['discount_et_price'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 2, '.', '') : 0; |
|
| 153 | + $price_infos['discount']['discount_tva'] = (!empty($product['tva'])) ? $product['tva'] : 0; |
|
| 154 | + |
|
| 155 | + $price_infos['ati'] = (!empty($product['price_ttc_before_discount'])) ? number_format((float)$product['price_ttc_before_discount'], 5, '.', '') : 0; |
|
| 156 | + $price_infos['et'] = (!empty($product['price_ht_before_discount'])) ? number_format((float)$product['price_ht_before_discount'], 5, '.', '') : 0; |
|
| 157 | + $price_infos['tva'] = $price_infos['ati'] - $price_infos['et']; |
|
| 158 | 158 | } |
| 159 | 159 | else { |
| 160 | - $price_infos['ati'] = ( !empty($product['product_price'] )) ? number_format((float)$product['product_price'], 5, '.', '') : 0; |
|
| 161 | - $price_infos['et'] = ( !empty($product['price_ht'] ) ) ? number_format((float)$product['price_ht'], 5, '.', '') : 0; |
|
| 162 | - $price_infos['tva'] = ( !empty($product['tva'] ) ) ? $product['tva'] : 0; |
|
| 160 | + $price_infos['ati'] = (!empty($product['product_price'])) ? number_format((float)$product['product_price'], 5, '.', '') : 0; |
|
| 161 | + $price_infos['et'] = (!empty($product['price_ht'])) ? number_format((float)$product['price_ht'], 5, '.', '') : 0; |
|
| 162 | + $price_infos['tva'] = (!empty($product['tva'])) ? $product['tva'] : 0; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -170,65 +170,65 @@ discard block |
||
| 170 | 170 | $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
| 171 | 171 | // $wpshop_price_piloting_option = 'TTC'; |
| 172 | 172 | /** Price for Mini-output **/ |
| 173 | - if( !empty($product['product_id']) && !$price_checking_done ) { |
|
| 173 | + if (!empty($product['product_id']) && !$price_checking_done) { |
|
| 174 | 174 | |
| 175 | 175 | /** Checking if it's a product with variation **/ |
| 176 | - $variation_option_checking = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true ); |
|
| 176 | + $variation_option_checking = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); |
|
| 177 | 177 | |
| 178 | - if( !empty($variation_option_checking) ) { |
|
| 179 | - $variations_exists = wpshop_products::get_variation( $product['product_id'], 'publish' ); |
|
| 178 | + if (!empty($variation_option_checking)) { |
|
| 179 | + $variations_exists = wpshop_products::get_variation($product['product_id'], 'publish'); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if( !empty($variation_option_checking) && !empty($variations_exists) ) { |
|
| 183 | - if ( !empty( $variation_option_checking['attributes']) ) { |
|
| 184 | - foreach( $variation_option_checking['attributes'] as $attribute ) { |
|
| 182 | + if (!empty($variation_option_checking) && !empty($variations_exists)) { |
|
| 183 | + if (!empty($variation_option_checking['attributes'])) { |
|
| 184 | + foreach ($variation_option_checking['attributes'] as $attribute) { |
|
| 185 | 185 | $selected_variation[$attribute] = 0; |
| 186 | - if( !empty( $variation_option_checking['options'] ) && !empty( $variation_option_checking['options']['attributes_default_value'] ) && array_key_exists( $attribute, $variation_option_checking['options']['attributes_default_value']) ){ |
|
| 187 | - if ( $variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') { |
|
| 186 | + if (!empty($variation_option_checking['options']) && !empty($variation_option_checking['options']['attributes_default_value']) && array_key_exists($attribute, $variation_option_checking['options']['attributes_default_value'])) { |
|
| 187 | + if ($variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') { |
|
| 188 | 188 | $selected_variation[$attribute] = $variation_option_checking['options']['attributes_default_value'][$attribute]; |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - if ( !empty($selected_variation) ) { |
|
| 194 | - $product_with_variation = wpshop_products::get_variation_by_priority( $selected_variation, $product['product_id'] ); |
|
| 193 | + if (!empty($selected_variation)) { |
|
| 194 | + $product_with_variation = wpshop_products::get_variation_by_priority($selected_variation, $product['product_id']); |
|
| 195 | 195 | } |
| 196 | - if( empty($product_with_variation[$product['product_id']]['variations']) ) { |
|
| 196 | + if (empty($product_with_variation[$product['product_id']]['variations'])) { |
|
| 197 | 197 | $product_with_variation[$product['product_id']]['variations'] = array(); |
| 198 | 198 | } |
| 199 | - if ( !empty($product_with_variation[$product['product_id']]['variation_priority']) ) { |
|
| 200 | - $product = wpshop_products::get_variation_price_behaviour( $product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '' ) ); |
|
| 199 | + if (!empty($product_with_variation[$product['product_id']]['variation_priority'])) { |
|
| 200 | + $product = wpshop_products::get_variation_price_behaviour($product, $product_with_variation[$product['product_id']]['variations'], $product['product_id'], array('type' => $product_with_variation[$product['product_id']]['variation_priority'], 'text_from' => !empty($product_with_variation['text_from']) ? 'on' : '')); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | else { |
| 204 | 204 | /** It's Simple product Check Discounts for products **/ |
| 205 | - $discount_config = self::check_discount_for_product( $product['product_id'] ); |
|
| 206 | - if ( !empty($discount_config) ) { |
|
| 207 | - if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) { |
|
| 205 | + $discount_config = self::check_discount_for_product($product['product_id']); |
|
| 206 | + if (!empty($discount_config)) { |
|
| 207 | + if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') { |
|
| 208 | 208 | $product['price_ttc_before_discount'] = $product['product_price']; |
| 209 | 209 | $product['price_ht_before_discount'] = $product['price_ht']; |
| 210 | 210 | |
| 211 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100); |
|
| 212 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value']; |
|
| 213 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 211 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100); |
|
| 212 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value']; |
|
| 213 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 214 | 214 | } |
| 215 | - elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) { |
|
| 215 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') { |
|
| 216 | 216 | $product['price_ttc_before_discount'] = $product['product_price']; |
| 217 | 217 | $product['price_ht_before_discount'] = $product['price_ht']; |
| 218 | 218 | |
| 219 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] - $discount_config['value'] ) : ( ( $product['price_ttc_before_discount'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 220 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] - $discount_config['value']; |
|
| 221 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 219 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] - $discount_config['value']) : (($product['price_ttc_before_discount'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100)); |
|
| 220 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] - $discount_config['value']; |
|
| 221 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | - elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 224 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 225 | 225 | $product['price_ttc_before_discount'] = $product['product_price']; |
| 226 | 226 | $product['price_ht_before_discount'] = $product['price_ht']; |
| 227 | 227 | |
| 228 | 228 | |
| 229 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht_before_discount'] * ( 1 - $discount_config['value'] / 100) ) : ( ( $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 230 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['price_ttc_before_discount'] * ( 1 - ( $discount_config['value'] / 100 ) ); |
|
| 231 | - $product['tva'] = $product['price_ht'] * ( $product['tx_tva'] / 100); |
|
| 229 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht_before_discount'] * (1 - $discount_config['value'] / 100)) : (($product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100)); |
|
| 230 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['price_ttc_before_discount'] * (1 - ($discount_config['value'] / 100)); |
|
| 231 | + $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100); |
|
| 232 | 232 | |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -236,116 +236,116 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - $price_infos = self::check_product_price( $product ); |
|
| 240 | - $productCurrency = '<span class="wps-currency">'.wpshop_tools::wpshop_get_currency().'</span>'; |
|
| 239 | + $price_infos = self::check_product_price($product); |
|
| 240 | + $productCurrency = '<span class="wps-currency">' . wpshop_tools::wpshop_get_currency() . '</span>'; |
|
| 241 | 241 | |
| 242 | 242 | $wps_marketing_tools = new wps_marketing_tools_ctr(); |
| 243 | 243 | |
| 244 | - if ( !empty($price_infos) ) { |
|
| 245 | - if ( $return_type == 'check_only' ) { |
|
| 244 | + if (!empty($price_infos)) { |
|
| 245 | + if ($return_type == 'check_only') { |
|
| 246 | 246 | /** Check if the product price has been set */ |
| 247 | - if( isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop'); |
|
| 247 | + if (isset($price_infos['ati']) && $price_infos['ati'] === '') return __('This product cannot be purchased - the price is not yet announced', 'wpshop'); |
|
| 248 | 248 | /** Check if the product price is coherent (not less than 0) */ |
| 249 | - if( isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop'); |
|
| 249 | + if (isset($price_infos['ati']) && $price_infos['ati'] < 0) return __('This product cannot be purchased - its price is negative', 'wpshop'); |
|
| 250 | 250 | |
| 251 | 251 | return true; |
| 252 | 252 | } |
| 253 | - elseif( $return_type == 'just_price_infos' ) { |
|
| 253 | + elseif ($return_type == 'just_price_infos') { |
|
| 254 | 254 | $tpl_component = array(); |
| 255 | 255 | |
| 256 | - $price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 257 | - $exploded_price = explode('.', number_format($price,2, '.', '')); |
|
| 258 | - $price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">,'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>'; |
|
| 256 | + $price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 257 | + $exploded_price = explode('.', number_format($price, 2, '.', '')); |
|
| 258 | + $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">,' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>'; |
|
| 259 | 259 | |
| 260 | - $tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 260 | + $tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 261 | 261 | |
| 262 | 262 | $tpl_component['CROSSED_OUT_PRICE'] = ''; |
| 263 | 263 | $tpl_component['MESSAGE_SAVE_MONEY'] = ''; |
| 264 | 264 | |
| 265 | 265 | |
| 266 | 266 | |
| 267 | - if( !empty($price_infos['discount']['discount_exist']) ) { |
|
| 268 | - $crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency; |
|
| 267 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 268 | + $crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency; |
|
| 269 | 269 | $tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price; |
| 270 | - if(!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') { |
|
| 271 | - $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', '')); |
|
| 270 | + if (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') { |
|
| 271 | + $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', '')); |
|
| 272 | 272 | } |
| 273 | 273 | else { |
| 274 | - $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', '')); |
|
| 274 | + $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', '')); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $discount_price = $exploded_discount_price[0].'<span class="wpshop_price_centimes_display">,'.( (!empty($exploded_discount_price[1]) ) ? $exploded_discount_price[1] : '').'</span>'; |
|
| 278 | - $tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">'.$discount_price.'</span> '.$productCurrency; |
|
| 277 | + $discount_price = $exploded_discount_price[0] . '<span class="wpshop_price_centimes_display">,' . ((!empty($exploded_discount_price[1])) ? $exploded_discount_price[1] : '') . '</span>'; |
|
| 278 | + $tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">' . $discount_price . '</span> ' . $productCurrency; |
|
| 279 | 279 | |
| 280 | - $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_infos ); |
|
| 280 | + $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_infos); |
|
| 281 | 281 | } |
| 282 | 282 | else { |
| 283 | - $tpl_component['PRODUCT_PRICE'] = $price.' '.$productCurrency; |
|
| 283 | + $tpl_component['PRODUCT_PRICE'] = $price . ' ' . $productCurrency; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $post_type = get_post_type( $product['product_id'] ); |
|
| 287 | - if ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
|
| 288 | - $price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true ); |
|
| 286 | + $post_type = get_post_type($product['product_id']); |
|
| 287 | + if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 288 | + $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); |
|
| 289 | 289 | } |
| 290 | - elseif( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 291 | - $parent_def = wpshop_products::get_parent_variation ( $product['product_id'] ); |
|
| 292 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 290 | + elseif ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 291 | + $parent_def = wpshop_products::get_parent_variation($product['product_id']); |
|
| 292 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 293 | 293 | $parent_post = $parent_def['parent_post']; |
| 294 | - $price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true ); |
|
| 294 | + $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | - $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
|
| 298 | - $tpl_component['PRICE_FROM'] = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? 'on' : ''; |
|
| 297 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 298 | + $tpl_component['PRICE_FROM'] = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? 'on' : ''; |
|
| 299 | 299 | |
| 300 | 300 | return $tpl_component; |
| 301 | 301 | } |
| 302 | - else if ( $return_type == 'price_display' ) { |
|
| 302 | + else if ($return_type == 'price_display') { |
|
| 303 | 303 | $tpl_component = array(); |
| 304 | - $price = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 304 | + $price = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 305 | 305 | |
| 306 | 306 | $price_data = $price_infos; |
| 307 | 307 | |
| 308 | - $exploded_price = explode('.', number_format($price,2, '.', '')); |
|
| 309 | - $price = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>'; |
|
| 308 | + $exploded_price = explode('.', number_format($price, 2, '.', '')); |
|
| 309 | + $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>'; |
|
| 310 | 310 | |
| 311 | - $tpl_component['TAX_PILOTING'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 311 | + $tpl_component['TAX_PILOTING'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 312 | 312 | |
| 313 | 313 | $tpl_component['CROSSED_OUT_PRICE'] = ''; |
| 314 | 314 | $tpl_component['MESSAGE_SAVE_MONEY'] = ''; |
| 315 | 315 | |
| 316 | - if( !empty($price_infos['discount']['discount_exist']) ) { |
|
| 316 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 317 | 317 | $text_from = false; |
| 318 | 318 | /** Get variation defining **/ |
| 319 | - $post_type = get_post_type( $product['product_id'] ); |
|
| 320 | - if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 321 | - $parent_def = wpshop_products::get_parent_variation ( $product['product_id'] ); |
|
| 322 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 319 | + $post_type = get_post_type($product['product_id']); |
|
| 320 | + if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 321 | + $parent_def = wpshop_products::get_parent_variation($product['product_id']); |
|
| 322 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 323 | 323 | $parent_post = $parent_def['parent_post']; |
| 324 | - $price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true ); |
|
| 324 | + $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | else { |
| 328 | - $price_display_attribute = get_post_meta( $product['product_id'], '_wpshop_variation_defining', true ); |
|
| 328 | + $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true); |
|
| 329 | 329 | } |
| 330 | - $text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) && !empty($product['text_from']) ) ? true : false; |
|
| 330 | + $text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']))))) && !empty($product['text_from'])) ? true : false; |
|
| 331 | 331 | |
| 332 | 332 | |
| 333 | - $exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'],2, '.', '')); |
|
| 334 | - $price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>'; |
|
| 333 | + $exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', '')); |
|
| 334 | + $price_infos['discount']['discount_et_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>'; |
|
| 335 | 335 | |
| 336 | - $exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'],2, '.', '')); |
|
| 337 | - $price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">'.$exploded_price[0].'</span><span class="wpshop_price_centimes_display">.'.( (!empty($exploded_price[1]) ) ? $exploded_price[1] : '').'</span>'; |
|
| 336 | + $exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', '')); |
|
| 337 | + $price_infos['discount']['discount_ati_price'] = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . ((!empty($exploded_price[1])) ? $exploded_price[1] : '') . '</span>'; |
|
| 338 | 338 | |
| 339 | 339 | |
| 340 | - $crossed_out_price = ( (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2) ).' '. $productCurrency; |
|
| 341 | - $tpl_component['CROSSED_OUT_PRICE'] = str_replace( '.', ',', ( ( $text_from ) ? __('Price from', 'wpshop') . ' ' : '' ). wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price)) ); |
|
| 342 | - $tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">'. $price_infos['discount']['discount_et_price'].'</span> '.$productCurrency : '<span class="wps-absolute-price">'.$price_infos['discount']['discount_ati_price'].'</span> '.$productCurrency; |
|
| 343 | - $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money( $price_data ); |
|
| 340 | + $crossed_out_price = ((!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? number_format($price_infos['et'], 2) : number_format($price_infos['ati'], 2)) . ' ' . $productCurrency; |
|
| 341 | + $tpl_component['CROSSED_OUT_PRICE'] = str_replace('.', ',', (($text_from) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $crossed_out_price))); |
|
| 342 | + $tpl_component['PRODUCT_PRICE'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? '<span class="wps-absolute-price">' . $price_infos['discount']['discount_et_price'] . '</span> ' . $productCurrency : '<span class="wps-absolute-price">' . $price_infos['discount']['discount_ati_price'] . '</span> ' . $productCurrency; |
|
| 343 | + $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_data); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | else { |
| 347 | - if( get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 348 | - $parent_def = wpshop_products::get_parent_variation( $product['product_id'] ); |
|
| 347 | + if (get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 348 | + $parent_def = wpshop_products::get_parent_variation($product['product_id']); |
|
| 349 | 349 | $pid = $parent_def['parent_post']; |
| 350 | 350 | $pid = $pid->ID; |
| 351 | 351 | } |
@@ -355,35 +355,35 @@ discard block |
||
| 355 | 355 | |
| 356 | 356 | $text_from = false; |
| 357 | 357 | /** Get variation defining **/ |
| 358 | - $post_type = get_post_type( $pid ); |
|
| 359 | - if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 360 | - $parent_def = wpshop_products::get_parent_variation ( $pid ); |
|
| 361 | - if( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 358 | + $post_type = get_post_type($pid); |
|
| 359 | + if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 360 | + $parent_def = wpshop_products::get_parent_variation($pid); |
|
| 361 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 362 | 362 | $parent_post = $parent_def['parent_post']; |
| 363 | - $price_display_attribute = get_post_meta( $parent_post->ID, '_wpshop_variation_defining', true ); |
|
| 363 | + $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | else { |
| 367 | - $price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true ); |
|
| 367 | + $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $price_display_attribute = get_post_meta( $pid, '_wpshop_variation_defining', true ); |
|
| 370 | + $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true); |
|
| 371 | 371 | |
| 372 | - $text_from = ( ( !empty($price_display_attribute) && empty($price_display_attribute['options'] ) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) || ( ( !empty($price_display_attribute) && (!empty($price_display_attribute['options'] ) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from']) ) ) ) ) ) ? true : false; |
|
| 372 | + $text_from = ((!empty($price_display_attribute) && empty($price_display_attribute['options']) && !empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) || ((!empty($price_display_attribute) && (!empty($price_display_attribute['options']) && (!empty($price_display_attribute['options']['price_display']) && !empty($price_display_attribute['options']['price_display']['text_from'])))))) ? true : false; |
|
| 373 | 373 | |
| 374 | - $tpl_component['PRODUCT_PRICE'] = ( $text_from && !empty($product['text_from']) ) ? __('Price from', 'wpshop') . ' ' : ''; |
|
| 375 | - $tpl_component['PRODUCT_PRICE'] .= $price.' '.$productCurrency; |
|
| 374 | + $tpl_component['PRODUCT_PRICE'] = ($text_from && !empty($product['text_from'])) ? __('Price from', 'wpshop') . ' ' : ''; |
|
| 375 | + $tpl_component['PRODUCT_PRICE'] .= $price . ' ' . $productCurrency; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
| 379 | 379 | // Replace . by , |
| 380 | - $tpl_component['PRODUCT_PRICE'] = str_replace( '.',',', $tpl_component['PRODUCT_PRICE'] ); |
|
| 380 | + $tpl_component['PRODUCT_PRICE'] = str_replace('.', ',', $tpl_component['PRODUCT_PRICE']); |
|
| 381 | 381 | |
| 382 | - if ( $output_type == 'complete_sheet' ) { |
|
| 383 | - $price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component ); |
|
| 382 | + if ($output_type == 'complete_sheet') { |
|
| 383 | + $price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component); |
|
| 384 | 384 | } |
| 385 | - elseif ( $output_type == 'mini_output' || in_array('mini_output', $output_type ) ) { |
|
| 386 | - $price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component ); |
|
| 385 | + elseif ($output_type == 'mini_output' || in_array('mini_output', $output_type)) { |
|
| 386 | + $price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component); |
|
| 387 | 387 | } |
| 388 | 388 | return $price_tpl; |
| 389 | 389 | } |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @return stdClass ( value, id ) L'id de l'attribut et le taux de TVA / |
| 404 | 404 | * Attribute ID and the VAT rate |
| 405 | 405 | */ |
| 406 | - public static function get_rate_vat( $product_id ) { |
|
| 406 | + public static function get_rate_vat($product_id) { |
|
| 407 | 407 | global $wpdb; |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -417,18 +417,18 @@ discard block |
||
| 417 | 417 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " as ATTR_VAL_INT ON ( ATTR_VAL_INT.attribute_id = ATTR.id AND ATTR_VAL_OPTIONS.id=ATTR_VAL_INT.value ) |
| 418 | 418 | WHERE ATTR.code=%s AND ATTR_VAL_INT.entity_id=%d"; |
| 419 | 419 | |
| 420 | - $request = $wpdb->prepare( $query, array( 'tx_tva', $product_id ) ); |
|
| 421 | - $rate_vat = $wpdb->get_row( $request ); |
|
| 420 | + $request = $wpdb->prepare($query, array('tx_tva', $product_id)); |
|
| 421 | + $rate_vat = $wpdb->get_row($request); |
|
| 422 | 422 | |
| 423 | 423 | /** |
| 424 | 424 | * Vérifie ensuite si elle est vide, si elle est vide met la valeur par |
| 425 | 425 | * défaut / Then checks if it is empty , if empty the value put the |
| 426 | 426 | * default value |
| 427 | 427 | */ |
| 428 | - if( empty( $rate_vat ) ) { |
|
| 429 | - wpeologs_ctr::log_datas_in_files( 'wps_product', array( |
|
| 428 | + if (empty($rate_vat)) { |
|
| 429 | + wpeologs_ctr::log_datas_in_files('wps_product', array( |
|
| 430 | 430 | 'object_id' => $product_id, |
| 431 | - 'message' => __( 'Use the default VAT rate', 'wpshop' ) ), 0 |
|
| 431 | + 'message' => __('Use the default VAT rate', 'wpshop') ), 0 |
|
| 432 | 432 | ); |
| 433 | 433 | |
| 434 | 434 | $query = " |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " as ATTR_VAL_OPTIONS ON ATTR_VAL_OPTIONS.attribute_id = ATTR.id |
| 438 | 438 | WHERE ATTR.code=%s AND ATTR_VAL_OPTIONS.id=ATTR.default_value"; |
| 439 | 439 | |
| 440 | - $request = $wpdb->prepare( $query, array( 'tx_tva' ) ); |
|
| 441 | - $rate_vat = $wpdb->get_row( $request ); |
|
| 440 | + $request = $wpdb->prepare($query, array('tx_tva')); |
|
| 441 | + $rate_vat = $wpdb->get_row($request); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -446,10 +446,10 @@ discard block |
||
| 446 | 446 | * dans ce cas la on utilise le log / If it is still empty , it means that no |
| 447 | 447 | * VAT rate found in this case the log is used |
| 448 | 448 | */ |
| 449 | - if( empty( $rate_vat ) ) { |
|
| 450 | - wpeologs_ctr::log_datas_in_files( 'wps_product', array( |
|
| 449 | + if (empty($rate_vat)) { |
|
| 450 | + wpeologs_ctr::log_datas_in_files('wps_product', array( |
|
| 451 | 451 | 'object_id' => $product_id, |
| 452 | - 'message' => __( 'No VAT rate in the product and no default VAT rate found', 'wpshop' ) ), 2 |
|
| 452 | + 'message' => __('No VAT rate in the product and no default VAT rate found', 'wpshop') ), 2 |
|
| 453 | 453 | ); |
| 454 | 454 | } |
| 455 | 455 | |
@@ -459,19 +459,19 @@ discard block |
||
| 459 | 459 | /** |
| 460 | 460 | * Check if isset Required attributes |
| 461 | 461 | */ |
| 462 | - public static function check_required_attributes( $product_id ) { |
|
| 462 | + public static function check_required_attributes($product_id) { |
|
| 463 | 463 | $required_attributes_list = array(); |
| 464 | - $variation_option = get_post_meta( $product_id, '_wpshop_variation_defining', true); |
|
| 465 | - if ( !empty($variation_option) && !empty($variation_option['attributes']) ) { |
|
| 466 | - if( !empty($variation_option['options']) && !empty($variation_option['options']['required_attributes']) ) { |
|
| 467 | - foreach( $variation_option['options']['required_attributes'] as $required_attribute ) { |
|
| 468 | - $required_attributes_list[ $required_attribute ] = $required_attribute; |
|
| 464 | + $variation_option = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 465 | + if (!empty($variation_option) && !empty($variation_option['attributes'])) { |
|
| 466 | + if (!empty($variation_option['options']) && !empty($variation_option['options']['required_attributes'])) { |
|
| 467 | + foreach ($variation_option['options']['required_attributes'] as $required_attribute) { |
|
| 468 | + $required_attributes_list[$required_attribute] = $required_attribute; |
|
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | /** Check the attribute configuration **/ |
| 472 | - foreach ( $variation_option['attributes'] as $variation ) { |
|
| 473 | - $attribute_def = wpshop_attributes::getElement( $variation, '"valid"', 'code' ); |
|
| 474 | - if ( is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes' ) { |
|
| 472 | + foreach ($variation_option['attributes'] as $variation) { |
|
| 473 | + $attribute_def = wpshop_attributes::getElement($variation, '"valid"', 'code'); |
|
| 474 | + if (is_object($attribute_def) && !empty($attribute_def->is_required) && $attribute_def->is_required == 'yes') { |
|
| 475 | 475 | $required_attributes_list[$attribute_def->code] = $attribute_def->code; |
| 476 | 476 | } |
| 477 | 477 | } |
@@ -483,60 +483,60 @@ discard block |
||
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** Check the Product lower price **/ |
| 486 | - public static function check_product_lower_price ( $product_id ) { |
|
| 486 | + public static function check_product_lower_price($product_id) { |
|
| 487 | 487 | global $wpdb; |
| 488 | - $price_piloting_option = get_option( 'wpshop_shop_price_piloting' ); |
|
| 488 | + $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 489 | 489 | $lower_price_product = $min_price = 0; |
| 490 | - $variations = wpshop_products::get_variation( $product_id, 'publish' ); |
|
| 490 | + $variations = wpshop_products::get_variation($product_id, 'publish'); |
|
| 491 | 491 | $single_variations = $lower_price_product_combinaison = array(); |
| 492 | 492 | $first = true; |
| 493 | 493 | |
| 494 | 494 | /** Check variations type **/ |
| 495 | - $query = $wpdb->prepare( 'SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' .$wpdb->postmeta .' AS m INNER JOIN ' .$wpdb->posts. ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def' ); |
|
| 496 | - $variation_type = $wpdb->get_results( $query ); |
|
| 495 | + $query = $wpdb->prepare('SELECT DISTINCT( SUBSTRING( m.meta_value, 3,1 ) ) AS attributes_count FROM ' . $wpdb->postmeta . ' AS m INNER JOIN ' . $wpdb->posts . ' AS P ON ((P.ID = m.post_id) AND (P.post_parent = %d)) WHERE meta_key LIKE %s', $product_id, '_wpshop_variations_attribute_def'); |
|
| 496 | + $variation_type = $wpdb->get_results($query); |
|
| 497 | 497 | |
| 498 | 498 | |
| 499 | 499 | /** Check which type of variation contains the product **/ |
| 500 | 500 | $contains_simple_variation = false; |
| 501 | - if ( !empty($variation_type) ) { |
|
| 502 | - foreach( $variation_type as $k => $value ) { |
|
| 503 | - if( $value->attributes_count == '1' ) { |
|
| 501 | + if (!empty($variation_type)) { |
|
| 502 | + foreach ($variation_type as $k => $value) { |
|
| 503 | + if ($value->attributes_count == '1') { |
|
| 504 | 504 | $contains_simple_variation = true; |
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( $contains_simple_variation ) { |
|
| 509 | + if ($contains_simple_variation) { |
|
| 510 | 510 | |
| 511 | - if( !empty($variations) ) { |
|
| 512 | - $attributes = get_post_meta( $product_id, '_wpshop_variation_defining', true); |
|
| 513 | - if ( !empty($attributes) && !empty($attributes['attributes']) ) { |
|
| 511 | + if (!empty($variations)) { |
|
| 512 | + $attributes = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 513 | + if (!empty($attributes) && !empty($attributes['attributes'])) { |
|
| 514 | 514 | /** Construct an array with all cheaper attributes **/ |
| 515 | - foreach( $attributes['attributes'] as $key=>$attribute ) { |
|
| 515 | + foreach ($attributes['attributes'] as $key=>$attribute) { |
|
| 516 | 516 | $min_price = 0; |
| 517 | 517 | $first = true; |
| 518 | - foreach( $variations as $k => $variation) { |
|
| 519 | - if ( !empty($variation['variation_def']) && count($variation['variation_def']) == 1 ) { |
|
| 520 | - if( array_key_exists($attribute, $variation['variation_def'] ) ) { |
|
| 521 | - $variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation['variation_dif']['price_ht'] : !empty( $variation['variation_dif']['product_price'] ) ? $variation['variation_dif']['product_price'] : 0; |
|
| 518 | + foreach ($variations as $k => $variation) { |
|
| 519 | + if (!empty($variation['variation_def']) && count($variation['variation_def']) == 1) { |
|
| 520 | + if (array_key_exists($attribute, $variation['variation_def'])) { |
|
| 521 | + $variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation['variation_dif']['price_ht'] : !empty($variation['variation_dif']['product_price']) ? $variation['variation_dif']['product_price'] : 0; |
|
| 522 | 522 | |
| 523 | 523 | /** Check Discount **/ |
| 524 | - $variation_price = ( !empty( $variation['variation_dif']['special_price'] ) && $variation['variation_dif']['special_price'] > 0 ) ? $variation['variation_dif']['special_price'] : $variation_price; |
|
| 525 | - if( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) { |
|
| 526 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] ); |
|
| 527 | - $tx_tva = $wpdb->get_var( $query ); |
|
| 528 | - $variation_price = $variation['variation_dif']['price_ht'] / ( 1 + ($variation['variation_dif']['discount_rate'] / 100 ) ); |
|
| 529 | - $variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100); |
|
| 524 | + $variation_price = (!empty($variation['variation_dif']['special_price']) && $variation['variation_dif']['special_price'] > 0) ? $variation['variation_dif']['special_price'] : $variation_price; |
|
| 525 | + if (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_rate']) && $variation['variation_dif']['discount_rate'] > 0) { |
|
| 526 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']); |
|
| 527 | + $tx_tva = $wpdb->get_var($query); |
|
| 528 | + $variation_price = $variation['variation_dif']['price_ht'] / (1 + ($variation['variation_dif']['discount_rate'] / 100)); |
|
| 529 | + $variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100); |
|
| 530 | 530 | } |
| 531 | - elseif( empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0 ) { |
|
| 532 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $variation['variation_dif']['tx_tva'] ); |
|
| 533 | - $tx_tva = $wpdb->get_var( $query ); |
|
| 534 | - $variation_price = $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount']; |
|
| 535 | - $variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? $variation_price : $variation_price * 1 + ($tx_tva / 100); |
|
| 531 | + elseif (empty($variation['variation_dif']['special_price']) && !empty($variation['variation_dif']['discount_amount']) && $variation['variation_dif']['discount_amount'] > 0) { |
|
| 532 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $variation['variation_dif']['tx_tva']); |
|
| 533 | + $tx_tva = $wpdb->get_var($query); |
|
| 534 | + $variation_price = $variation['variation_dif']['price_ht'] - $variation['variation_dif']['discount_amount']; |
|
| 535 | + $variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $variation_price : $variation_price * 1 + ($tx_tva / 100); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** Check the Min-price **/ |
| 539 | - if( $first|| $min_price >= $variation_price ) { |
|
| 539 | + if ($first || $min_price >= $variation_price) { |
|
| 540 | 540 | $first = false; |
| 541 | 541 | $min_price = $variation_price; |
| 542 | 542 | $lower_price_product_combinaison['variations'][$attribute] = $k; |
@@ -550,22 +550,22 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | else { |
| 553 | - if ( !empty($product_id) ) { |
|
| 554 | - if( !empty($variations) ) { |
|
| 553 | + if (!empty($product_id)) { |
|
| 554 | + if (!empty($variations)) { |
|
| 555 | 555 | |
| 556 | - foreach( $variations as $variation_id => $variation) { |
|
| 557 | - if ( !empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) { |
|
| 558 | - $variation_price = ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) ? ( ( !empty($variation['variation_dif']['price_ht']) ) ? $variation['variation_dif']['price_ht'] : 0) : ( ( !empty($variation['variation_dif']['product_price']) ) ? $variation['variation_dif']['product_price'] : 0); |
|
| 556 | + foreach ($variations as $variation_id => $variation) { |
|
| 557 | + if (!empty($variation['variation_dif']) && !empty($variation['variation_def']) && count($variation['variation_def']) > 1) { |
|
| 558 | + $variation_price = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) : ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0); |
|
| 559 | 559 | /** Check the Min-price **/ |
| 560 | - if( $min_price >= $variation_price || $first ) { |
|
| 560 | + if ($min_price >= $variation_price || $first) { |
|
| 561 | 561 | $min_price = $variation_price; |
| 562 | 562 | $var_id = $variation_id; |
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | - $first = false; |
|
| 565 | + $first = false; |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - if ( !empty($var_id) ) { |
|
| 568 | + if (!empty($var_id)) { |
|
| 569 | 569 | $lower_price_product_combinaison['variations'][] = $var_id; |
| 570 | 570 | $lower_price_product_combinaison['variation_priority'] = 'combined'; |
| 571 | 571 | } |
@@ -581,25 +581,25 @@ discard block |
||
| 581 | 581 | * @param array $discount_config |
| 582 | 582 | * @return array |
| 583 | 583 | */ |
| 584 | - public static function calcul_discounted_price( $product, $discount_config ) { |
|
| 585 | - $wpshop_price_piloting_option = get_option( 'wpshop_shop_price_piloting'); |
|
| 586 | - if( !empty($discount_config) ) { |
|
| 584 | + public static function calcul_discounted_price($product, $discount_config) { |
|
| 585 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 586 | + if (!empty($discount_config)) { |
|
| 587 | 587 | |
| 588 | - if ( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price' ) { |
|
| 589 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] /100); |
|
| 590 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] /100) : $discount_config['value']; |
|
| 588 | + if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') { |
|
| 589 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100); |
|
| 590 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value']; |
|
| 591 | 591 | $product['tva'] = $product['product_price'] - $product['price_ht']; |
| 592 | 592 | } |
| 593 | - elseif( !empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount' ) { |
|
| 594 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] - $discount_config['value'] ) : ( ( $product['product_price'] - $discount_config['value'] ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 595 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * (1 + $product['tx_tva'] /100) : $product['product_price'] - $discount_config['value']; |
|
| 596 | - $product['tva'] = $product['product_price'] - $product['price_ht']; |
|
| 593 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') { |
|
| 594 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] - $discount_config['value']) : (($product['product_price'] - $discount_config['value']) / (1 + $product['tx_tva'] / 100)); |
|
| 595 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] - $discount_config['value']; |
|
| 596 | + $product['tva'] = $product['product_price'] - $product['price_ht']; |
|
| 597 | 597 | |
| 598 | 598 | } |
| 599 | - elseif(!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 600 | - $product['price_ht'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? ( $product['price_ht'] * ( 1 - $discount_config['value'] / 100) ) : ( ( $product['product_price'] * ( 1 - ( $discount_config['value'] / 100 ) ) ) / (1 + $product['tx_tva'] /100) ) ; |
|
| 601 | - $product['product_price'] = ( !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ) ? $product['price_ht'] * ( 1 + $product['tx_tva'] /100) : $product['product_price'] * ( 1 - ( $discount_config['value'] / 100 ) ); |
|
| 602 | - $product['tva'] = $product['product_price'] - $product['price_ht']; |
|
| 599 | + elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') { |
|
| 600 | + $product['price_ht'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? ($product['price_ht'] * (1 - $discount_config['value'] / 100)) : (($product['product_price'] * (1 - ($discount_config['value'] / 100))) / (1 + $product['tx_tva'] / 100)); |
|
| 601 | + $product['product_price'] = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $product['price_ht'] * (1 + $product['tx_tva'] / 100) : $product['product_price'] * (1 - ($discount_config['value'] / 100)); |
|
| 602 | + $product['tva'] = $product['product_price'] - $product['price_ht']; |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | return $product; |
@@ -607,39 +607,39 @@ discard block |
||
| 607 | 607 | |
| 608 | 608 | |
| 609 | 609 | /** Check Discount for Product **/ |
| 610 | - public static function check_discount_for_product( $product_id, $head_product_id = 0 ) { |
|
| 610 | + public static function check_discount_for_product($product_id, $head_product_id = 0) { |
|
| 611 | 611 | $discount_config = array(); |
| 612 | 612 | $time_def = array('0000-00-00 00:00:00', '0000-00-00'); |
| 613 | 613 | |
| 614 | - if( !empty($product_id) ) { |
|
| 615 | - if ( !empty($head_product_id) ) { |
|
| 616 | - $product_meta = get_post_meta( $head_product_id, '_wpshop_product_metadata', true ); |
|
| 617 | - $product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0; |
|
| 618 | - $product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0; |
|
| 614 | + if (!empty($product_id)) { |
|
| 615 | + if (!empty($head_product_id)) { |
|
| 616 | + $product_meta = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 617 | + $product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0; |
|
| 618 | + $product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0; |
|
| 619 | 619 | |
| 620 | - $product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true ); |
|
| 620 | + $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 621 | 621 | } |
| 622 | 622 | else { |
| 623 | - $product_meta = get_post_meta( $product_id, '_wpshop_product_metadata', true ); |
|
| 624 | - $product_discount_date_from = ( !empty($product_meta['special_from']) ) ? $product_meta['special_from'] : 0; |
|
| 625 | - $product_discount_date_to = ( !empty($product_meta['special_to']) ) ? $product_meta['special_to'] : 0; |
|
| 623 | + $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true); |
|
| 624 | + $product_discount_date_from = (!empty($product_meta['special_from'])) ? $product_meta['special_from'] : 0; |
|
| 625 | + $product_discount_date_to = (!empty($product_meta['special_to'])) ? $product_meta['special_to'] : 0; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | $current_date = date('Y-m-d'); |
| 629 | 629 | |
| 630 | - if ( !empty( $product_meta ) ) { |
|
| 630 | + if (!empty($product_meta)) { |
|
| 631 | 631 | |
| 632 | - if( ( empty($product_discount_date_from) && empty($product_discount_date_to) ) || ( in_array($product_discount_date_from, $time_def) && in_array( $product_discount_date_to, $time_def) ) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to) ) ) { |
|
| 632 | + if ((empty($product_discount_date_from) && empty($product_discount_date_to)) || (in_array($product_discount_date_from, $time_def) && in_array($product_discount_date_to, $time_def)) || (strtotime($product_discount_date_from) < strtotime($current_date) && strtotime($current_date) < strtotime($product_discount_date_to))) { |
|
| 633 | 633 | /** Special Price **/ |
| 634 | - if ( !empty($product_meta['special_price']) && $product_meta['special_price'] > 0 ) { |
|
| 634 | + if (!empty($product_meta['special_price']) && $product_meta['special_price'] > 0) { |
|
| 635 | 635 | $discount_config['type'] = 'special_price'; |
| 636 | 636 | $discount_config['value'] = $product_meta['special_price']; |
| 637 | 637 | } |
| 638 | - elseif( !empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) { |
|
| 638 | + elseif (!empty($product_meta['discount_amount']) && $product_meta['discount_amount'] > 0) { |
|
| 639 | 639 | $discount_config['type'] = 'discount_amount'; |
| 640 | 640 | $discount_config['value'] = $product_meta['discount_amount']; |
| 641 | 641 | } |
| 642 | - elseif( !empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0 ) { |
|
| 642 | + elseif (!empty($product_meta['discount_rate']) && $product_meta['discount_rate'] > 0) { |
|
| 643 | 643 | $discount_config['type'] = 'discount_rate'; |
| 644 | 644 | $discount_config['value'] = $product_meta['discount_rate']; |
| 645 | 645 | } |
@@ -652,13 +652,13 @@ discard block |
||
| 652 | 652 | /** |
| 653 | 653 | * Check the parent product price |
| 654 | 654 | */ |
| 655 | - function check_parent_product_price( $product ) { |
|
| 655 | + function check_parent_product_price($product) { |
|
| 656 | 656 | $price_infos = array(); |
| 657 | - if( !empty($product) ) { |
|
| 657 | + if (!empty($product)) { |
|
| 658 | 658 | $price_infos['ati'] = $product['product_price']; |
| 659 | 659 | $price_infos['et'] = $product['price_ht']; |
| 660 | 660 | $price_infos['tva'] = $product['tva']; |
| 661 | - $price_infos['fork_price'] = array( 'have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => ''); |
|
| 661 | + $price_infos['fork_price'] = array('have_fork_price' => false, 'min_product_price' => '', 'max_product_price' => ''); |
|
| 662 | 662 | } |
| 663 | 663 | return $price_infos; |
| 664 | 664 | } |
@@ -668,81 +668,81 @@ discard block |
||
| 668 | 668 | global $wpdb; |
| 669 | 669 | $status = false; $result = ''; |
| 670 | 670 | @ini_set('max_execution_time', '500'); |
| 671 | - $price_piloting_option = get_option( 'wpshop_shop_price_piloting' ); |
|
| 672 | - $output_type_option = get_option( 'wpshop_display_option' ); |
|
| 671 | + $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 672 | + $output_type_option = get_option('wpshop_display_option'); |
|
| 673 | 673 | $output_type = $output_type_option['wpshop_display_list_type']; |
| 674 | 674 | |
| 675 | 675 | /** Get tx_tva attribute_id **/ |
| 676 | - $query = $wpdb->prepare( 'SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE code = %s', 'tx_tva' ); |
|
| 677 | - $tx_tva_attribute_id = $wpdb->get_var( $query ); |
|
| 676 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'tx_tva'); |
|
| 677 | + $tx_tva_attribute_id = $wpdb->get_var($query); |
|
| 678 | 678 | |
| 679 | 679 | /** Product entity Definition **/ |
| 680 | - $product_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 680 | + $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 681 | 681 | |
| 682 | 682 | /** Attributes def **/ |
| 683 | - $tva_attribute_def = wpshop_attributes::getElement('tva',"'valid'", 'code'); |
|
| 684 | - $product_price_attribute_def = wpshop_attributes::getElement('product_price',"'valid'", 'code'); |
|
| 685 | - $price_ht_attribute_def = wpshop_attributes::getElement('price_ht',"'valid'", 'code'); |
|
| 683 | + $tva_attribute_def = wpshop_attributes::getElement('tva', "'valid'", 'code'); |
|
| 684 | + $product_price_attribute_def = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 685 | + $price_ht_attribute_def = wpshop_attributes::getElement('price_ht', "'valid'", 'code'); |
|
| 686 | 686 | |
| 687 | - if ( !empty($tx_tva_attribute_id) ) { |
|
| 688 | - $query = $wpdb->prepare( 'SELECT id, value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid' ); |
|
| 689 | - $tx_tva = $wpdb->get_results( $query ); |
|
| 687 | + if (!empty($tx_tva_attribute_id)) { |
|
| 688 | + $query = $wpdb->prepare('SELECT id, value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid'); |
|
| 689 | + $tx_tva = $wpdb->get_results($query); |
|
| 690 | 690 | |
| 691 | 691 | $tva_array = array(); |
| 692 | 692 | /** Transform array to easy teatment **/ |
| 693 | - foreach( $tx_tva as $t ) { |
|
| 694 | - $tva_array[ $t->id ] = $t->value; |
|
| 693 | + foreach ($tx_tva as $t) { |
|
| 694 | + $tva_array[$t->id] = $t->value; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - if ( !empty($tx_tva) ) { |
|
| 697 | + if (!empty($tx_tva)) { |
|
| 698 | 698 | |
| 699 | 699 | $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
| 700 | 700 | |
| 701 | - for( $i = 0; $i <= $count_products->publish; $i+= 100 ) { |
|
| 702 | - $query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish' ); |
|
| 703 | - $products = $wpdb->get_results( $query ); |
|
| 701 | + for ($i = 0; $i <= $count_products->publish; $i += 100) { |
|
| 702 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
|
| 703 | + $products = $wpdb->get_results($query); |
|
| 704 | 704 | |
| 705 | - if( !empty($products) ){ |
|
| 706 | - foreach( $products as $product ) { |
|
| 707 | - $product_data = get_post_meta( $product->ID, '_wpshop_product_metadata', true); |
|
| 708 | - if ( !empty($product_data) ) { |
|
| 709 | - if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) { |
|
| 705 | + if (!empty($products)) { |
|
| 706 | + foreach ($products as $product) { |
|
| 707 | + $product_data = get_post_meta($product->ID, '_wpshop_product_metadata', true); |
|
| 708 | + if (!empty($product_data)) { |
|
| 709 | + if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) { |
|
| 710 | 710 | |
| 711 | - if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) { |
|
| 711 | + if (!empty($price_piloting_option) && $price_piloting_option == 'HT') { |
|
| 712 | 712 | /** Update post meta **/ |
| 713 | - $product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] ); |
|
| 714 | - $product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 715 | - $product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 716 | - update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data); |
|
| 713 | + $product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']); |
|
| 714 | + $product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100)); |
|
| 715 | + $product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100)); |
|
| 716 | + update_post_meta($product->ID, '_wpshop_product_metadata', $product_data); |
|
| 717 | 717 | |
| 718 | 718 | |
| 719 | 719 | /** Update attributes values **/ |
| 720 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 721 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 722 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 720 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 721 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 722 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (float)$product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 723 | 723 | |
| 724 | 724 | /** Update Display price meta **/ |
| 725 | 725 | $p = wpshop_products::get_product_data($product->ID); |
| 726 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) ); |
|
| 727 | - update_post_meta( $product->ID, '_wps_price_infos', $price ); |
|
| 726 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 727 | + update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 728 | 728 | } |
| 729 | 729 | else { |
| 730 | 730 | /** Update post meta **/ |
| 731 | - $product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] ); |
|
| 732 | - $product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 733 | - $product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 734 | - update_post_meta( $product->ID, '_wpshop_product_metadata', $product_data); |
|
| 731 | + $product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']); |
|
| 732 | + $product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100)); |
|
| 733 | + $product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100)); |
|
| 734 | + update_post_meta($product->ID, '_wpshop_product_metadata', $product_data); |
|
| 735 | 735 | |
| 736 | 736 | /** Update attributes values **/ |
| 737 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 738 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 739 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID) ); |
|
| 737 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 738 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 739 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID)); |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | 742 | /** Update Display price meta **/ |
| 743 | 743 | $p = wpshop_products::get_product_data($product->ID); |
| 744 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type) ); |
|
| 745 | - update_post_meta( $product->ID, '_wps_price_infos', $price ); |
|
| 744 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 745 | + update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 746 | 746 | } |
| 747 | 747 | } |
| 748 | 748 | } |
@@ -750,41 +750,41 @@ discard block |
||
| 750 | 750 | |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | - unset( $products ); |
|
| 753 | + unset($products); |
|
| 754 | 754 | |
| 755 | 755 | $count_variations = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION); |
| 756 | - for( $i = 0; $i <= $count_variations->publish; $i+= 100 ) { |
|
| 757 | - $query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish' ); |
|
| 758 | - $product_variations = $wpdb->get_results( $query ); |
|
| 756 | + for ($i = 0; $i <= $count_variations->publish; $i += 100) { |
|
| 757 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish'); |
|
| 758 | + $product_variations = $wpdb->get_results($query); |
|
| 759 | 759 | /** Update Products Variations **/ |
| 760 | - if ( !empty($product_variations) ) { |
|
| 761 | - foreach( $product_variations as $product_variation ) { |
|
| 762 | - $product_data = get_post_meta( $product_variation->ID, '_wpshop_product_metadata', true); |
|
| 763 | - if ( !empty($product_data) ) { |
|
| 764 | - if ( !empty($product_data['tx_tva']) && array_key_exists( $product_data['tx_tva'], $tva_array) ) { |
|
| 765 | - if ( !empty($price_piloting_option) && $price_piloting_option == 'HT' ) { |
|
| 760 | + if (!empty($product_variations)) { |
|
| 761 | + foreach ($product_variations as $product_variation) { |
|
| 762 | + $product_data = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true); |
|
| 763 | + if (!empty($product_data)) { |
|
| 764 | + if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) { |
|
| 765 | + if (!empty($price_piloting_option) && $price_piloting_option == 'HT') { |
|
| 766 | 766 | /** Update post meta **/ |
| 767 | - $product_data['price_ht'] = (float)str_replace( ',', '.', $product_data['price_ht'] ); |
|
| 768 | - $product_data['product_price'] = $product_data['price_ht'] * ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 769 | - $product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 770 | - update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data); |
|
| 767 | + $product_data['price_ht'] = (float)str_replace(',', '.', $product_data['price_ht']); |
|
| 768 | + $product_data['product_price'] = $product_data['price_ht'] * (1 + ($tva_array[$product_data['tx_tva']] / 100)); |
|
| 769 | + $product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100)); |
|
| 770 | + update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data); |
|
| 771 | 771 | |
| 772 | 772 | /** Update attributes values **/ |
| 773 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 774 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 775 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 773 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 774 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 775 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 776 | 776 | } |
| 777 | 777 | else { |
| 778 | 778 | /** Update post meta **/ |
| 779 | - $product_data['product_price'] = (float)str_replace( ',', '.', $product_data['product_price'] ); |
|
| 780 | - $product_data['price_ht'] = $product_data['product_price'] / ( 1 + ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 781 | - $product_data['tva'] = $product_data['price_ht'] * ( ($tva_array[ $product_data['tx_tva'] ] / 100) ); |
|
| 782 | - update_post_meta( $product_variation->ID, '_wpshop_product_metadata', $product_data); |
|
| 779 | + $product_data['product_price'] = (float)str_replace(',', '.', $product_data['product_price']); |
|
| 780 | + $product_data['price_ht'] = $product_data['product_price'] / (1 + ($tva_array[$product_data['tx_tva']] / 100)); |
|
| 781 | + $product_data['tva'] = $product_data['price_ht'] * (($tva_array[$product_data['tx_tva']] / 100)); |
|
| 782 | + update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data); |
|
| 783 | 783 | |
| 784 | 784 | /** Update attributes values **/ |
| 785 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 786 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 787 | - $wpdb->update( WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price'] ), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID) ); |
|
| 785 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 786 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 787 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID)); |
|
| 788 | 788 | } |
| 789 | 789 | } |
| 790 | 790 | } |
@@ -801,15 +801,15 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | else { |
| 804 | - $result = __( 'VAT rate attribute was not found', 'wpshop' ); |
|
| 804 | + $result = __('VAT rate attribute was not found', 'wpshop'); |
|
| 805 | 805 | } |
| 806 | - return array( $status, $result ); |
|
| 806 | + return array($status, $result); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | } |
| 812 | 812 | /** Instanciate the module utilities if not */ |
| 813 | -if ( class_exists("wpshop_prices") ) { |
|
| 813 | +if (class_exists("wpshop_prices")) { |
|
| 814 | 814 | $wpshop_prices = new wpshop_prices(); |
| 815 | 815 | } |
@@ -184,20 +184,20 @@ discard block |
||
| 184 | 184 | public static function admin_menu() { |
| 185 | 185 | global $submenu; |
| 186 | 186 | $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
| 187 | - $entities_to_unset = array( 'free_product', 'default' ); |
|
| 187 | + $entities_to_unset = array('free_product', 'default'); |
|
| 188 | 188 | $submenu_before = $submenu['edit.php?post_type=wpshop_product']; |
| 189 | 189 | foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
| 190 | - if ( !( in_array( $attribute_set->slug, $entities_to_unset ) || in_array( $attribute_set->name, $entities_to_unset ) ) ) { |
|
| 191 | - add_submenu_page( 'edit.php?post_type=wpshop_product', sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product'); |
|
| 190 | + if (!(in_array($attribute_set->slug, $entities_to_unset) || in_array($attribute_set->name, $entities_to_unset))) { |
|
| 191 | + add_submenu_page('edit.php?post_type=wpshop_product', sprintf(__('Add %s', 'wpshop'), $attribute_set->name), sprintf(__('Add %s', 'wpshop'), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product'); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | - $submenu_new_elements = array_diff_key ( $submenu['edit.php?post_type=wpshop_product'], $submenu_before ); |
|
| 194 | + $submenu_new_elements = array_diff_key($submenu['edit.php?post_type=wpshop_product'], $submenu_before); |
|
| 195 | 195 | $submenu_reorder = array(); |
| 196 | - foreach( $submenu_before as $key => $element ) { |
|
| 197 | - if( empty( $submenu_reorder[$key] ) ) { |
|
| 196 | + foreach ($submenu_before as $key => $element) { |
|
| 197 | + if (empty($submenu_reorder[$key])) { |
|
| 198 | 198 | $submenu_reorder[$key] = $element; |
| 199 | - if( in_array( 'post-new.php?post_type=wpshop_product', $element ) ) { |
|
| 200 | - $submenu_reorder = array_merge( $submenu_reorder, array_values( $submenu_new_elements ) ); |
|
| 199 | + if (in_array('post-new.php?post_type=wpshop_product', $element)) { |
|
| 200 | + $submenu_reorder = array_merge($submenu_reorder, array_values($submenu_new_elements)); |
|
| 201 | 201 | } |
| 202 | 202 | } else { |
| 203 | 203 | $submenu_reorder[] = $element; |
@@ -604,12 +604,12 @@ discard block |
||
| 604 | 604 | |
| 605 | 605 | $products = array(); |
| 606 | 606 | $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
| 607 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 607 | + $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 608 | 608 | |
| 609 | 609 | if (!empty($data)) { |
| 610 | 610 | if ($data['data_type_to_use'] == 'custom') { |
| 611 | 611 | // Find which table to take |
| 612 | - if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;} |
|
| 612 | + if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME; } elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL; } elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER; } elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; } elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; } elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; } |
|
| 613 | 613 | |
| 614 | 614 | if (isset($table_name)) { |
| 615 | 615 | // If the value is an id of a select, radio or checkbox |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | if (!empty($atts['product_type'])) { |
| 760 | 760 | switch ($atts['product_type']) { |
| 761 | 761 | case 'related': |
| 762 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 762 | + $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID(); |
|
| 763 | 763 | $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
| 764 | 764 | $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE; |
| 765 | 765 | |
| 766 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 766 | + $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 767 | 767 | if (!empty($pids) && !empty($pids[0])) { |
| 768 | 768 | $pid = implode(',', $pids); |
| 769 | 769 | } |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | $sub_tpl_component = array(); |
| 833 | 833 | $criteria = ''; |
| 834 | 834 | foreach ($sorting_criteria as $c): |
| 835 | - $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 835 | + $criteria .= '<option value="' . $c['code'] . '" ' . selected($atts['order'], $c['code'], false) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 836 | 836 | endforeach; |
| 837 | 837 | $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
| 838 | 838 | $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | // --------------------- // |
| 1002 | 1002 | // Pagination management // |
| 1003 | 1003 | // --------------------- // |
| 1004 | - if ( $display_pagination ) { |
|
| 1004 | + if ($display_pagination) { |
|
| 1005 | 1005 | if ($nb_of_product_limit == 0) { |
| 1006 | 1006 | |
| 1007 | 1007 | $paginate = paginate_links(array( |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | { |
| 1283 | 1283 | global $wpdb; |
| 1284 | 1284 | |
| 1285 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1285 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST; |
|
| 1286 | 1286 | // Apply a filter to extra actions |
| 1287 | 1287 | $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
| 1288 | 1288 | |
@@ -1338,7 +1338,7 @@ discard block |
||
| 1338 | 1338 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1339 | 1339 | } |
| 1340 | 1340 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1341 | - $attributeValue = (int) $attributeValue; |
|
| 1341 | + $attributeValue = (int)$attributeValue; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | $productMetaDatas[$attributeCode] = $attributeValue; |
| 1344 | 1344 | } |
@@ -1388,7 +1388,7 @@ discard block |
||
| 1388 | 1388 | $attributeValue = str_replace(',', '.', $attribute->$value_key); |
| 1389 | 1389 | } |
| 1390 | 1390 | if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
| 1391 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1391 | + $attributeValue = (int)$attribute->$value_key; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | $variation_metadata[$attribute->code] = $attribute->$value_key; |
| 1394 | 1394 | } |
@@ -1401,7 +1401,7 @@ discard block |
||
| 1401 | 1401 | $attributeValue = str_replace(',', '.', $attributeValue); |
| 1402 | 1402 | } |
| 1403 | 1403 | if (($attributeType == 'integer') && !is_array($attributeValue)) { |
| 1404 | - $attributeValue = (int) $attributeValue; |
|
| 1404 | + $attributeValue = (int)$attributeValue; |
|
| 1405 | 1405 | } |
| 1406 | 1406 | $variation_metadata[$attributeCode] = $attributeValue; |
| 1407 | 1407 | } |
@@ -1737,13 +1737,13 @@ discard block |
||
| 1737 | 1737 | if (!empty($product_price_infos)) { |
| 1738 | 1738 | $tpl_component_price = array(); |
| 1739 | 1739 | /** Price piloting **/ |
| 1740 | - $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
|
| 1741 | - $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
|
| 1740 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1741 | + $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : ''; |
|
| 1742 | 1742 | $price_ploting = get_option('wpshop_shop_price_piloting'); |
| 1743 | 1743 | $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : ''; |
| 1744 | 1744 | $variations = wpshop_products::get_variation($product_id); |
| 1745 | 1745 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1746 | - if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
|
| 1746 | + if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) { |
|
| 1747 | 1747 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1748 | 1748 | } |
| 1749 | 1749 | $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
@@ -2186,7 +2186,7 @@ discard block |
||
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | 2188 | $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
| 2189 | - $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
|
| 2189 | + $template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id); |
|
| 2190 | 2190 | |
| 2191 | 2191 | $tpl_component = array(); |
| 2192 | 2192 | $tpl_component['PRODUCT_ID'] = $product_id; |
@@ -3149,7 +3149,7 @@ discard block |
||
| 3149 | 3149 | * Since 1.4.3.7 |
| 3150 | 3150 | * L'option du produit remplace le prix du produit de tête. |
| 3151 | 3151 | */ |
| 3152 | - if( true ) { |
|
| 3152 | + if (true) { |
|
| 3153 | 3153 | //Replace the product price |
| 3154 | 3154 | if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
| 3155 | 3155 | $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
@@ -3516,16 +3516,16 @@ discard block |
||
| 3516 | 3516 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3517 | 3517 | $variation_post_meta['options'] = $options; |
| 3518 | 3518 | $variation_post_meta['follow_general_config'] = true; |
| 3519 | - if( $variation_post_meta['follow_general_config'] ) { |
|
| 3519 | + if ($variation_post_meta['follow_general_config']) { |
|
| 3520 | 3520 | $shop_option = get_option('wpshop_catalog_product_option', array()); |
| 3521 | - if( isset( $shop_option ) ) { |
|
| 3521 | + if (isset($shop_option)) { |
|
| 3522 | 3522 | $variation_post_meta['options']['price_display'] = $shop_option['price_display']; |
| 3523 | 3523 | } |
| 3524 | 3524 | } |
| 3525 | 3525 | $variations = wpshop_attributes::get_variation_available_attribute($current_post_id); |
| 3526 | - if( !empty( $variations['available'] ) ) { |
|
| 3527 | - foreach( $variations['available'] as $key => $value ) { |
|
| 3528 | - if( !in_array( $value['attribute_complete_def']->code, $variation_post_meta['attributes'] ) ) { |
|
| 3526 | + if (!empty($variations['available'])) { |
|
| 3527 | + foreach ($variations['available'] as $key => $value) { |
|
| 3528 | + if (!in_array($value['attribute_complete_def']->code, $variation_post_meta['attributes'])) { |
|
| 3529 | 3529 | $variation_post_meta['attributes'][] = $value['attribute_complete_def']->code; |
| 3530 | 3530 | } |
| 3531 | 3531 | } |