예제 #1
1
 /**
  *	Function called on plugin initialisation allowing to declare the new types needed by our plugin
  *	@see wpshop_products::create_wpshop_products_type();
  *	@see wpshop_categories::create_product_categories();
  */
 public static function add_new_wp_type()
 {
     $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
     /*	Creation du type d'element Entité pour wpshop	*/
     wpshop_entities::create_wpshop_entities_type();
     add_action('add_meta_boxes', array('wpshop_entities', 'add_meta_boxes'));
     add_action('save_post', array('wpshop_entities', 'save_entity_type_custom_informations'));
     add_filter('manage_posts_columns', array('wpshop_entities', 'custom_columns_header'), 10, 2);
     add_filter('manage_posts_custom_column', array('wpshop_entities', 'custom_columns_content'), 10, 2);
     // 			add_action('quick_edit_custom_box', array('wpshop_attributes', 'quick_edit'), 10, 2);
     add_action('bulk_edit_custom_box', array('wpshop_attributes', 'bulk_edit'), 10, 2);
     /*	Creation des types personnalisé à partir des entités créées	*/
     wpshop_entities::create_wpshop_entities_custom_type();
     /*	Add wpshop product type and add a new meta_bow into product creation/edition interface for regrouping title and editor in order to sort interface	*/
     wpshop_products::create_wpshop_products_type();
     add_action('add_meta_boxes', array('wpshop_products', 'add_meta_boxes'));
     add_filter('post_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
     add_filter('post_type_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
     add_action('pre_get_posts', array('wpshop_products', 'set_product_request_by_name'));
     $product_class = new wpshop_products();
     add_action('save_post', array($product_class, 'save_product_custom_informations'));
     /*	Add wpshop product category term	*/
     wpshop_categories::create_product_categories();
     /*	Add wpshop message term	*/
     if ($wpshop_shop_type == 'sale') {
         /*	Add wpshop orders term	*/
         wpshop_orders::create_orders_type();
         add_action('add_meta_boxes', array('wpshop_orders', 'add_meta_boxes'));
         add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_posts_custom_column', array('wpshop_orders', 'orders_custom_columns'), 10, 2);
         add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_columns', array('wpshop_orders', 'orders_edit_columns'));
         add_action('restrict_manage_posts', array('wpshop_orders', 'list_table_filters'));
         add_filter('parse_query', array('wpshop_orders', 'list_table_filter_parse_query'));
     }
     $args = array('public' => true, '_builtin' => false);
     $output = 'objects';
     // names or objects, note names is the default
     $operator = 'or';
     // 'and' or 'or'
     $wp_types_original = get_post_types($args, $output, $operator);
     foreach ($wp_types_original as $type => $type_definition) {
         $wp_types[$type] = $type_definition->labels->name;
     }
     $to_exclude = unserialize(WPSHOP_INTERNAL_TYPES_TO_EXCLUDE);
     if (!empty($to_exclude)) {
         foreach ($to_exclude as $excluded_type) {
             if (isset($wp_types[$excluded_type])) {
                 unset($wp_types[$excluded_type]);
             }
         }
     }
     DEFINE('WPSHOP_INTERNAL_TYPES', serialize(array_merge($wp_types, array('users' => __('Users', 'wpshop')))));
 }
 /**
  * Save custom Order informations
  */
 function save_order_custom_informations()
 {
     global $wpdb;
     // Check if it is an order save action
     if (!empty($_REQUEST['post_ID']) && get_post_type($_REQUEST['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
         //Define Customer ID
         $user_id = !empty($_REQUEST['wps_customer_id']) ? $_REQUEST['wps_customer_id'] : get_current_user_id();
         // Order MetaData
         $order_meta = get_post_meta(intval($_REQUEST['post_ID']), '_order_postmeta', true);
         // Save General information of order's attached customer
         $wpdb->update($wpdb->posts, array('post_parent' => $user_id, 'post_status' => 'publish'), array('ID' => $_REQUEST['post_ID']));
         update_post_meta($_REQUEST['post_ID'], '_wpshop_order_customer_id', $user_id);
         $order_meta['customer_id'] = $user_id;
         if (empty($order_meta['order_key'])) {
             $order_meta['order_key'] = !empty($order_meta['order_key']) ? $order_meta['order_key'] : (!empty($order_meta['order_status']) && $order_meta['order_status'] != 'awaiting_payment' ? wpshop_orders::get_new_order_reference() : '');
             $order_meta['order_temporary_key'] = isset($order_meta['order_temporary_key']) && $order_meta['order_temporary_key'] != '' ? $order_meta['order_temporary_key'] : wpshop_orders::get_new_pre_order_reference();
         }
         $order_meta['order_status'] = isset($order_meta['order_status']) && $order_meta['order_status'] != '' ? $order_meta['order_status'] : 'awaiting_payment';
         $order_meta['order_date'] = isset($order_meta['order_date']) && $order_meta['order_date'] != '' ? $order_meta['order_date'] : current_time('mysql', 0);
         $order_meta['order_currency'] = wpshop_tools::wpshop_get_currency(true);
         // Order Attached Addresses save
         if (!empty($_REQUEST['wps_order_selected_address']['billing'])) {
             // Informations
             $order_informations = get_post_meta($_REQUEST['post_ID'], '_order_info', true);
             $order_informations = !empty($order_informations) ? $order_informations : array();
             $billing_address_option = get_option('wpshop_billing_address');
             $billing_address_option = !empty($billing_address_option) && !empty($billing_address_option['choice']) ? $billing_address_option['choice'] : '';
             // Billing datas
             $order_informations['billing'] = array('id' => $billing_address_option, 'address_id' => $_REQUEST['wps_order_selected_address']['billing'], 'address' => get_post_meta($_REQUEST['wps_order_selected_address']['billing'], '_wpshop_address_metadata', true));
             // Shipping datas
             if (!empty($_REQUEST['wps_order_selected_address']['shipping'])) {
                 $shipping_address_option = get_option('wpshop_shipping_address_choice');
                 $shipping_address_option = !empty($shipping_address_option) && !empty($shipping_address_option['choice']) ? $shipping_address_option['choice'] : '';
                 $order_informations['shipping'] = array('id' => $shipping_address_option, 'address_id' => $_REQUEST['wps_order_selected_address']['shipping'], 'address' => get_post_meta($_REQUEST['wps_order_selected_address']['shipping'], '_wpshop_address_metadata', true));
             }
             update_post_meta($_REQUEST['post_ID'], '_order_info', $order_informations);
         }
         // Add a Payment to Order MetaData
         if (!empty($_REQUEST['wpshop_admin_order_payment_received']) && !empty($_REQUEST['wpshop_admin_order_payment_received']['method']) && !empty($_REQUEST['wpshop_admin_order_payment_received']['date']) && !empty($_REQUEST['wpshop_admin_order_payment_received']['received_amount']) && ($_REQUEST['action_triggered_from'] == 'add_payment' || !empty($_REQUEST['wpshop_admin_order_payment_reference']))) {
             $received_payment_amount = $_REQUEST['wpshop_admin_order_payment_received']['received_amount'];
             // Payment Params
             $params_array = array('method' => $_REQUEST['wpshop_admin_order_payment_received']['method'], 'waited_amount' => $received_payment_amount, 'status' => 'payment_received', 'author' => $user_id, 'payment_reference' => $_REQUEST['wpshop_admin_order_payment_received']['payment_reference'], 'date' => current_time('mysql', 0), 'received_amount' => $received_payment_amount);
             $order_meta = wpshop_payment::check_order_payment_total_amount($_REQUEST['post_ID'], $params_array, 'completed', $order_meta, false);
         }
         //Round final amount
         $order_meta['order_grand_total'] = number_format(round($order_meta['order_grand_total'], 2), 2, '.', '');
         $order_meta['order_total_ttc'] = number_format(round($order_meta['order_total_ttc'], 2), 2, '.', '');
         $order_meta['order_amount_to_pay_now'] = number_format(round($order_meta['order_amount_to_pay_now'], 2), 2, '.', '');
         // Payment Pre-Fill
         if (empty($order_meta['order_payment'])) {
             $order_meta['order_payment']['customer_choice']['method'] = '';
             $order_meta['order_payment']['received'][] = array('waited_amount' => !empty($order_meta) && !empty($order_meta['order_grand_total']) ? number_format($order_meta['order_grand_total'], 2, '.', '') : 0);
         }
         // Apply a filter to make credit, notificate the customer and generate billing actions
         $order_meta = apply_filters('wps_order_saving_admin_extra_action', $order_meta, $_REQUEST);
         // Save Shipping informations & Order status
         update_post_meta($_REQUEST['post_ID'], '_wpshop_order_shipping_date', $order_meta['order_shipping_date']);
         update_post_meta($_REQUEST['post_ID'], '_wpshop_order_status', $order_meta['order_status']);
         // Save Metadata
         update_post_meta($_REQUEST['post_ID'], '_order_postmeta', $order_meta);
     }
 }
 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;
 }
예제 #4
0
                $order_meta['shipping_is_free'] = true;
                $order_meta['order_grand_total'] = $order_meta['order_grand_total'] - $order_meta['order_shipping_cost'];
                $order_meta['order_shipping_cost'] = 0;
                break;
                // Unset the shipping price to zero
            // Unset the shipping price to zero
            case 'unset_shipping_to_free':
                $order_meta['order_shipping_cost'] = $order_meta['order_old_shipping_cost'];
                $order_meta['order_grand_total'] = $order_meta['order_grand_total'] + $order_meta['order_shipping_cost'];
                unset($order_meta['order_old_shipping_cost']);
                unset($order_meta['shipping_is_free']);
                break;
        }
        /*	Update order content	*/
        update_post_meta($elementIdentifier, '_order_postmeta', $order_meta);
        echo wpshop_orders::order_content(get_post($elementIdentifier));
        break;
        //	Load product list
    //	Load product list
    case 'ajax_load_product_list':
        $product_per_page = 6;
        $current_order_id = isset($_POST['order_id']) && $_POST['order_id'] > 0 ? $_POST['order_id'] : 0;
        $current_page = isset($_POST['page']) && $_POST['page'] > 0 ? $_POST['page'] : 1;
        if ($current_order_id > 0) {
            $product_list_for_selection_pagination = '<div class="dialog_listing_pagination_container alignright" >' . paginate_links(array('base' => '#', 'current' => $current_page, 'total' => $wp_query->max_num_pages, 'type' => 'list', 'prev_next' => false)) . '</div>';
            wp_reset_query();
            $product_association_box = '<div id="product_selection_dialog_msg" class="wpshopHide wpshopPageMessage wpshopPageMessage_Updated" >&nbsp;</div><div id="product_listing_container" ><form action="' . WPSHOP_AJAX_FILE_URL . '" id="wpshop_order_selector_product_form" ><input type="hidden" name="list_has_been_modified" id="list_has_been_modified" value="" /><input type="hidden" name="post" value="true" /><input type="hidden" name="order_id" value="' . $current_order_id . '" /><input type="hidden" name="elementCode" value="ajax_add_product_to_order" />' . wpshop_products::custom_product_list() . '</form></div>
<script type="text/javascript" >
wpshop(document).ready(function(){
jQuery(".wpshop_product_cb_dialog").click(function(){
	jQuery("#list_has_been_modified").val("yes");