コード例 #1
0
function ajax_wpshop_restart_the_order()
{
    global $wpshop_cart, $wpdb;
    $status = $add_to_cart_checking = $manage_stock_checking_bool = false;
    $add_to_cart_checking_message = '';
    $result = __('Error, you cannot restart this order', 'wpshop');
    $order_id = !empty($_POST['order_id']) ? wpshop_tools::varSanitizer($_POST['order_id']) : null;
    $is_make_order_again = !empty($_POST['make_order_again']) ? wpshop_tools::varSanitizer($_POST['make_order_again']) : null;
    if (!empty($order_id)) {
        $order_meta = get_post_meta($order_id, '_order_postmeta', true);
        $_SESSION['cart'] = array();
        $_SESSION['cart']['order_items'] = array();
        $wpshop_cart_type = $order_meta['cart_type'];
        if (!empty($order_meta) && !empty($order_meta['order_items'])) {
            $wpshop_cart_type = $order_meta['cart_type'];
            foreach ($order_meta['order_items'] as $item_key => $item) {
                $item_meta = get_post_meta($item['item_id'], '_wpshop_product_metadata', true);
                $stock = $item_meta['product_stock'];
                $qty = $item['item_qty'];
                $item_option = get_post_meta($item['item_id'], '_wpshop_product_options', true);
                if (!empty($item_meta['manage_stock'])) {
                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $item_meta['manage_stock']);
                    $manage_stock_checking = $wpdb->get_var($query);
                    if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
                        $manage_stock_checking_bool = true;
                    }
                } else {
                    if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                        $parent_product = wpshop_products::get_parent_variation($item['item_id']);
                        if (!empty($parent_product) && !empty($parent_product['parent_post_meta'])) {
                            $parent_metadata = $parent_product['parent_post_meta'];
                            if (!empty($parent_product['parent_post_meta']['manage_stock'])) {
                                $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_product['parent_post_meta']['manage_stock']);
                                $manage_stock_checking = $wpdb->get_var($query);
                                if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
                                    $manage_stock_checking_bool = true;
                                    $stock = $parent_product['parent_post_meta']['product_stock'];
                                }
                            }
                        }
                    }
                }
                /** Checking stock **/
                if (empty($item_meta['manage_stock']) || !empty($item_meta['manage_stock']) && !$manage_stock_checking_bool || !empty($item_meta['manage_stock']) && $manage_stock_checking_bool && $stock >= $qty) {
                    $_SESSION['cart']['order_items'][$item_key] = $item;
                } else {
                    $add_to_cart_checking = true;
                    $add_to_cart_checking_message = __('Some products cannot be added to cart because they are out of stock', 'wpshop');
                }
            }
            $wps_cart_ctr = new wps_cart();
            $order = $wps_cart_ctr->calcul_cart_information(array());
            $order['cart_type'] = $wpshop_cart_type;
            $wps_cart_ctr->store_cart_in_session($order);
        }
        if (empty($is_make_order_again)) {
            $_SESSION['order_id'] = $order_id;
        }
        $status = true;
        $result = get_permalink(get_option('wpshop_cart_page_id'));
    }
    $response = array('status' => $status, 'response' => $result, 'add_to_cart_checking' => $add_to_cart_checking, 'add_to_cart_checking_message' => $add_to_cart_checking_message);
    echo json_encode($response);
    die;
}
コード例 #2
0
 public static function process_checkout($paymentMethod = 'paypal', $order_id = 0, $customer_id = 0, $customer_billing_address_id = 0, $customer_shipping_address_id = 0)
 {
     global $wpdb, $wpshop, $wpshop_cart;
     $wps_message = new wps_message_ctr();
     $shipping_address_option = get_option('wpshop_shipping_address_choice');
     if (is_user_logged_in()) {
         $user_id = get_current_user_id();
         if ($customer_id != 0) {
             $user_id = $customer_id;
         }
         // If the order is already created in the db
         if (!empty($order_id) && is_numeric($order_id)) {
             $order = get_post_meta($order_id, '_order_postmeta', true);
             if (!empty($order)) {
                 if ($order['customer_id'] == $user_id) {
                     $order['payment_method'] = $paymentMethod;
                     $_SESSION['order_id'] = wpshop_tools::varSanitizer($order_id);
                     // Store cart in session
                     //wpshop_cart::store_cart_in_session($order);
                     // Add a payment
                     $order['order_payment']['received'][] = array('method' => $paymentMethod, 'waited_amount' => $order['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => get_current_user_id());
                     // On enregistre la commande
                     update_post_meta($order_id, '_order_postmeta', $order);
                     update_post_meta($order_id, '_wpshop_order_customer_id', $user_id);
                 } else {
                     $wpshop->add_error(__('You don\'t own the order', 'wpshop'));
                 }
             } else {
                 $wpshop->add_error(__('The order doesn\'t exist.', 'wpshop'));
             }
         } else {
             $order_data = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'post_title' => sprintf(__('Order - %s', 'wpshop'), mysql2date('d M Y\\, H:i:s', current_time('mysql', 0), true)), 'post_status' => 'publish', 'post_excerpt' => !empty($_POST['wps-customer-comment']) ? $_POST['wps-customer-comment'] : '', 'post_author' => $user_id, 'comment_status' => 'closed');
             // Cart items
             $order_items = array();
             $order_tva = array();
             //$cart = (array)$wpshop_cart->cart;
             if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['shipping_method'])) {
                 $_SESSION['cart']['shipping_method'] = __('Standard shipping method', 'wpshop');
             }
             $cart = (array) $_SESSION['cart'];
             $download_codes = array();
             // Nouvelle commande
             $order_id = wp_insert_post($order_data);
             $_SESSION['order_id'] = $order_id;
             // Cr�ation des codes de t�l�chargement si il y a des produits t�l�chargeable dans le panier
             if (!empty($cart['order_items'])) {
                 foreach ($cart['order_items'] as $c) {
                     $product = wpshop_products::get_product_data($c['item_id']);
                     /** Check if it's a variation and check the parent product **/
                     if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                         $parent_def = wpshop_products::get_parent_variation($c['item_id']);
                         if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) {
                             $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_'];
                         }
                     }
                     if (!empty($product['is_downloadable_'])) {
                         $download_codes[$c['item_id']] = array('item_id' => $c['item_id'], 'download_code' => uniqid('', true));
                     }
                 }
             }
             if (!empty($download_codes)) {
                 update_user_meta($user_id, '_order_download_codes_' . $order_id, $download_codes);
             }
             // Informations de commande � stocker
             $currency = wpshop_tools::wpshop_get_currency(true);
             $order = array_merge(array('order_key' => NULL, 'customer_id' => $user_id, 'order_status' => 'awaiting_payment', 'order_date' => current_time('mysql', 0), 'order_shipping_date' => null, 'order_invoice_ref' => '', 'order_currency' => $currency, 'order_payment' => array('customer_choice' => array('method' => $paymentMethod), 'received' => array('0' => array('method' => $paymentMethod, 'waited_amount' => $cart['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => $user_id)), 'shipping_method' => !empty($_SESSION['shipping_method']) ? wpshop_tools::varSanitizer($_SESSION['shipping_method']) : __('Standard shipping method', 'wpshop'))), $cart);
             // Si c'est un devis
             if ($paymentMethod == 'quotation') {
                 $order['order_temporary_key'] = wpshop_orders::get_new_pre_order_reference();
             } else {
                 $order['order_key'] = wpshop_orders::get_new_order_reference();
             }
             //Round final amount
             $order['order_grand_total'] = number_format(round($order['order_grand_total'], 2), 2, '.', '');
             $order['order_total_ttc'] = number_format(round($order['order_total_ttc'], 2), 2, '.', '');
             $order['order_amount_to_pay_now'] = number_format(round($order['order_amount_to_pay_now'], 2), 2, '.', '');
             /** On enregistre la commande	*/
             update_post_meta($order_id, '_order_postmeta', $order);
             update_post_meta($order_id, '_wpshop_order_customer_id', $order['customer_id']);
             update_post_meta($order_id, '_wpshop_order_shipping_date', $order['order_shipping_date']);
             update_post_meta($order_id, '_wpshop_order_status', $order['order_status']);
             do_action('wps_order_extra_save', $order_id);
             //Add an action to extra actions on order save
             $args = array('order_id' => $order_id, 'posted_data' => $_REQUEST);
             wpshop_tools::create_custom_hook('wps_order_extra_save_action', $args);
             /**	Set custmer information for the order	*/
             $shipping_address = !empty($shipping_address_option) && !empty($shipping_address_option['activate']) ? !empty($_SESSION['shipping_address']) ? wpshop_tools::varSanitizer($_SESSION['shipping_address']) : $customer_shipping_address_id : '';
             $billing_address = !empty($_SESSION['billing_address']) ? wpshop_tools::varSanitizer($_SESSION['billing_address']) : $customer_billing_address_id;
             if (!empty($billing_address)) {
                 wpshop_orders::set_order_customer_addresses($user_id, $order_id, $shipping_address, $billing_address);
             }
             if (!empty($_SESSION['shipping_address_to_save'])) {
                 $order_infos_postmeta = get_post_meta($order_id, '_order_info', true);
                 $order_infos_postmeta['shipping']['address'] = $_SESSION['shipping_address_to_save'];
                 $order_infos_postmeta['shipping']['address_id'] = '';
                 update_post_meta($order_id, '_order_info', $order_infos_postmeta);
                 unset($_SESSION['shipping_address_to_save']);
             }
             /** Save Coupon use **/
             if (!empty($_SESSION['cart']['coupon_id'])) {
                 $wps_coupon_mdl = new wps_coupon_model();
                 $wps_coupon_mdl->save_coupon_use($_SESSION['cart']['coupon_id']);
             }
             /**	Notify the customer as the case	*/
             $user_info = get_userdata($user_id);
             $email = $user_info->user_email;
             $first_name = $user_info->user_firstname;
             $last_name = $user_info->user_lastname;
             // Envoie du message de confirmation de commande au client
             $order_meta = get_post_meta($order_id, '_order_postmeta', true);
             $shipping_mode_option = get_option('wps_shipping_mode');
             $shipping_method = !empty($order_meta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_meta['order_payment']['shipping_method'], $shipping_mode_option['modes']) ? $shipping_mode_option['modes'][$order_meta['order_payment']['shipping_method']]['name'] : (!empty($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : '');
             if (!empty($order_meta) && !empty($order_meta['cart_type']) && $order_meta['cart_type'] == 'quotation' && empty($order_meta['order_key'])) {
                 $wps_message->wpshop_prepared_email($email, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_date' => current_time('mysql', 0), 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => ''));
             } else {
                 $email_option = get_option('wpshop_emails');
                 if (empty($email_option['send_confirmation_order_message'])) {
                     $payment_method_option = get_option('wps_payment_mode');
                     $order_payment_method = !empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_meta['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]) ? $payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]['name'] : $order_meta['order_payment']['customer_choice']['method'];
                     $wps_message->wpshop_prepared_email($email, 'WPSHOP_ORDER_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_key' => !empty($order_meta['order_key']) ? $order_meta['order_key'] : '', 'order_date' => current_time('mysql', 0), 'order_payment_method' => $order_payment_method, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => ''));
                 }
             }
             if (empty($_SESSION['wps-pos-addon'])) {
                 $email_option = get_option('wpshop_emails');
                 if (empty($email_option) || !empty($email_option) && empty($email_option['send_confirmation_order_message'])) {
                     self::send_order_email_to_administrator($order_id, $user_info);
                 }
             }
             /** IF Order amount is 0, Finish the Order **/
             if ($cart['order_amount_to_pay_now'] == 0) {
                 $order_meta = get_post_meta($order_id, '_order_postmeta', true);
                 $payment_status = 'completed';
                 $params_array = array('method' => 'free', 'waited_amount' => $order_meta['order_amount_to_pay_now'], 'status' => 'payment_received', 'author' => $order_meta['customer_id'], 'payment_reference' => 'FREE_ORDER', 'date' => current_time('mysql', 0), 'received_amount' => $order_meta['order_amount_to_pay_now']);
                 wpshop_payment::check_order_payment_total_amount($order_id, $params_array, $payment_status);
             }
             apply_filters('wpshop_finish_order_extra_actions', $order_id);
         }
     }
     return $order_id;
 }
コード例 #3
0
 /**
  * Return the cart total weight
  * @param array $cart_items
  * @return number
  */
 function calcul_cart_weight($cart_items)
 {
     $cart_weight = 0;
     if (!empty($cart_items)) {
         foreach ($cart_items as $id_item => $cart_item) {
             $id_item = wpshop_products::get_id_variation($id_item);
             if (get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                 $product_data = get_post_meta($id_item, '_wpshop_product_metadata', true);
                 if (!empty($product_data) && !empty($product_data['product_weight'])) {
                     $cart_weight += $product_data['product_weight'] * $cart_item['item_qty'];
                 } else {
                     $parent_def = wpshop_products::get_parent_variation($id_item);
                     if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight'])) {
                         $cart_weight += $parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty'];
                     }
                 }
             } else {
                 $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true);
                 if (!empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty'])) {
                     $cart_weight += $product_data['product_weight'] * $cart_item['item_qty'];
                 }
             }
         }
     }
     return $cart_weight;
 }
コード例 #4
0
 /** Create a credit **/
 function create_an_credit($order_id, $product_list = array(), $credit_statut = 'not_paid', $credit_customer_account = '', $products_list_to_restock = array())
 {
     $status = false;
     if (!empty($order_id)) {
         $price_piloting_option = get_option('wpshop_shop_price_piloting');
         $order_credits = get_post_meta($order_id, '_wps_order_credit', true);
         $order_meta = get_post_meta($order_id, '_order_postmeta', true);
         if (empty($product_list)) {
             if (!empty($order_meta) && !empty($order_meta['order_items'])) {
                 $credit_def = array();
                 $credit_def['ref'] = self::generate_credit_slip_number($order_id);
                 $credit_def['credit_status'] = 'not_paid';
                 $credit_def['items'] = array();
                 $credit_total_amount = 0;
                 foreach ($order_meta['order_items'] as $item_id => $item) {
                     if (!empty($item_id) && !empty($item)) {
                         $credit_def['items'][$item_id] = $item;
                         $credit_total_amount += $credit_def['items'][$item_id]['item_total_ttc'];
                     }
                 }
                 if (!empty($order_meta['order_shipping_cost'])) {
                     $credit_def['items']['shipping_cost']['item_qty'] = 1;
                     $credit_def['items']['shipping_cost']['item_total_ht'] = $credit_def['items'][$product_id]['item_pu_ht'] = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $product['price'] : $product['price'] / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100);
                     $credit_def['items']['shipping_cost']['item_total_ttc'] = $credit_def['items'][$product_id]['item_pu_ttc'] = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $product['price'] * (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100) : $product['price'];
                     $credit_def['items']['shipping_cost']['item_tva_amount'] = $credit_def['items'][$product_id]['item_tva_total_amount'] = $credit_def['items'][$product_id]['item_pu_ttc'] - $credit_def['items'][$product_id]['item_pu_ht'];
                     $credit_def['items']['shipping_cost']['item_name'] = __('Shipping cost', 'wpshop');
                     $credit_def['items']['shipping_cost']['item_tva_rate'] = WPSHOP_VAT_ON_SHIPPING_COST;
                 }
             }
             $d = array();
             $d[] = $credit_def;
             update_post_meta($order_id, '_wps_order_credit', $d);
         } else {
             if (empty($order_credits)) {
                 $order_credits = array();
             }
             $credit_def = array();
             $credit_def['credit_date'] = current_time('mysql', 0);
             $credit_def['ref'] = self::generate_credit_slip_number($order_id);
             $credit_def['credit_status'] = $credit_statut;
             $credit_def['items'] = array();
             $credit_total_amount = 0;
             foreach ($product_list as $product_id => $product) {
                 if (!empty($order_meta) && !empty($order_meta['order_items']) && !empty($order_meta['order_items'][$product_id])) {
                     $credit_def['items'][$product_id] = $order_meta['order_items'][$product_id];
                     /** Check Price & Quantity **/
                     if (!empty($product['qty']) && $product['qty'] != $credit_def['items'][$product_id]['item_qty']) {
                         $credit_def['items'][$product_id]['item_qty'] = $product['qty'];
                         $credit_def['items'][$product_id]['item_total_ht'] = $credit_def['items'][$product_id]['item_pu_ht'] * $credit_def['items'][$product_id]['item_qty'];
                         $credit_def['items'][$product_id]['item_total_ttc'] = $credit_def['items'][$product_id]['item_pu_ht'] * (1 + $credit_def['items'][$product_id]['item_tva_rate'] / 100) * $credit_def['items'][$product_id]['item_qty'];
                         $credit_def['items'][$product_id]['item_tva_total_amount'] = $credit_def['items'][$product_id]['item_pu_ht'] * ($credit_def['items'][$product_id]['item_tva_rate'] / 100) * $credit_def['items'][$product_id]['item_qty'];
                     }
                     if (!empty($product['price']) && $product['price'] != (!empty($price_piloting_option) && $price_piloting_option == 'HT' ? $credit_def['items'][$product_id]['item_pu_ht'] : $credit_def['items'][$product_id]['item_qty'])) {
                         $credit_def['items'][$product_id]['item_pu_ht'] = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $product['price'] / (1 + $credit_def['items'][$product_id]['item_tva_rate'] / 100) : $product['price'];
                         $credit_def['items'][$product_id]['item_pu_ttc'] = $credit_def['items'][$product_id]['item_pu_ht'] * (1 + $credit_def['items'][$product_id]['item_tva_rate'] / 100);
                         $credit_def['items'][$product_id]['item_tva_amount'] = $credit_def['items'][$product_id]['item_pu_ht'] * (1 + $credit_def['items'][$product_id]['item_tva_rate'] / 100);
                         /** Total **/
                         $credit_def['items'][$product_id]['item_total_ht'] = $credit_def['items'][$product_id]['item_pu_ht'] * $credit_def['items'][$product_id]['item_qty'];
                         $credit_def['items'][$product_id]['item_total_ttc'] = $credit_def['items'][$product_id]['item_pu_ht'] * (1 + $credit_def['items'][$product_id]['item_tva_rate'] / 100) * $credit_def['items'][$product_id]['item_qty'];
                         $credit_def['items'][$product_id]['item_tva_total_amount'] = $credit_def['items'][$product_id]['item_pu_ht'] * ($credit_def['items'][$product_id]['item_tva_rate'] / 100) * $credit_def['items'][$product_id]['item_qty'];
                     }
                 }
                 /** Shipping Cost Include **/
                 if ($product_id == 'shipping_cost') {
                     $credit_def['items'][$product_id]['item_qty'] = 1;
                     $credit_def['items'][$product_id]['item_total_ht'] = $credit_def['items'][$product_id]['item_pu_ht'] = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $product['price'] : $product['price'] / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100);
                     $credit_def['items'][$product_id]['item_total_ttc'] = $credit_def['items'][$product_id]['item_pu_ttc'] = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $product['price'] * (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100) : $product['price'];
                     $credit_def['items'][$product_id]['item_tva_amount'] = $credit_def['items'][$product_id]['item_tva_total_amount'] = $credit_def['items'][$product_id]['item_pu_ttc'] - $credit_def['items'][$product_id]['item_pu_ht'];
                     $credit_def['items'][$product_id]['item_name'] = __('Shipping cost', 'wpshop');
                     $credit_def['items'][$product_id]['item_tva_rate'] = WPSHOP_VAT_ON_SHIPPING_COST;
                 }
                 $credit_total_amount += $credit_def['items'][$product_id]['item_total_ttc'];
                 if (!empty($products_list_to_restock)) {
                     if (array_key_exists($product_id, $products_list_to_restock)) {
                         /** Check Post type to know if product is a variation **/
                         $product_quantity = $credit_def['items'][$product_id]['item_qty'];
                         $item_post_type = get_post_type($product_id);
                         if ($item_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                             $parent_product_def = wpshop_products::get_parent_variation($product_id);
                             $parent_post = $parent_product_def['parent_post'];
                             if (!empty($parent_post)) {
                                 $product_id = $parent_post->ID;
                             }
                         }
                         self::restock_product_after_credit($product_id, $product_quantity);
                     }
                 }
             }
             $credit_def['total_credit'] = $credit_total_amount;
             $order_credits[] = $credit_def;
             update_post_meta($order_id, '_wps_order_credit', $order_credits);
             if (!empty($credit_customer_account)) {
                 $user_metadata = get_user_meta($order_meta['customer_id'], '_wps_credit_amount', true);
                 if (empty($user_metadata)) {
                     $user_metadata = 0;
                 }
                 $user_metadata += $credit_def['total_credit'];
                 update_user_meta($order_meta['customer_id'], '_wps_credit_amount', $user_metadata);
             }
         }
         $status = true;
     }
     return $status;
 }
コード例 #5
0
	];
	var myPie = new Chart(document.getElementById("wps-statistics-best-sales").getContext("2d")).Pie(pieData);         	
});
</script>
<!-- Display Legend -->
<ul class="wps_statistics_legend">
	<?php 
    if (!empty($products)) {
        $i = 0;
        foreach ($products as $item_id => $product) {
            if ($i < 8) {
                $product_type = get_post_type($item_id);
                if ($product_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
                    $product_name = get_the_title($item_id);
                } else {
                    $parent_def = wpshop_products::get_parent_variation($item_id);
                    if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                        $parent_post = $parent_def['parent_post'];
                        $product_name = $parent_post->post_title;
                    }
                }
                ?>
	
					<li><span style="background :<?php 
                echo $colors[$i];
                ?>
;" class="legend_indicator"></span><span><a href="<?php 
                echo admin_url('post.php?post=' . $item_id . '&action=edit');
                ?>
"><?php 
                echo !empty($product_name) ? $product_name : __('Deleted product', 'wpshop');
コード例 #6
0
require_once ABSPATH . 'wp-admin/includes/admin.php';
// T�l�chargement produit t�l�chargeable
if (!empty($_GET['download']) && !empty($_GET['oid'])) {
    $variation_id = '';
    if (is_user_logged_in()) {
        $user_id = get_current_user_id();
        $order = get_post_meta($_GET['oid'], '_order_postmeta', true);
        if (!empty($order)) {
            $download_codes = get_user_meta($user_id, '_order_download_codes_' . $_GET['oid'], true);
            if (!empty($download_codes) && is_array($download_codes)) {
                foreach ($download_codes as $downloadable_product_id => $d) {
                    $is_encrypted = false;
                    if ($d['download_code'] == $_GET['download']) {
                        wpshop_tools::create_custom_hook('encrypt_actions_for_downloadable_product', array('order_id' => $_GET['oid'], 'download_product_id' => $downloadable_product_id));
                        if (get_post_type($downloadable_product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                            $parent_def = wpshop_products::get_parent_variation($downloadable_product_id);
                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                                $parent_post = $parent_def['parent_post'];
                                $variation_id = $downloadable_product_id;
                                $downloadable_product_id = $parent_post->ID;
                            }
                        }
                        $link = wpshop_attributes::get_attribute_option_output(array('item_id' => $downloadable_product_id, 'item_is_downloadable_' => 'yes'), 'is_downloadable_', 'file_url', $order);
                        if ($link !== false) {
                            $uploads = wp_upload_dir();
                            $basedir = $uploads['basedir'];
                            $pos = strpos($link, 'uploads');
                            $link = $basedir . substr($link, $pos + 7);
                            /** If plugin is encrypted **/
                            $encrypted_plugin_path = get_post_meta($_GET['oid'], '_download_file_path_' . $_GET['oid'] . '_' . (!empty($variation_id) && get_post_type($variation_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ? $variation_id : $downloadable_product_id), true);
                            if (!empty($encrypted_plugin_path)) {
コード例 #7
0
 /**
  * Add product if is queried and recalcule cart informations
  * @param array $product_list
  * @param string $custom_order_information
  * @param array $current_cart
  * @param boolean $from_admin
  * @return array
  */
 function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false)
 {
     // Price piloting option
     $price_piloting = get_option('wpshop_shop_price_piloting');
     // Init vars
     $cart_infos = !empty($current_cart) ? $current_cart : (!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ? $_SESSION['cart'] : array());
     $cart_items = !empty($current_cart) && !empty($current_cart['order_items']) ? $current_cart['order_items'] : array();
     $cart_items = !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ? $_SESSION['cart']['order_items'] : $cart_items;
     $order_total_ht = $order_total_ttc = $total_vat = 0;
     $order_tva = array();
     $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0;
     $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0;
     // If Product list is not empty, add products to order
     if (!empty($product_list)) {
         foreach ($product_list as $product_id => $d) {
             $product_key = $product_id;
             if (isset($d['product_qty'])) {
                 // Formate datas
                 $product_id = $head_product_id = $d['product_id'];
                 $product_qty = $d['product_qty'];
                 $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
                 // If product is a single variation product
                 if (!empty($product_variation) && count($product_variation) == 1) {
                     $product_id = $product_variation[0];
                 }
                 // Construct final product
                 $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"');
                 $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product);
                 //	Add variation to product into cart for storage
                 if (!empty($product_variation)) {
                     $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
                 }
                 // Free Variations Checking
                 if (!empty($d['free_variation'])) {
                     $the_product['item_meta']['free_variation'] = $d['free_variation'];
                     $head_product_id = $the_product['product_id'];
                 }
                 // If product is a variation, we check parent product general
                 if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                     $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
                     if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                         $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
                         $parent_meta = $parent_def['parent_post_meta'];
                         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) {
                             $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
                             $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
                             $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
                         }
                     }
                 }
                 // Delete product if its qty is equals to zero, else add this product to order
                 if (empty($d['product_qty'])) {
                     unset($cart_items[$product_key]);
                     unset($cart_infos['order_items'][$product_key]);
                 } else {
                     $wps_orders = new wps_orders_ctr();
                     $cart_items[$product_key] = $wps_orders->add_product_to_order($the_product);
                 }
             }
         }
     }
     // Add automaticaly Add-to-cart Products
     $cart_items = $this->add_automaticaly_product_to_cart($cart_items);
     // Calcul Cart Informations
     if (!empty($cart_items) && is_array($cart_items)) {
         foreach ($cart_items as $item_id => $item) {
             $order_total_ht += $item['item_total_ht'];
             $order_total_ttc += $item['item_total_ttc'];
             // VAT
             if (!empty($order_tva[$item['item_tva_rate']])) {
                 $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount'];
             } else {
                 $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount'];
             }
         }
     } else {
         return array();
     }
     // Apply informations to cart
     $cart_infos['order_items'] = $cart_items;
     $cart_infos['order_total_ht'] = $order_total_ht;
     $cart_infos['order_total_ttc'] = $order_total_ttc;
     // Calcul Shipping cost
     if (!$from_admin) {
         $wps_shipping = new wps_shipping();
         $total_cart_ht_or_ttc_regarding_config = !empty($price_piloting) && $price_piloting == 'HT' ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc'];
         $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']);
         $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']);
         $cart_infos['order_shipping_cost'] = $wps_shipping->get_shipping_cost(count($cart_infos['order_items']), $total_cart_ht_or_ttc_regarding_config, $total_shipping_cost_for_products, $cart_weight);
     }
     // If Price piloting is ET, calcul VAT on Shipping cost
     if (!empty($price_piloting) && $price_piloting == 'HT') {
         $shipping_cost_vat = !empty($cart_infos['order_shipping_cost']) ? WPSHOP_VAT_ON_SHIPPING_COST / 100 * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0;
         $order_tva['VAT_shipping_cost'] = $shipping_cost_vat;
     }
     // Calcul VAT Total
     if (!empty($order_tva)) {
         foreach ($order_tva as $vat_rate => $vat_value) {
             $total_vat += $vat_value;
         }
     }
     // Recap totals
     $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;
     $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc'];
     // Apply coupons
     if (!empty($_SESSION['cart']) && !$from_admin) {
         if (!empty($_SESSION['cart']['coupon_id'])) {
             $wps_coupon_mdl = new wps_coupon_model();
             $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']);
             if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) {
                 $wps_coupon = new wps_coupon_ctr();
                 $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']);
                 // If Coupon conditions are Ok
                 if (!empty($coupon_checking) && !empty($coupon_checking['status']) && $coupon_checking['status']) {
                     $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type'];
                     $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value'];
                 }
             }
         }
     }
     // Checking Discounts
     if (!empty($cart_infos['order_discount_type']) && $cart_infos['order_discount_value']) {
         // Calcul discount on Order
         switch ($cart_infos['order_discount_type']) {
             case 'amount':
                 $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '');
                 break;
             case 'percent':
                 $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);
                 break;
         }
         $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', '');
         $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'], 2, '.', '');
     }
     // Apply Partial Payments
     $wpshop_payment = new wpshop_payment();
     $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']);
     if (!empty($partial_payment['amount_to_pay'])) {
         unset($partial_payment['display']);
         $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
         $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', '');
     }
     // Cart Type
     if (isset($_SESSION['cart']['cart_type'])) {
         $cart_infos['cart_type'] = $_SESSION['cart']['cart_type'];
     }
     // Apply Extra actions on cart infos
     $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION);
     return $cart_infos;
 }
コード例 #8
0
 function latest_products_ordered($orders)
 {
     global $wpdb;
     $product_id = $output = '';
     $products = array();
     $display_option = get_option('wpshop_display_option');
     if (!empty($orders) && !empty($display_option) && !empty($display_option['latest_products_ordered'])) {
         foreach ($orders as $order) {
             $order_content = get_post_meta($order->ID, '_order_postmeta', true);
             if (!empty($order_content) && !empty($order_content['order_items'])) {
                 foreach ($order_content['order_items'] as $item) {
                     if (count($products) >= $display_option['latest_products_ordered']) {
                         continue;
                     }
                     $product_id = $item['item_id'];
                     if (!empty($item) && !empty($item['item_meta']) && !empty($item['item_meta']['variation_definition'])) {
                         $parent_def = wpshop_products::get_parent_variation($item['item_id']);
                         if (!empty($parent_def)) {
                             $parent_post = $parent_def['parent_post'];
                             $product_id = $parent_post->ID;
                         }
                     }
                     if (!in_array($product_id, $products)) {
                         $products[] = $product_id;
                     }
                 }
             }
         }
         if (!empty($products)) {
             $products_id = implode(",", $products);
             $output = wpshop_display::display_template_element('latest_products_ordered', array('LATEST_PRODUCTS_ORDERED' => do_shortcode('[wpshop_products pid="' . $products_id . '"]')));
         }
     }
     return $output;
 }
コード例 #9
0
 /**
  * Update th receive payment part in order postmeta and return "Complete" if the shop have received the total amount of the order
  * @param int $order_id
  * @param array $params_array
  * @return string
  */
 public static function check_order_payment_total_amount($order_id, $params_array, $bank_response, $order_meta = array(), $save_metadata = true)
 {
     global $wpshop_payment;
     global $wpdb;
     $order_meta = !empty($order_meta) ? $order_meta : get_post_meta($order_id, '_order_postmeta', true);
     $wps_message = new wps_message_ctr();
     if (!empty($order_meta)) {
         $order_info = get_post_meta($order_id, '_order_info', true);
         $user_data = get_userdata($order_meta['customer_id']);
         $email = !empty($user_data) && !empty($user_data->user_email) ? $user_data->user_email : '';
         // 			$email = ( !empty($order_info) &&  !empty($order_info['billing']) && !empty($order_info['billing']['address']['address_user_email']) ) ? $order_info['billing']['address']['address_user_email'] : '' ;
         $first_name = !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']['address_first_name']) ? $order_info['billing']['address']['address_first_name'] : '';
         $last_name = !empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']['address_last_name']) ? $order_info['billing']['address']['address_last_name'] : '';
         $key = self::get_order_waiting_payment_array_id($order_id, $params_array['method']);
         $order_grand_total = $order_meta['order_grand_total'];
         $total_received = !empty($params_array['status']) && $params_array['status'] == 'payment_received' && $bank_response == 'completed' && !empty($params_array['received_amount']) ? $params_array['received_amount'] : 0;
         foreach ($order_meta['order_payment']['received'] as $received) {
             $total_received += !empty($received['status']) && $received['status'] == 'payment_received' && $bank_response == 'completed' && !empty($received['received_amount']) ? $received['received_amount'] : 0;
         }
         $order_meta['order_amount_to_pay_now'] = $order_grand_total - $total_received;
         $order_meta['order_payment']['received'][$key] = self::add_new_payment_to_order($order_id, $order_meta, $key, $params_array, $bank_response);
         if ($bank_response == 'completed') {
             if (number_format((double) $total_received, 2, '.', '') >= number_format((double) $order_grand_total, 2, '.', '')) {
                 $payment_status = 'completed';
                 $order_meta['order_invoice_ref'] = empty($order_meta['order_invoice_ref']) && !empty($order_meta['order_payment']['received'][$key]) && !empty($order_meta['order_payment']['received'][$key]['invoice_ref']) ? $order_meta['order_payment']['received'][$key]['invoice_ref'] : $order_meta['order_invoice_ref'];
                 $order_meta['order_invoice_date'] = current_time('mysql', 0);
                 if (!empty($order_meta['order_items'])) {
                     foreach ($order_meta['order_items'] as $item_id => $o) {
                         $pid = $o['item_id'];
                         if (strpos($item_id, '__') !== false) {
                             $product_data_id = explode('__', $item_id);
                             $pid = !empty($product_data_id) && !empty($product_data_id[1]) ? $product_data_id[1] : $pid;
                         }
                         $product = wpshop_products::get_product_data($pid);
                         if (get_post_type($pid) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                             $parent_def = wpshop_products::get_parent_variation($pid);
                             $parent_post = $parent_def['parent_post'];
                             $product = wpshop_products::get_product_data($parent_post->ID);
                         }
                         if (!empty($product) && !empty($product['manage_stock']) && strtolower(__($product['manage_stock'], 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
                             wpshop_products::reduce_product_stock_qty($product['product_id'], $o['item_qty'], $pid);
                         }
                     }
                 }
                 /** Add information about the order completed date */
                 update_post_meta($order_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_completed_date', current_time('mysql', 0));
                 /** Check if the order content a downloadable product **/
                 if (!empty($order_meta['order_items'])) {
                     foreach ($order_meta['order_items'] as $key_value => $item) {
                         $key_value = $item['item_id'];
                         /** Check if it's a product with signle variation, check the parent product **/
                         if (!empty($item['item_id']) && get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                             $parent_item = wpshop_products::get_parent_variation($item['item_id']);
                             $key_value = $parent_item['parent_post']->ID;
                             $parent_post_metadata = $parent_item['parent_post_meta'];
                             if (!empty($parent_post_metadata['is_downloadable_'])) {
                                 $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_post_metadata['is_downloadable_']);
                                 $downloadable_option_value = $wpdb->get_var($query);
                                 if (!empty($downloadable_option_value)) {
                                     $item['item_is_downloadable_'] = $downloadable_option_value;
                                 }
                             }
                         }
                         if (!empty($item) && !empty($item['item_is_downloadable_']) && (__($item['item_is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($item['item_is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) {
                             $download_codes = get_user_meta($order_meta['customer_id'], '_order_download_codes_' . $order_id, true);
                             if (!empty($download_codes) && !empty($download_codes[$key_value]) && !empty($download_codes[$key_value]['download_code'])) {
                                 $link = '<a href="' . WPSHOP_URL . '/download_file.php?oid=' . $order_id . '&amp;download=' . $download_codes[$key_value]['download_code'] . '">' . __('Download', 'wpshop') . '</a>';
                                 $wps_message->wpshop_prepared_email($email, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE', array('order_key' => $order_meta['order_key'], 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'order_date' => $order_meta['order_date'], 'download_product_link' => $link), array());
                             }
                         }
                     }
                 }
                 // Send confirmation e-mail to administrator
                 if (empty($_SESSION['wps-pos-addon'])) {
                     $email_option = get_option('wpshop_emails');
                     if (!empty($email_option) && !empty($email_option['send_confirmation_order_message'])) {
                         wpshop_checkout::send_order_email_to_administrator($order_id, $user_data);
                     }
                 }
                 // POS Status
                 if (!empty($order_meta['order_payment']) && !empty($order_meta['order_payment']['shipping_method']) && $order_meta['order_payment']['shipping_method'] == 'default_shipping_mode_for_pos') {
                     $payment_status = 'pos';
                 }
             } else {
                 $payment_status = 'partially_paid';
             }
             $order_meta['order_status'] = $payment_status;
             update_post_meta($order_id, '_order_postmeta', $order_meta);
             $save_metadata = false;
             $allow_send_invoice = get_option('wpshop_send_invoice');
             $invoice_attachment_file = !empty($allow_send_invoice) ? wpshop_modules_billing::generate_invoice_for_email($order_id, $order_meta['order_payment']['received'][$key]['invoice_ref']) : '';
             $email_option = get_option('wpshop_emails');
             $shipping_mode_option = get_option('wps_shipping_mode');
             $shipping_method = !empty($order_meta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_meta['order_payment']['shipping_method'], $shipping_mode_option['modes']) ? $shipping_mode_option['modes'][$order_meta['order_payment']['shipping_method']]['name'] : (!empty($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : '');
             $payment_method_option = get_option('wps_payment_mode');
             $order_payment_method = !empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_meta['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]) ? $payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]['name'] : $order_meta['order_payment']['customer_choice']['method'];
             if (!empty($email_option) && !empty($email_option['send_confirmation_order_message']) && $payment_status == 'completed') {
                 $wps_message->wpshop_prepared_email($email, 'WPSHOP_ORDER_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_key' => !empty($order_meta['order_key']) ? $order_meta['order_key'] : '', 'order_date' => current_time('mysql', 0), 'order_payment_method' => $order_payment_method, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method));
             }
             $wps_message->wpshop_prepared_email($email, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE', array('order_key' => $order_meta['order_key'], 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'order_date' => $order_meta['order_date'], 'order_shipping_method' => $shipping_method), array(), $invoice_attachment_file);
         } else {
             $payment_status = $bank_response;
         }
         $order_meta['order_status'] = $payment_status;
         if (!$save_metadata) {
             return $order_meta;
         } else {
             update_post_meta($order_id, '_order_postmeta', $order_meta);
         }
         update_post_meta($order_id, '_wpshop_order_status', $payment_status);
     }
 }
コード例 #10
0
 function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
 {
     global $wpdb;
     global $wpshop_payment;
     $output = '';
     $tpl_component = array();
     /**	Get attribute order for current product	*/
     $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
     $output_order = array();
     if (count($product_attribute_order_detail) > 0) {
         foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
             foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
                 if (!empty($attribute_def->code)) {
                     $output_order[$attribute_def->code] = $position;
                 }
             }
         }
     }
     $variation_attribute_ordered = array();
     /** Check if product is a variation and change his name **/
     $product_post_type = get_post_type($the_product['product_id']);
     if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
         $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
         $parent_post = !empty($parent_infos) && !empty($parent_infos['parent_post']) ? $parent_infos['parent_post'] : array();
         $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
     }
     foreach ($the_product as $product_definition_key => $product_definition_value) {
         if ($product_definition_key != 'item_meta') {
             $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
             if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
                 $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
             }
         } else {
             $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
         }
     }
     ksort($variation_attribute_ordered['attribute_list']);
     $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
     foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
         $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
     }
     /**	For security get all attributes defined as user defined or used in variation in order to set default value to empty	*/
     $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
     if (!empty($attribute_list)) {
         foreach ($attribute_list as $attribute_def) {
             $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
         }
     }
     /**	Fill the array with all prices for different variations	*/
     foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
         $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
     }
     $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
     $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
     $post_list_with_options = $wpdb->get_results($query);
     if (!empty($post_list_with_options)) {
         $additionnal_price = 0;
         foreach ($post_list_with_options as $product_info) {
             $product_meta = unserialize($product_info->meta_value);
             if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && $product_meta['cart']['auto_add'] == 'yes') {
                 $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
                 $the_product = array_merge(array('product_id' => $product_info->post_id, 'product_qty' => 1), $product);
                 $additionnal_price += !$different_currency || $change_rate == 1 ? $the_product['product_price'] : $the_product['product_price'] * $change_rate;
                 $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
                 $tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', !$different_currency || $change_rate == 1 ? $the_product['product_price'] : $the_product['product_price'] * $change_rate);
                 $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
             }
         }
     }
     $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
     $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
     if (!empty($additionnal_price)) {
         $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
         $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price;
         $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
     }
     /**	Call informtion for partial payment	*/
     $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
     $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
     /**	Define the current selected currency for the order summary	*/
     // 		$response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
     $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
     return $output;
 }
コード例 #11
0
 function add_gift_product_to_cart($cartContent, $order)
 {
     global $wpdb;
     if (!empty($order['cart_rule']) && !empty($order['cart_rule']['discount_value']) && !empty($order['cart_rule']['discount_type']) && $order['cart_rule']['discount_type'] == 'gift_product') {
         $product = get_post($order['cart_rule']['discount_value']);
         $option_name = '';
         if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
             $parent_product_infos = wpshop_products::get_parent_variation($product->ID);
             if (!empty($parent_product_infos) && !empty($parent_product_infos['parent_post'])) {
                 $parent_post_infos = $parent_product_infos['parent_post'];
                 $product_title = $parent_post_infos->post_title;
                 $product_options = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
                 if (!empty($product_options) && is_array($product_options)) {
                     $option_name = '';
                     foreach ($product_options as $k => $product_option) {
                         $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', $k);
                         $option_name .= $wpdb->get_var($query) . ' ';
                         $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $product_option);
                         $option_name .= $wpdb->get_var($query) . ' ';
                     }
                     $discount_value = $product_title;
                 }
             }
         } else {
             $discount_value = $product->post_title;
         }
         $tpl_component['CART_PRODUCT_MORE_INFO'] = $option_name;
         $tpl_component['CART_LINE_ITEM_ID'] = $order['cart_rule']['discount_value'];
         $tpl_component['CART_LINE_ITEM_PUHT'] = number_format(0, 2);
         $tpl_component['CART_LINE_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2);
         $tpl_component['CART_LINE_ITEM_TPHT'] = number_format(0, 2);
         $tpl_component['CART_LINE_ITEM_TPTTC'] = number_format(0, 2);
         $tpl_component['CART_LINE_ITEM_QTY_'] = 1;
         $tpl_component['CART_LINE_ITEM_REMOVER'] = '';
         $tpl_component['CART_PRODUCT_NAME'] = $discount_value . ' (' . __('Gift product', 'wpshop') . ')';
         $cartContent .= wpshop_display::display_template_element('cart_line', $tpl_component);
     }
     return $cartContent;
 }
コード例 #12
0
 /**
  * Check if there is enough stock for asked product if manage stock option is checked
  *
  * @param integer $product_id The product we have to check the stock for
  * @param unknown_type $cart_asked_quantity The quantity the end user want to add to the cart
  *
  * @return boolean|string  If there is enough sotck or if the option for managing stock is set to false return OK (true) In the other case return an alert message for the user
  */
 function check_stock($product_id, $cart_asked_quantity, $combined_variation_id = '')
 {
     // Checking if combined variation ID exist and it is a simple option
     if (!empty($combined_variation_id) && strpos($combined_variation_id, '__') !== false) {
         $var_id = explode('__', $combined_variation_id);
         $combined_variation_id = $var_id[1];
     }
     if (!empty($combined_variation_id)) {
         $variation_metadata = get_post_meta($combined_variation_id, '_wpshop_product_metadata', true);
         if (isset($variation_metadata['product_stock'])) {
             $product_id = $combined_variation_id;
         }
     }
     $product_data = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"');
     if (!empty($product_data)) {
         $manage_stock = !empty($product_data['manage_stock']) ? $product_data['manage_stock'] : '';
         $product_post_type = get_post_type($product_id);
         if ($product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
             $parent_def = wpshop_products::get_parent_variation($product_id);
             if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                 $parent_post = $parent_def['parent_post'];
                 $parent_product_data = wpshop_products::get_product_data($parent_post->ID);
                 $manage_stock = !empty($parent_product_data['manage_stock']) ? $parent_product_data['manage_stock'] : '';
             }
         }
         $manage_stock_is_activated = !empty($manage_stock) && strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')) ? true : false;
         $the_qty_is_in_stock = !empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity ? true : false;
         if ($manage_stock_is_activated && $the_qty_is_in_stock or !$manage_stock_is_activated) {
             return true;
         } else {
             return __('You cannot add that amount to the cart since there is not enough stock.', 'wpshop');
         }
     }
     return false;
 }
	];
	var myPie = new Chart(document.getElementById("wps-statistics-most-viewed-statistics").getContext("2d")).Pie(pieData);         	
});
</script>
<!-- Display Legend -->
<ul class="wps_statistics_legend">
	<?php 
    if (!empty($products)) {
        $i = 0;
        foreach ($products as $item_id => $product) {
            if ($i < 8) {
                $product_type = get_post_type($product->post_id);
                if ($product_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
                    $product_name = get_the_title($product->post_id);
                } else {
                    $parent_def = wpshop_products::get_parent_variation($product->post_id);
                    if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                        $parent_post = $parent_def['parent_post'];
                        $product_name = $parent_post->post_title;
                    }
                }
                ?>
	
					<li><span style="background :<?php 
                echo $colors[$i];
                ?>
;" class="legend_indicator"></span><span><a href="<?php 
                echo admin_url('post.php?post=' . $product->post_id . '&action=edit');
                ?>
"><?php 
                echo $product_name;
コード例 #14
0
 public static function get_product_price($product, $return_type, $output_type = '', $only_price = false, $price_checking_done = false)
 {
     $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
     // 			$wpshop_price_piloting_option = 'TTC';
     /** Price for Mini-output **/
     if (!$price_checking_done) {
         /** Checking if it's a product with variation **/
         $variation_option_checking = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
         if (!empty($variation_option_checking)) {
             $variations_exists = wpshop_products::get_variation($product['product_id']);
         }
         if (!empty($variation_option_checking) && !empty($variations_exists)) {
             if (!empty($variation_option_checking['attributes'])) {
                 foreach ($variation_option_checking['attributes'] as $attribute) {
                     $selected_variation[$attribute] = 0;
                     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'])) {
                         if ($variation_option_checking['options']['attributes_default_value'][$attribute] != 'none') {
                             $selected_variation[$attribute] = $variation_option_checking['options']['attributes_default_value'][$attribute];
                         }
                     }
                 }
             }
             if (!empty($selected_variation)) {
                 $product_with_variation = wpshop_products::get_variation_by_priority($selected_variation, $product['product_id']);
             }
             if (empty($product_with_variation[$product['product_id']]['variations'])) {
                 $product_with_variation[$product['product_id']]['variations'] = array();
             }
             if (!empty($product_with_variation[$product['product_id']]['variation_priority'])) {
                 $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' : ''));
             }
         } else {
             /** It's Simple product Check Discounts for products **/
             $discount_config = self::check_discount_for_product($product['product_id']);
             if (!empty($discount_config)) {
                 if (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'special_price') {
                     $product['price_ttc_before_discount'] = $product['product_price'];
                     $product['price_ht_before_discount'] = $product['price_ht'];
                     $product['price_ht'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $discount_config['value'] : $discount_config['value'] / (1 + $product['tx_tva'] / 100);
                     $product['product_price'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $discount_config['value'] * (1 + $product['tx_tva'] / 100) : $discount_config['value'];
                     $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
                 } elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_amount') {
                     $product['price_ttc_before_discount'] = $product['product_price'];
                     $product['price_ht_before_discount'] = $product['price_ht'];
                     $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);
                     $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'];
                     $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
                 } elseif (!empty($discount_config['type']) && !empty($discount_config['value']) && $discount_config['type'] == 'discount_rate') {
                     $product['price_ttc_before_discount'] = $product['product_price'];
                     $product['price_ht_before_discount'] = $product['price_ht'];
                     $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);
                     $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);
                     $product['tva'] = $product['price_ht'] * ($product['tx_tva'] / 100);
                 }
             }
         }
     }
     $price_infos = self::check_product_price($product);
     $productCurrency = '<span class="wps-currency">' . wpshop_tools::wpshop_get_currency() . '</span>';
     $wps_marketing_tools = new wps_marketing_tools_ctr();
     if (!empty($price_infos)) {
         if ($return_type == 'check_only') {
             /** Check if the product price has been set	*/
             if (isset($price_infos['ati']) && $price_infos['ati'] === '') {
                 return __('This product cannot be purchased - the price is not yet announced', 'wpshop');
             }
             /** Check if the product price is coherent (not less than 0)	*/
             if (isset($price_infos['ati']) && $price_infos['ati'] < 0) {
                 return __('This product cannot be purchased - its price is negative', 'wpshop');
             }
             return true;
         } elseif ($return_type == 'just_price_infos') {
             $tpl_component = array();
             $price = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $price_infos['et'] : $price_infos['ati'];
             $exploded_price = explode('.', number_format($price, 2, '.', ''));
             $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">,' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>';
             $tpl_component['TAX_PILOTING'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? __('ET', 'wpshop') : '';
             $tpl_component['CROSSED_OUT_PRICE'] = '';
             $tpl_component['MESSAGE_SAVE_MONEY'] = '';
             if (!empty($price_infos['discount']['discount_exist'])) {
                 $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;
                 $tpl_component['CROSSED_OUT_PRICE'] = $crossed_out_price;
                 if (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') {
                     $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
                 } else {
                     $exploded_discount_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
                 }
                 $discount_price = $exploded_discount_price[0] . '<span class="wpshop_price_centimes_display">,' . (!empty($exploded_discount_price[1]) ? $exploded_discount_price[1] : '') . '</span>';
                 $tpl_component['PRODUCT_PRICE'] = '<span class="wps-absolute-price">' . $discount_price . '</span> ' . $productCurrency;
                 $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_infos);
             } else {
                 $tpl_component['PRODUCT_PRICE'] = $price . ' ' . $productCurrency;
             }
             $post_type = get_post_type($product['product_id']);
             if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
                 $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
             } elseif ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                 $parent_def = wpshop_products::get_parent_variation($product['product_id']);
                 if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                     $parent_post = $parent_def['parent_post'];
                     $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
                 }
             }
             $price_display_option = get_option('wpshop_catalog_product_option');
             $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' : '';
             return $tpl_component;
         } else {
             if ($return_type == 'price_display') {
                 $tpl_component = array();
                 $price = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? $price_infos['et'] : $price_infos['ati'];
                 $price_data = $price_infos;
                 $exploded_price = explode('.', number_format($price, 2, '.', ''));
                 $price = '<span class="wps-absolute-price">' . $exploded_price[0] . '</span><span class="wpshop_price_centimes_display">.' . (!empty($exploded_price[1]) ? $exploded_price[1] : '') . '</span>';
                 $tpl_component['TAX_PILOTING'] = !empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT' ? __('ET', 'wpshop') : '';
                 $tpl_component['CROSSED_OUT_PRICE'] = '';
                 $tpl_component['MESSAGE_SAVE_MONEY'] = '';
                 if (!empty($price_infos['discount']['discount_exist'])) {
                     $text_from = false;
                     /** Get variation defining **/
                     $post_type = get_post_type($product['product_id']);
                     if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                         $parent_def = wpshop_products::get_parent_variation($product['product_id']);
                         if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                             $parent_post = $parent_def['parent_post'];
                             $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
                         }
                     } else {
                         $price_display_attribute = get_post_meta($product['product_id'], '_wpshop_variation_defining', true);
                     }
                     $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;
                     $exploded_price = explode('.', number_format($price_infos['discount']['discount_et_price'], 2, '.', ''));
                     $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>';
                     $exploded_price = explode('.', number_format($price_infos['discount']['discount_ati_price'], 2, '.', ''));
                     $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>';
                     $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;
                     $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)));
                     $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;
                     $tpl_component['MESSAGE_SAVE_MONEY'] = $wps_marketing_tools->display_message_you_save_money($price_data);
                 } else {
                     if (get_post_type($product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                         $parent_def = wpshop_products::get_parent_variation($product['product_id']);
                         $pid = $parent_def['parent_post'];
                         $pid = $pid->ID;
                     } else {
                         $pid = $product['product_id'];
                     }
                     $text_from = false;
                     /** Get variation defining **/
                     $post_type = get_post_type($pid);
                     if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                         $parent_def = wpshop_products::get_parent_variation($pid);
                         if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                             $parent_post = $parent_def['parent_post'];
                             $price_display_attribute = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
                         }
                     } else {
                         $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
                     }
                     $price_display_attribute = get_post_meta($pid, '_wpshop_variation_defining', true);
                     $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;
                     $tpl_component['PRODUCT_PRICE'] = $text_from && !empty($product['text_from']) ? __('Price from', 'wpshop') . ' ' : '';
                     $tpl_component['PRODUCT_PRICE'] .= $price . ' ' . $productCurrency;
                 }
                 // Replace . by ,
                 $tpl_component['PRODUCT_PRICE'] = str_replace('.', ',', $tpl_component['PRODUCT_PRICE']);
                 if ($output_type == 'complete_sheet') {
                     $price_tpl = wpshop_display::display_template_element('product_price_template_complete_sheet', $tpl_component);
                 } elseif ($output_type == 'mini_output' || in_array('mini_output', $output_type)) {
                     $price_tpl = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component);
                 }
                 return $price_tpl;
             }
         }
     }
     return false;
 }
コード例 #15
0
 /**
  * AJAX - Valid Checkout Step three
  */
 function wps_checkout_valid_step_three()
 {
     $response = '';
     $status = true;
     $shipping_address = !empty($_POST['shipping_address_id']) ? wpshop_tools::varSanitizer($_POST['shipping_address_id']) : null;
     $billing_address = !empty($_POST['billing_address_id']) ? wpshop_tools::varSanitizer($_POST['billing_address_id']) : null;
     $user_id = get_current_user_id();
     $response = '<div class="wps-alert-error"><ul>';
     if ($user_id != 0) {
         $shipping_option = get_option('wpshop_shipping_address_choice');
         $billing_option = get_option('wpshop_billing_address');
         $user_addresses = wps_address::get_addresses_list($user_id);
         // Check if is only downloadable else display address
         $cart_is_downloadable = false;
         if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
             foreach ($_SESSION['cart']['order_items'] as $c) {
                 $product = wpshop_products::get_product_data($c['item_id']);
                 /** Check if it's a variation and check the parent product **/
                 if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                     $parent_def = wpshop_products::get_parent_variation($c['item_id']);
                     if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) {
                         $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_'];
                     }
                 }
                 if (!empty($product['is_downloadable_'])) {
                     $cart_is_downloadable = true;
                 } else {
                     $cart_is_downloadable = false;
                     break;
                 }
             }
         }
         if (!empty($shipping_option) && !empty($shipping_option['activate']) && !$cart_is_downloadable) {
             /** Check Shipping address **/
             if (empty($shipping_address)) {
                 $status = false;
                 /** Check if user have already create a shipping address **/
                 if (!empty($shipping_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$shipping_option['choice']])) {
                     $response .= '<li>' . __('You must select a shipping address', 'wpshop') . '</li>';
                 } else {
                     $response .= '<li>' . __('You must create a shipping address', 'wpshop') . '</li>';
                 }
             }
         }
         /** Check Billing address **/
         if (empty($billing_address)) {
             $status = false;
             if (!empty($billing_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$billing_option['choice']])) {
                 $response .= '<li>' . __('You must select a billing address', 'wpshop') . '</li>';
             } else {
                 $response .= '<li>' . __('You must create a billing address', 'wpshop') . '</li>';
             }
         }
     } else {
         $status = false;
         $response .= '<li>' . __('You must be logged to pass to next step', 'wpshop') . '</li>';
     }
     $response .= '</ul></div>';
     /** If no error **/
     if ($status) {
         $_SESSION['shipping_address'] = $shipping_address;
         $_SESSION['billing_address'] = $billing_address;
         $permalink_option = get_option('permalink_structure');
         $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
         /** Checking if no shipping method is required and it is a quotation or a free order **/
         $shipping_option = get_option('wps_shipping_mode');
         $available_shipping_method = false;
         if (!empty($shipping_option) && !empty($shipping_option['modes']) && !$cart_is_downloadable) {
             foreach ($shipping_option['modes'] as $shipping_mode_id => $shipping_mode) {
                 if (!empty($shipping_mode['active']) && $shipping_mode['active'] == 'on') {
                     $available_shipping_method = true;
                 }
             }
         }
         if (!$available_shipping_method) {
             $_SESSION['shipping_method'] = 'No Shipping method required';
             $order_id = !empty($_SESSION['cart']['order_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0;
             if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') {
                 $status = true;
                 $payment_method = $_SESSION['payment_method'] = 'quotation';
                 $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']);
                 $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6';
             } elseif (!empty($_SESSION) && !empty($_SESSION['cart']) && isset($_SESSION['cart']['order_amount_to_pay_now']) && number_format($_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '') == '0.00') {
                 $status = true;
                 $payment_method = $_SESSION['payment_method'] = 'free';
                 $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']);
                 $permalink_option = get_option('permalink_structure');
                 $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
                 $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6';
                 // 						wpshop_tools::wpshop_safe_redirect( $url );
                 $response = $url;
             } else {
                 $status = true;
                 $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . (!empty($permalink_option) ? '?' : '&') . 'order_step=5';
             }
         } else {
             $status = true;
             $response = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=4';
         }
     }
     //Stock checking verification
     $this->checking_stock();
     echo json_encode(array('status' => $status, 'response' => $response));
     die;
 }
コード例 #16
0
 /**
  * Display Address Inteface
  * @param integer $customer_id
  * @param boolean $admin_display
  * @param integer $order_id
  * @return string
  */
 function display_addresses_interface($customer_id = '', $admin_display = false, $order_id = '')
 {
     $output = $extra_class = $billing_address_display = $shipping_address_display = '';
     $is_from_admin = !empty($customer_id) ? true : false;
     $user_id = !empty($customer_id) ? $customer_id : get_current_user_id();
     if ($user_id != 0) {
         $shipping_option = get_option('wpshop_shipping_address_choice');
         $billing_option = get_option('wpshop_billing_address');
         /** Shipping address **/
         // Check if is only downloadable else display address
         $cart_is_downloadable = false;
         if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
             foreach ($_SESSION['cart']['order_items'] as $c) {
                 $product = wpshop_products::get_product_data($c['item_id']);
                 /** Check if it's a variation and check the parent product **/
                 if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                     $parent_def = wpshop_products::get_parent_variation($c['item_id']);
                     if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) {
                         $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_'];
                     }
                 }
                 if (!empty($product['is_downloadable_'])) {
                     $cart_is_downloadable = true;
                 } else {
                     $cart_is_downloadable = false;
                     break;
                 }
             }
         }
         if (!empty($shipping_option) && !empty($shipping_option['activate']) && !$cart_is_downloadable) {
             $address_title = __('Shipping address', 'wpshop');
             $address_type = 'shipping-address';
             $extra_class = 'wps-' . $address_type;
             $address_type_id = $shipping_option['choice'];
             $type = 'shipping';
             $box_content = !$admin_display ? self::display_address_interface_content($shipping_option['choice'], $address_title, '', $type, $user_id) : '';
             /** First address checking **/
             $selected_address = !empty($_SESSION['shipping_address']) ? $_SESSION['shipping_address'] : '';
             $addresses = self::get_addresses_list($user_id);
             $list_addresses = !empty($addresses[$billing_option['choice']]) ? $addresses[$billing_option['choice']] : array();
             $first_address_checking = empty($list_addresses) ? true : false;
             if ($admin_display) {
                 ob_start();
                 require wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "container");
                 $shipping_address_display = ob_get_contents();
                 ob_end_clean();
             } else {
                 ob_start();
                 require wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "frontend", "address", "container");
                 $output .= ob_get_contents();
                 ob_end_clean();
             }
         }
         /** Billing address **/
         if (!empty($billing_option) && !empty($billing_option['choice'])) {
             $address_title = __('Billing address', 'wpshop');
             $address_type = 'billing-address';
             $address_type_id = $billing_option['choice'];
             $type = 'billing';
             $box_content = !$admin_display ? self::display_address_interface_content($billing_option['choice'], $address_title, '', $type, $user_id) : '';
             $extra_class = 'wps-' . $address_type;
             $selected_address = !empty($_SESSION['billing_address']) ? $_SESSION['billing_address'] : '';
             if ($admin_display) {
                 ob_start();
                 require wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "container");
                 $billing_address_display .= ob_get_contents();
                 ob_end_clean();
             } else {
                 ob_start();
                 require wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "frontend", "address", "container");
                 $output .= ob_get_contents();
                 ob_end_clean();
             }
         }
     }
     return $admin_display ? $billing_address_display . $shipping_address_display : $output;
 }