コード例 #1
0
 /**
  * AJAX - Save into current user meta the different help that have to be closed next time the user will be logged in
  */
 function wps_ajax_close_wps_help_window()
 {
     $status = false;
     $result = '';
     $pointer_id = !empty($_POST['pointer_id']) ? wpshop_tools::varSanitizer($_POST['pointer_id']) : '';
     if (!empty($pointer_id)) {
         $seen_help_windows = get_user_meta(get_current_user_id(), '_wps_closed_help', true);
         $seen_help_windows[$pointer_id] = true;
         update_user_meta(get_current_user_id(), '_wps_closed_help', $seen_help_windows);
         $status = true;
     }
     $response = array('status' => $status, 'response' => $result);
     wp_die(json_encode($response));
 }
コード例 #2
0
 /**
  * Delete address in order
  */
 function delete_address_in_order_panel()
 {
     $status = false;
     $address_datas = !empty($_POST['address_id']) ? wpshop_tools::varSanitizer($_POST['address_id']) : null;
     if (!empty($address_datas)) {
         $address_datas = explode('-', $address_datas);
         if (!empty($address_datas) && !empty($address_datas[0])) {
             wp_delete_post($address_datas[0], true);
             delete_post_meta($address_datas[0], '_wpshop_address_attribute_set_id');
             delete_post_meta($address_datas[0], '_wpshop_address_metadata');
             $status = true;
         }
     }
     echo json_encode(array('status' => $status));
     wp_die();
 }
コード例 #3
0
 /**
  *	Define the title of the page
  *
  *	@return string $title The title of the page looking at the environnement
  */
 function pageTitle()
 {
     $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : '';
     $objectInEdition = isset($_REQUEST['id']) ? wpshop_tools::varSanitizer($_REQUEST['id']) : '';
     $title = __(self::pageTitle, 'wpshop');
     if ($action != '') {
         if ($action == 'edit' || $action == 'delete') {
             $editedItem = self::getElement($objectInEdition);
             $title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label) . ' (' . $editedItem->code . ')');
         } elseif ($action == 'add') {
             $title = __(self::pageAddingTitle, 'wpshop');
         }
     } elseif (self::getEditionSlug() != self::getListingSlug() && $_GET['page'] == self::getEditionSlug()) {
         $title = __(self::pageAddingTitle, 'wpshop');
     }
     return $title;
 }
コード例 #4
0
 /** Save the cart rule **/
 function wpshop_ajax_delete_cart_rule()
 {
     $cart_rule_id = !empty($_POST['cart_rule_id']) ? wpshop_tools::varSanitizer($_POST['cart_rule_id']) : null;
     $status = false;
     $response = array();
     $cart_rules = !empty($_POST['cart_rules']) ? $_POST['cart_rules'] : null;
     $cart_rule_id = str_replace('_', '.', $cart_rule_id);
     if (!empty($cart_rule_id)) {
         $cart_rules = unserialize(stripslashes($cart_rules));
         unset($cart_rules[$cart_rule_id]);
         $cart_rules = serialize($cart_rules);
         $status = true;
     }
     $display_rules = wpshop_cart_rules::display_cart_rules($cart_rules);
     $display_rules = wpshop_cart_rules::display_cart_rules($cart_rules);
     $reponse = array('status' => $status, 'response' => $cart_rules, 'display_rules' => $display_rules);
     echo json_encode($reponse);
     die;
 }
コード例 #5
0
 /**
  * AJAX - Load element list from choosen letter into alphabet list
  */
 function ajax_load_element_from_letter()
 {
     $response = array('status' => false, 'output' => __('An error occured', 'wps-pos-i18n'));
     $alphabet = unserialize(WPSPOS_ALPHABET_LETTERS);
     $letter = !empty($_POST['term']) && in_array($_POST['term'], $alphabet) ? $_POST['term'] : null;
     $element_type = !empty($_POST['element_type']) ? wpshop_tools::varSanitizer($_POST['element_type']) : 'customer';
     $response['element_type'] = $element_type;
     if (!empty($letter)) {
         $error_message = '';
         switch ($element_type) {
             case 'customer':
                 $result = $this->wps_pos_customer->display_customer_list($letter);
                 break;
             case 'product':
                 $wps_pos_product = new wps_pos_addon_product();
                 $result = $this->wps_pos_product->get_product_table_by_alphabet($letter);
                 break;
         }
         if (empty($result)) {
             $response['output'] = sprintf(__('Nothing found in %s for letter %s', 'wps-pos-i18n'), __($element_type, 'wps-pos-i18n'), $letter);
         } else {
             $response['status'] = true;
             $response['output'] = $result;
         }
     } else {
         $response['output'] = sprintf(__('THe requested term (%s) to search is invalid. Please check your request and try again', 'wps-pos-i18n'), $_POST['term']);
     }
     wp_die(json_encode($response));
 }
コード例 #6
0
 /**
  *	Return The complete output page code
  *
  *	@return string The complete html page output
  */
 public static function display_page()
 {
     $pageAddButton = false;
     $pageMessage = $addButtonLink = $pageFormButton = $pageIcon = $pageIconTitle = $pageIconAlt = $objectType = '';
     $outputType = 'listing';
     $objectToEdit = isset($_REQUEST['id']) ? wpshop_tools::varSanitizer($_REQUEST['id']) : '';
     $pageSlug = isset($_REQUEST['page']) ? wpshop_tools::varSanitizer($_REQUEST['page']) : '';
     $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : '';
     /*	Select the content to add to the page looking for the parameter	*/
     switch ($pageSlug) {
         case WPSHOP_URL_SLUG_ATTRIBUTE_LISTING:
             $objectType = new wpshop_attributes();
             $current_user_can_edit = current_user_can('wpshop_edit_attributes');
             $current_user_can_add = current_user_can('wpshop_add_attributes');
             $current_user_can_delete = current_user_can('wpshop_delete_attributes');
             if (current_user_can('wpshop_add_attributes')) {
                 $pageAddButton = true;
             }
             break;
         case WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING:
             $objectType = new wpshop_attributes_set();
             $current_user_can_edit = current_user_can('wpshop_edit_attribute_set');
             $current_user_can_add = current_user_can('wpshop_add_attribute_set');
             $current_user_can_delete = current_user_can('wpshop_delete_attribute_set');
             if (current_user_can('wpshop_add_attribute_set')) {
                 $pageAddButton = true;
             }
             break;
         case WPSHOP_URL_SLUG_SHORTCODES:
             $pageAddButton = false;
             $current_user_can_edit = false;
             $objectType = new wps_shortcodes_ctr();
             break;
         case WPSHOP_URL_SLUG_MESSAGES:
             $pageAddButton = false;
             $objectType = new wpshop_messages();
             $current_user_can_edit = true;
             if (!empty($_GET['mid'])) {
                 $action = 'edit';
             }
             break;
         default:
             $pageTitle = sprintf(__('You have to add this page into %s at line %s', 'wpshop'), __FILE__, __LINE__ - 4);
             $pageAddButton = false;
             break;
     }
     if ($objectType != '') {
         if ($action != '' && ($action == 'edit' && $current_user_can_edit || $action == 'add' && $current_user_can_add || $action == 'delete' && $current_user_can_delete)) {
             $outputType = 'adding';
         }
         $objectType->elementAction();
         $pageIcon = self::getPageIconInformation('path', $objectType);
         $pageIconTitle = self::getPageIconInformation('title', $objectType);
         $pageIconAlt = self::getPageIconInformation('alt', $objectType);
         if ($outputType == 'listing') {
             $pageContent = $objectType->elementList();
         } elseif ($outputType == 'adding') {
             $pageAddButton = false;
             $pageFormButton = $objectType->getPageFormButton($objectToEdit);
             $pageContent = $objectType->elementEdition($objectToEdit);
         }
         $pageTitle = $objectType->pageTitle();
         $pageMessage = $objectType->pageMessage;
         if (in_array($objectType->getEditionSlug(), array(WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING))) {
             $addButtonLink = admin_url('admin.php?page=' . $objectType->getEditionSlug() . '&action=add');
         } else {
             $addButtonLink = admin_url('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES . '&page=' . $objectType->getEditionSlug() . '&action=add');
         }
     }
     /*	Page content header	*/
     wpshop_display::displayPageHeader($pageTitle, $pageIcon, $pageIconTitle, $pageIconAlt, $pageAddButton, $addButtonLink, $pageMessage, $pageSlug);
     /*	Page content	*/
     echo $pageContent;
     /*	Page content footer	*/
     wpshop_display::displayPageFooter($pageFormButton);
 }
コード例 #7
0
 /**
  * AJAX - Load order details in customer account
  */
 function wps_orders_load_details()
 {
     $order_id = !empty($_POST['order_id']) ? wpshop_tools::varSanitizer($_POST['order_id']) : '';
     $user_id = get_current_user_id();
     $status = false;
     $result = '';
     if (!empty($order_id)) {
         $order = get_post($order_id);
         $order_infos = get_post_meta($order_id, '_order_postmeta', true);
         $order_key = !empty($order_infos['order_key']) ? $order_infos['order_key'] : '-';
         if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) {
             $result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]');
             $status = true;
         }
     }
     echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result));
     wp_die();
 }
コード例 #8
0
 /**
  * Save informations for current entity
  */
 public static function save_entities_custom_informations($post)
 {
     global $wpdb;
     global $wpshop_account;
     $post_id = !empty($_REQUEST['post_ID']) ? intval(wpshop_tools::varSanitizer($_REQUEST['post_ID'])) : null;
     if (!empty($post_id) && empty($_POST['edit_other_thing']) || !empty($_REQUEST['post_ID']) && !(bool) $_POST['edit_other_thing'] && get_post_type($_REQUEST['post_ID']) != WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
         $current_post_type = get_post_type($post_id);
         /*	Vérification de l'existence de l'envoi de l'identifiant du set d'attribut	*/
         if (!empty($_REQUEST[$current_post_type . '_attribute_set_id'])) {
             $attribute_set_id = intval(wpshop_tools::varSanitizer($_REQUEST[$current_post_type . '_attribute_set_id']));
             $attribet_set_infos = wpshop_attributes_set::getElement($attribute_set_id, "'valid'", 'id');
             if ($attribet_set_infos->entity == $_REQUEST['post_type']) {
                 /*	Enregistrement de l'identifiant du set d'attribut associé à l'entité	*/
                 update_post_meta($post_id, sprintf(WPSHOP_ATTRIBUTE_SET_ID_META_KEY, $current_post_type), $attribute_set_id);
                 /*	Enregistrement de tous les attributs	*/
                 if (!empty($_REQUEST[$current_post_type . '_attribute'])) {
                     /*	Traduction des virgule en point pour la base de donnees	*/
                     if (!empty($_REQUEST[$current_post_type . '_attribute']['decimal'])) {
                         foreach ($_REQUEST[$current_post_type . '_attribute']['decimal'] as $attributeName => $attributeValue) {
                             if (!is_array($attributeValue)) {
                                 $_REQUEST[$current_post_type . '_attribute']['decimal'][$attributeName] = str_replace(',', '.', $_REQUEST[$current_post_type . '_attribute']['decimal'][$attributeName]);
                             }
                         }
                     }
                     /*	Enregistrement des valeurs des différents attributs	*/
                     wpshop_attributes::saveAttributeForEntity($_REQUEST[$current_post_type . '_attribute'], wpshop_entities::get_entity_identifier_from_code($current_post_type), $post_id, WPSHOP_CURRENT_LOCALE);
                     /*	Enregistrement des valeurs des attributs dans les metas de l'entité => Permet de profiter de la recherche native de wordpress	*/
                     $productMetaDatas = array();
                     foreach ($_REQUEST[$current_post_type . '_attribute'] as $attributeType => $attributeValues) {
                         foreach ($attributeValues as $attributeCode => $attributeValue) {
                             $productMetaDatas[$attributeCode] = $attributeValue;
                         }
                     }
                     update_post_meta($_REQUEST['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
                 }
             }
         }
         if (!empty($_REQUEST['attribute'])) {
             $current_id = array();
             foreach ($_REQUEST['attribute'] as $key => $values) {
                 $ad_id = '';
                 $addresses_id = get_post_meta($_REQUEST['post_ID'], '_wpshop_attached_address', true);
                 if (!empty($addresses_id)) {
                     foreach ($addresses_id as $address_id) {
                         $address_type = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true);
                         if ($address_type == $key) {
                             $ad_id = $address_id;
                         }
                     }
                 }
                 $_REQUEST['item_id'] = $ad_id;
                 $result = wps_address::save_address_infos($key);
                 $current_id[] = $result['current_id'];
             }
             update_post_meta($_REQUEST['post_ID'], '_wpshop_attached_address', $current_id);
         } else {
             $current_id = array();
             if (!empty($_REQUEST['address_type'])) {
                 foreach ($_REQUEST['address_type'] as $key => $value) {
                     $current_id[] = $value;
                 }
             }
             update_post_meta($_REQUEST['post_ID'], '_wpshop_entity_attached_address', $current_id);
         }
     }
     /** Save price infos **/
     if (!empty($_REQUEST) && !empty($_REQUEST['post_ID']) && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
     }
     flush_rewrite_rules();
 }
コード例 #9
0
 /**
  *	Add additionnal fields to the category edition form
  */
 public static function category_edit_fields()
 {
     $category_id = wpshop_tools::varSanitizer($_REQUEST["tag_ID"]);
     $category_meta_information = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
     $tpl_component = array();
     $category_thumbnail_preview = '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail_preview" />';
     /*	Check if there is already a picture for the selected category	*/
     if (!empty($category_meta_information['wpshop_category_picture'])) {
         $image_post = wp_get_attachment_image($category_meta_information['wpshop_category_picture'], 'thumbnail', false, array('class' => 'category_thumbnail_preview'));
         $category_thumbnail_preview = !empty($image_post) ? $image_post : '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail_preview" />';
     }
     $tpl_component['CATEGORY_DELETE_PICTURE_BUTTON'] = '';
     if (!empty($category_meta_information) && !empty($category_meta_information['wpshop_category_picture'])) {
         $tpl_component['CATEGORY_DELETE_PICTURE_BUTTON'] = '<a href="#" role="button" id="wps-delete-category-picture" class="wps-bton-second-mini-rounded">' . __('Delete the category picture', 'wpshop') . '</a> ';
     }
     $tpl_component['CATEGORY_PICTURE_ID'] = !empty($category_meta_information['wpshop_category_picture']) ? $category_meta_information['wpshop_category_picture'] : '';
     $tpl_component['CATEGORY_THUMBNAIL_PREVIEW'] = $category_thumbnail_preview;
     if (isset($_GET['tag_ID'])) {
         $tpl_component['CATEGORY_TAG_ID'] = $_GET['tag_ID'];
         $tpl_component['CATEGORY_FILTERABLE_ATTRIBUTES'] = '';
         $wpshop_category_products = wpshop_categories::get_product_of_category($_GET['tag_ID']);
         $filterable_attributes_list = array();
         foreach ($wpshop_category_products as $wpshop_category_product) {
             $elementId = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             if (!empty($elementId)) {
                 $product_attributes = wpshop_attributes::get_attribute_list_for_item($elementId, $wpshop_category_product);
                 if (!empty($product_attributes)) {
                     foreach ($product_attributes as $key => $product_attribute) {
                         if (!empty($product_attribute) && !empty($product_attribute->is_filterable) && strtolower(__($product_attribute->is_filterable, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) {
                             if (!array_key_exists($product_attribute->attribute_id, $filterable_attributes_list)) {
                                 $filterable_attributes_list[$product_attribute->attribute_id] = $product_attribute;
                                 $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_ID'] = $product_attribute->attribute_id;
                                 $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_NAME'] = __($product_attribute->frontend_label, 'wpshop');
                                 if (!empty($category_meta_information) && !empty($category_meta_information['wpshop_category_filterable_attributes']) && array_key_exists($product_attribute->attribute_id, $category_meta_information['wpshop_category_filterable_attributes'])) {
                                     $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_CHECKED'] = 'checked="checked"';
                                 } else {
                                     $sub_tpl_component['CATEGORY_FILTERABLE_ATTRIBUTE_CHECKED'] = '';
                                 }
                                 $tpl_component['CATEGORY_FILTERABLE_ATTRIBUTES'] .= wpshop_display::display_template_element('wpshop_category_filterable_attribute_element', $sub_tpl_component, array(), 'admin');
                                 unset($sub_tpl_component);
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $tpl_component['CATEGORY_TAG_ID'] = 1;
     }
     $output = wpshop_display::display_template_element('wpshop_category_edit_interface_admin', $tpl_component, array(), 'admin');
     echo $output;
 }
コード例 #10
0
    /**
     *	Return the page content to add a new item
     *
     *	@return string The html code that output the interface for adding a nem item
     */
    function unit_group_edition($itemToEdit = '')
    {
        global $attribute_displayed_field;
        $dbFieldList = wpshop_database::fields_to_input(WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
        $editedItem = '';
        $_REQUEST['action'] = 'save_new_attribute_unit_group';
        if ($itemToEdit != '') {
            $editedItem = self::get_unit_group($itemToEdit);
            $_REQUEST['action'] = 'update_attribute_unit_group';
        }
        $the_form_content_hidden = $the_form_general_content = $the_form_option_content = '';
        foreach ($dbFieldList as $input_key => $input_def) {
            $pageAction = isset($_REQUEST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_action']) : '';
            $requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['name']]) ? wpshop_tools::varSanitizer($_REQUEST[self::currentPageCode][$input_def['name']]) : '';
            $currentFieldValue = $input_def['value'];
            if (is_object($editedItem)) {
                $currentFieldValue = $editedItem->{$input_def}['name'];
            } elseif ($pageAction != '' && $requestFormValue != '') {
                $currentFieldValue = $requestFormValue;
            }
            $input_def['value'] = $currentFieldValue;
            $input_def['value'] = __(str_replace("\\", "", $input_def['value']), 'wpshop');
            $the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
            if ($input_def['type'] != 'hidden') {
                $label = 'for="' . $input_def['name'] . '"';
                if ($input_def['type'] == 'radio' || $input_def['type'] == 'checkbox') {
                    $label = '';
                }
                $input = '
	<div class="wpshop_cls" >
		<div class="wpshop_form_label wpshop_' . self::currentPageCode . '_' . $input_def['name'] . '_label alignleft" >
			<label ' . $label . ' >' . __($input_def['name'], 'wpshop') . '</label>
		</div>
		<div class="wpshop_form_input wpshop_' . self::currentPageCode . '_' . $input_def['name'] . '_input alignleft" >
			' . $the_input . '
		</div>
	</div>';
                if (substr($input_def['name'], 0, 3) == 'is_') {
                    $the_form_option_content .= $input;
                } else {
                    $the_form_general_content .= $input;
                }
            } else {
                $the_form_content_hidden .= '
	' . $the_input;
            }
        }
        $the_form = '
<form name="' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_form" id="' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_form" method="post" action="' . WPSHOP_AJAX_FILE_URL . '" >
' . wpshop_form::form_input('action', 'action', $_REQUEST['action'], 'hidden') . '
' . wpshop_form::form_input('post', 'post', 'true', 'hidden') . '
' . wpshop_form::form_input('elementCode', 'elementCode', 'attribute_unit_management', 'hidden') . '
' . wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no', 'hidden') . '
	' . $the_form_content_hidden . '' . $the_form_general_content . '
	<input type="button" value="' . __('Retour', 'wpshop') . '" class="button-primary alignright" name="cancel_unit_group_edition" id="cancel_unit_group_edition" />
	<input type="submit" value="' . __('Save', 'wpshop') . '" class="button-primary alignright" name="save_new_unit_group" id="save_new_unit_group" />
</form>
<script type="text/javascript" >
	wpshop(document).ready(function(){
		wpshopMainInterface("' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '", "' . __('Are you sure you want to quit this page? You will loose all current modification', 'wpshop') . '", "' . __('Are you sure you want to delete this unit group?', 'wpshop') . '");

		jQuery("#wpshop_unit_list_tab").hide();

		jQuery("#cancel_unit_group_edition").click(function(){
			jQuery("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, {
				"post": "true",
				"elementCode": "attribute_unit_management",
				"action": "load_attribute_unit_groups"
			});
		});

		jQuery("#' . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . '_form").ajaxForm({
			target: "#wpshop_unit_group_list"
		});
	});
</script>';
        return $the_form;
    }
コード例 #11
0
 /**
  * AJAX - Valid Checkout step four
  */
 function wps_checkout_valid_step_five()
 {
     $status = false;
     $response = '';
     $payment_method = !empty($_POST['wps-payment-method']) ? wpshop_tools::varSanitizer($_POST['wps-payment-method']) : null;
     $order_id = !empty($_SESSION['cart']['order_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0;
     $customer_comment = !empty($_POST['wps-customer-comment']) ? wpshop_tools::varSanitizer($_POST['wps-customer-comment']) : null;
     $terms_of_sale_checking = isset($_POST['terms_of_sale_indicator']) && !empty($_POST['terms_of_sale']) || !empty($_POST['terms_of_sale']) || !isset($_POST['terms_of_sale_indicator']) && empty($_POST['terms_of_sale']) ? true : false;
     if ($terms_of_sale_checking) {
         if (!empty($payment_method)) {
             /** Check if the payment method exist for the shop **/
             $payment_option = get_option('wps_payment_mode');
             if (!empty($payment_option) && !empty($payment_option['mode']) && array_key_exists($payment_method, $payment_option['mode']) && !empty($payment_option['mode'][$payment_method]['active'])) {
                 $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']);
                 if (!empty($order_id) && !empty($customer_comment)) {
                     wp_update_post(array('ID' => $order_id, 'post_excerpt' => $customer_comment));
                 }
                 $permalink_option = get_option('permalink_structure');
                 $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
                 $response = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6';
                 $_SESSION['payment_method'] = $payment_method;
                 $status = true;
                 //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);
             } else {
                 $response = '<div class="wps-alert-error">' . __('This payment method is unavailable', 'wpshop') . '</div>';
             }
         } else {
             $response = '<div class="wps-alert-error">' . __('You must choose a payment method', 'wpshop') . '</div>';
         }
     } else {
         $response = '<div class="wps-alert-error">' . __('You must accept the terms of sale to order', 'wpshop') . '</div>';
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     die;
 }
コード例 #12
0
 /**
  * AJAX - Vérifie si le produit sur le point d'être ajouté à la commande est un produit simple ou un produit composé / Check if the selected produt is a simple one or a combined one
  */
 function ajax_pos_check_product_type()
 {
     $product_type = 'simple';
     $product_id = !empty($_POST['product_id']) ? wpshop_tools::varSanitizer($_POST['product_id']) : null;
     if (!empty($product_id)) {
         $product_post_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
         if (!empty($product_post_meta)) {
             $product_type = 'variations';
         }
     }
     wp_die(json_encode(array('product_type' => $product_type)));
 }
コード例 #13
0
 /**
  * AJAX - Calculate Shipping cost
  */
 function wps_calculate_shipping_cost()
 {
     $status = false;
     $result = '';
     $chosen_method = !empty($_POST['chosen_method']) ? wpshop_tools::varSanitizer($_POST['chosen_method']) : null;
     if (!empty($chosen_method)) {
         $_SESSION['shipping_method'] = $chosen_method;
         $wps_cart = new wps_cart();
         $order = $wps_cart->calcul_cart_information(array());
         $wps_cart->store_cart_in_session($order);
         $status = true;
     }
     $response = array('status' => $status);
     echo json_encode($response);
     die;
 }
コード例 #14
0
<?php

/*	Wordpress - Main bootstrap file that load wordpress basic files	*/
require_once '../../../../../wp-load.php';
header('Content-Type: text/html; charset=' . get_bloginfo('charset'));
$content = $content_explanation = '';
$type = isset($_GET['type']) ? wpshop_tools::varSanitizer($_GET['type']) : null;
$post_type = isset($_GET['post_type']) ? wpshop_tools::varSanitizer($_GET['post_type']) : null;
$display_option_display_type = true;
$display_option_grouped = true;
$display_search_form = true;
if (!empty($type)) {
    switch ($type) {
        case 'attribute_value':
            $display_option_grouped = false;
            $display_search_form = false;
            $display_option_grouped = false;
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_att_val attid';
            $content = wpshop_attributes::get_attribute_list(null, $type, $post_type);
            break;
        case 'categories':
            $content = wpshop_categories::product_list_cats(true);
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_category cid';
            ob_start();
            ?>
			<p><?php 
            _e('Shortcode options', 'wpshop');
            ?>
</p>
			<div id="wpshop_wysiwyg_shortcode_categorie_options_container" >
				<input type="checkbox" name="wpshop_wysiwyg_shortcode_options[]" id="wpshop_wysiwyg_shortcode_options_categorie_display_product" class="wpshop_wysiwyg_shortcode_options wpshop_wysiwyg_shortcode_options_categories_display_product" value="only_cat" checked ><label for="wpshop_wysiwyg_shortcode_options_categorie_display_product" > <?php 
コード例 #15
0
ファイル: invoice.php プロジェクト: pronoSoupe/pronobo_soupe
<?php

/*	Wordpress - Ajax functionnality activation	*/
DEFINE('DOING_AJAX', true);
/*	Wordpress - Main bootstrap file that load wordpress basic files	*/
require_once '../../../../wp-load.php';
/*	Wordpress - Admin page that define some needed vars and include file	*/
require_once ABSPATH . 'wp-admin/includes/admin.php';
$order_id = !empty($_GET['order_id']) ? wpshop_tools::varSanitizer($_GET['order_id']) : null;
$invoice_ref = !empty($_GET['invoice_ref']) ? wpshop_tools::varSanitizer($_GET['invoice_ref']) : null;
$mode = !empty($_GET['mode']) ? wpshop_tools::varSanitizer($_GET['mode']) : 'html';
$is_credit_slip = !empty($_GET['credit_slip']) ? wpshop_tools::varSanitizer($_GET['credit_slip']) : null;
$user_id = get_current_user_id();
if (!empty($order_id) && $user_id != 0) {
    /**	Order reading	*/
    $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
    /**	Start invoice display	*/
    if (!empty($is_credit_slip)) {
        $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref, 'credit_slip');
    } else {
        $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref);
    }
    if ($mode == 'pdf') {
        require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php';
        try {
            //$html_content = wpshop_display::display_template_element('invoice_print_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
            $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
            $html2pdf = new HTML2PDF('P', 'A4', 'fr');
            $html2pdf->setDefaultFont('Arial');
            $html2pdf->writeHTML($html_content);
            $html2pdf->Output('order_' . $order_id . '.pdf', 'D');
コード例 #16
0
 /** AJAX - action to apply coupon **/
 function wps_apply_coupon()
 {
     $status = false;
     $response = '';
     $coupon = !empty($_POST['coupon_code']) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null;
     if (!empty($coupon)) {
         $wps_coupon_ctr = new wps_coupon_ctr();
         $result = $wps_coupon_ctr->applyCoupon($_REQUEST['coupon_code']);
         if ($result['status'] === true) {
             $order = $this->calcul_cart_information(array());
             $this->store_cart_in_session($order);
             $status = true;
             $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>';
         } else {
             $response = '<div class="wps-alert-error">' . $result['message'] . '</div>';
         }
     } else {
         $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>';
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     die;
 }
コード例 #17
0
 /**
  * Display the installer interface
  */
 function installer_main_page()
 {
     $current_step = !empty($_GET['wps-installation-step']) ? wpshop_tools::varSanitizer($_GET['wps-installation-step']) : $this->current_installation_step;
     $steps = unserialize(WPSINSTALLER_STEPS);
     /**	Get the defined shop type in order to display the different element to	*/
     $wps_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
     /** Check the current step to display */
     $current_step_output = '';
     $the_step_file = '';
     switch ($current_step) {
         case 2:
             $the_step_file = 'step_two';
             break;
         default:
             $the_step_file = 'step_one';
             break;
     }
     /**	Create display for current step	*/
     ob_start();
     require_once wpshop_tools::get_template_part(WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", $the_step_file);
     $current_step_output = ob_get_contents();
     ob_end_clean();
     require_once wpshop_tools::get_template_part(WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "installer");
 }
コード例 #18
0
 /**
  * Add Credit informations on order
  * @param array $order_metadata
  * @param array $posted_datas
  */
 function wps_credit_actions_on_order_save($order_metadata, $posted_datas)
 {
     if (!empty($posted_datas['markascanceled_order_hidden_indicator']) && wpshop_tools::varSanitizer($posted_datas['markascanceled_order_hidden_indicator']) == 'canceled' || !empty($posted_datas['markasrefunded_order_hidden_indicator']) && wpshop_tools::varSanitizer($posted_datas['markasrefunded_order_hidden_indicator']) == 'refunded' || !empty($posted_datas['resendordertocustomer_order_hidden_indicator']) && wpshop_tools::varSanitizer($posted_datas['resendordertocustomer_order_hidden_indicator']) == 'resended') {
         if (empty($posted_datas['resendordertocustomer_order_hidden_indicator'])) {
             // Make a credit
             $this->create_an_credit($posted_datas['post_ID']);
             if (!empty($posted_datas['markascanceled_order_hidden_indicator'])) {
                 $order_metadata['order_status'] = wpshop_tools::varSanitizer($posted_datas['markascanceled_order_hidden_indicator']);
             } elseif (!empty($posted_datas['markasrefunded_order_hidden_indicator'])) {
                 $order_metadata['order_status'] = wpshop_tools::varSanitizer($posted_datas['markasrefunded_order_hidden_indicator']);
             }
             $order_metadata['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0);
             $order_metadata['order_payment']['refunded_action']['author'] = get_current_user_id();
         } elseif (wpshop_tools::varSanitizer($posted_datas['resendordertocustomer_order_hidden_indicator']) == 'resended') {
             $order_id = $posted_datas['post_ID'];
             $order_info = get_post_meta($order_id, '_order_info', true);
             $user_data = get_userdata($order_metadata['customer_id']);
             $shipping_mode_option = get_option('wps_shipping_mode');
             $shipping_method = !empty($order_metadata['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_metadata['order_payment']['shipping_method'], $shipping_mode_option['modes']) ? $shipping_mode_option['modes'][$order_metadata['order_payment']['shipping_method']]['name'] : (!empty($order_metadata['order_payment']['shipping_method']) ? $order_metadata['order_payment']['shipping_method'] : '');
             $email = !empty($user_data) && !empty($user_data->user_email) ? $user_data->user_email : '';
             //echo '<pre>'; print_r($email); echo '</pre>'; exit();
             $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'] : '';
             $allow_send_invoice = get_option('wpshop_send_invoice');
             $payment_methods = new wpshop_payment();
             $key = count($order_metadata['order_payment']['received']) - 1;
             $invoice_attachment_file = !empty($allow_send_invoice) ? wpshop_modules_billing::generate_invoice_for_email($order_id, $order_metadata['order_payment']['received'][$key]['invoice_ref']) : '';
             $wps_message = new wps_message_ctr();
             $wps_message->wpshop_prepared_email($email, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE', array('order_key' => $order_metadata['order_key'], 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'order_date' => $order_metadata['order_date'], 'order_shipping_method' => $shipping_method), array(), $invoice_attachment_file);
         }
     }
     return $order_metadata;
 }
コード例 #19
0
 /**
  * AJAX - Traite la commande / Process checkout
  */
 function wps_pos_process_checkout()
 {
     $status = false;
     $output = $message = '';
     $order_id = !empty($_POST['order_id']) ? wpshop_tools::varSanitizer($_POST['order_id']) : null;
     $new_order = empty($_POST['order_id']);
     $payment_method = !empty($_POST['wpspos-payment-method']) ? wpshop_tools::varSanitizer($_POST['wpspos-payment-method']) : null;
     $customer_id = !empty($_POST['customer_id']) ? wpshop_tools::varSanitizer($_POST['customer_id']) : !empty($_SESSION['cart']['customer_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['customer_id']) : null;
     $payment_amount = !empty($_POST['wps-pos-total-order-amount']) ? wpshop_tools::varSanitizer($_POST['wps-pos-total-order-amount']) : null;
     $received_payment_amount = !empty($_POST['wpspos-order-received-amount']) ? wpshop_tools::varSanitizer($_POST['wpspos-order-received-amount']) : $payment_amount;
     if (!empty($customer_id)) {
         if (empty($order_id) && !empty($payment_method)) {
             $_SESSION['shipping_method'] = 'default_shipping_mode_for_pos';
             $order_id = wpshop_checkout::process_checkout($payment_method, '', $customer_id, $_SESSION['billing_address'], $_SESSION['shipping_address']);
             wp_update_post(array('ID' => $order_id, 'post_parent' => get_current_user_id()));
         }
         if (!empty($order_id)) {
             $status = true;
             if (!empty($received_payment_amount)) {
                 $params_array = array('method' => $payment_method, 'waited_amount' => $payment_amount, 'status' => 'payment_received', 'author' => $customer_id, 'payment_reference' => '', 'date' => current_time('mysql', 0), 'received_amount' => 'money' == $payment_method && number_format((double) $received_payment_amount, 2, '.', '') > number_format((double) $payment_amount, 2, '.', '') ? $payment_amount : $received_payment_amount);
                 wpshop_payment::check_order_payment_total_amount($order_id, $params_array, 'completed');
             }
             /**	Get order content	*/
             $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
             ob_start();
             require_once wpshop_tools::get_template_part(WPSPOS_DIR, WPSPOS_TEMPLATES_MAIN_DIR, 'backend/order', 'order', 'complete');
             $output = ob_get_contents();
             ob_end_clean();
             /**	Empty the cart	*/
             /*if ( !empty( $order_postmeta ) && !empty( $order_postmeta['order_status'] ) && ( 'completed' ==  $order_postmeta['order_status'] ) ) {
             			$wps_cart = new wps_cart();
             			$wps_cart->empty_cart();
             		}*/
             $message = __('Order have been saved', 'wps-pos-i18n');
         } else {
             $message = __('No order have been found', 'wps-pos-i18n');
         }
         /*}
         		else {
         			$message = __( 'Please choose a payment method for order', 'wps-pos-i18n' );
         		}*/
     } else {
         $message = __('No customer has been selected for current order', 'wps-pos-i18n');
     }
     wp_die(json_encode(array('status' => $status, 'output' => $output, 'message' => $message)));
 }
コード例 #20
0
    /**
     * Display the differents forms fields
     * @param string $type : Type of address
     * @param string $first : Customer first address ?
     * @param string $referer : Referer website page
     * @param string $admin : Display this form in admin panel
     */
    function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '')
    {
        global $wpshop, $wpshop_form, $wpdb;
        $choosen_address = get_option('wpshop_billing_address');
        $shipping_address = get_option('wpshop_shipping_address_choice');
        $output_form_fields = $form_model = '';
        $user_id = !empty($other_customer) ? $other_customer : get_current_user_id();
        if (empty($type)) {
            $type = $choosen_address['choice'];
        }
        $result = wps_address::get_addresss_form_fields_by_type($type, $id);
        /** Check if it's shipping or billing **/
        if ($type == $choosen_address['choice']) {
            $form_model = !empty($choosen_address['display_model']) ? $choosen_address['display_model'] : null;
        } elseif ($type == $shipping_address['choice']) {
            $form_model = !empty($shipping_address['display_model']) ? $shipping_address['display_model'] : null;
        }
        $form = $result[$type];
        // Take the post id to make the link with the post meta of  address
        $values = array();
        // take the address informations
        $current_item_edited = !empty($id) ? (int) wpshop_tools::varSanitizer($id) : null;
        foreach ($form as $group_id => $group_fields) {
            if (empty($options) || !empty($options) && $options['title']) {
                $output_form_fields .= '<h2>' . __($group_fields['name'], 'wpshop') . '</h2>';
            }
            $end_line_indicator = 0;
            $fields_limit_per_line = -1;
            foreach ($group_fields['content'] as $key => $field) {
                $attribute_def = wpshop_attributes::getElement($field['name'], $element_status = "'valid'", $field_to_search = 'code');
                /** Grid opening **/
                if (!empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1) {
                    $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]);
                    $current_attribute_key = array_search('attribute_' . $attribute_def->id, $form_model[$group_id]);
                    if ($current_attribute_key > $current_key) {
                        /** Define limit **/
                        if (in_array('wps-attribute-end-line-' . ($end_line_indicator + 1), $form_model[$group_id])) {
                            $next_key = array_search('wps-attribute-end-line-' . ($end_line_indicator + 1), $form_model[$group_id]);
                            $fields_limit_per_line = $next_key - $current_key - 1;
                            $fields_limit_per_line = $fields_limit_per_line > 6 ? 6 : $fields_limit_per_line;
                        } else {
                            $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]);
                            $end_tab = count($form_model[$group_id]) - 1;
                            $fields_limit_per_line = $end_tab - $current_key - 1;
                            $fields_limit_per_line = $fields_limit_per_line > 6 ? 6 : $fields_limit_per_line;
                        }
                        if (!empty($fields_limit_per_line) && $fields_limit_per_line != -1) {
                            if ($fields_limit_per_line == 1) {
                                $output_form_fields .= '<div class="wps-row">';
                            } else {
                                $output_form_fields .= '<div class="wps-row wps-gridwrapper' . $fields_limit_per_line . '-padded">';
                            }
                        }
                    }
                }
                if (empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array($key, $options['field_to_hide'])) {
                    $attributeInputDomain = 'attribute[' . $type . '][' . $field['data_type'] . ']';
                    // Test if there is POST var or if user have already fill his address infos and fill the fields with these infos
                    if (!empty($_POST)) {
                        $referer = !empty($_POST['referer']) ? $_POST['referer'] : '';
                        if (!empty($form['id']) && !empty($field['name']) && isset($_POST[$form['id'] . "_" . $field['name']])) {
                            $value = $_POST[$form['id'] . "_" . $field['name']];
                        }
                    }
                    // Fill Automaticly some fields when it's an address creation
                    switch ($field['name']) {
                        case 'address_title':
                            if (empty($field['value'])) {
                                /** Count Billing and shipping address **/
                                $billing_address_count = $shipping_address_count = 1;
                                if (get_current_user_id() != 0) {
                                    $addresses = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft'));
                                    if (!empty($addresses)) {
                                        foreach ($addresses as $address) {
                                            $address_type = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true);
                                            if (!empty($address_type)) {
                                                if (!empty($shipping_address_choice['choice']) && $address_type == $shipping_address_choice['choice']) {
                                                    $shipping_address_count++;
                                                } else {
                                                    $billing_address_count++;
                                                }
                                            }
                                        }
                                    }
                                }
                                $field['value'] = $type == $choosen_address['choice'] ? __('Billing address', 'wpshop') . ($billing_address_count > 1 ? ' ' . $billing_address_count : '') : __('Shipping address', 'wpshop') . ($shipping_address_count > 1 ? ' ' . $shipping_address_count : '');
                            }
                            break;
                        case 'address_last_name':
                            if (empty($field['value'])) {
                                $usermeta_last_name = get_user_meta($user_id, 'last_name', true);
                                $field['value'] = !empty($usermeta_last_name) ? $usermeta_last_name : '';
                            }
                            break;
                        case 'address_first_name':
                            if (empty($field['value'])) {
                                $usermeta_first_name = get_user_meta($user_id, 'first_name', true);
                                $field['value'] = !empty($usermeta_first_name) ? $usermeta_first_name : '';
                            }
                            break;
                        case 'address_user_email':
                            if (empty($field['value'])) {
                                $user_infos = get_userdata($user_id);
                                $field['value'] = !empty($user_infos) && !empty($user_infos->user_email) ? $user_infos->user_email : '';
                            }
                            break;
                        default:
                            $field['value'] = !empty($field['value']) ? $field['value'] : '';
                            break;
                    }
                    /** Fill fields if $_POST exist **/
                    if (!empty($_POST['attribute'][$type][$field['data_type']][$field['name']])) {
                        $field['value'] = $_POST['attribute'][$type][$field['data_type']][$field['name']];
                    }
                    if ($field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop')) {
                        $value = __('Billing address', 'wpshop');
                    } elseif ($field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop')) {
                        $value = __('Shipping address', 'wpshop');
                    }
                    if (!empty($special_values[$field['name']])) {
                        $field['value'] = $special_values[$field['name']];
                    }
                    $template = 'wpshop_account_form_input';
                    if ($field['type'] == 'hidden') {
                        $template = 'wpshop_account_form_hidden_input';
                    }
                    if ($field['frontend_verification'] == 'country') {
                        $field['type'] = 'select';
                        /** display a country list **/
                        $countries_list = unserialize(WPSHOP_COUNTRY_LIST);
                        $possible_values = array_merge(array('' => __('Choose a country')), $countries_list);
                        $limit_countries_list = get_option('wpshop_limit_country_list');
                        $default_country_choice = get_option('wpshop_country_default_choice');
                        if (!empty($limit_countries_list)) {
                            $possible_values = array();
                            if (count($limit_countries_list) > 1) {
                                $possible_values[''] = __('Choose a country');
                            }
                            foreach ($limit_countries_list as $country_code) {
                                if (!empty($countries_list) && !empty($countries_list[$country_code])) {
                                    $possible_values[$country_code] = $countries_list[$country_code];
                                }
                            }
                        }
                        $field['value'] = !empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values) ? $default_country_choice : '';
                        $field['possible_value'] = $possible_values;
                        $field['valueToPut'] = 'index';
                    }
                    $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option'])));
                    $input_tpl_component = array();
                    //$input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class;
                    $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = $field['type'] != 'hidden' ? stripslashes(__($field['label'], 'wpshop')) . ($field['required'] == 'yes' ? ' <em>*</em>' : '') : '';
                    $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"';
                    $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain);
                    //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component);
                    $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop');
                    unset($input_tpl_component);
                    if ($field['_need_verification'] == 'yes') {
                        $field['name'] = $field['name'] . '2';
                        $field['id'] = $field['id'] . '2';
                        $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option'])));
                        $input_tpl_component = array();
                        $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __($field['label'], 'wpshop') . ($field['required'] == 'yes' && !is_admin() || $field['name'] == 'address_user_email' && is_admin() ? ' <span class="required">*</span>' : '');
                        $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"';
                        $input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class;
                        $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf(__('Confirm %s', 'wpshop'), strtolower(__($field['label'], 'wpshop'))) . ($field['required'] == 'yes' && !is_admin() ? ' <span class="required">*</span>' : '');
                        $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain) . $field['options'];
                        //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component);
                        $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop');
                        unset($input_tpl_component);
                    }
                }
                /** Grid closing **/
                if ($fields_limit_per_line != -1 && !empty($fields_limit_per_line)) {
                    $fields_limit_per_line--;
                    if ($fields_limit_per_line == 0) {
                        $output_form_fields .= '</div>';
                        $fields_limit_per_line = -1;
                        $end_line_indicator++;
                    }
                }
            }
        }
        if ($type == $choosen_address['choice']) {
            $output_form_fields .= '<input type="hidden" name="billing_address" value="' . $choosen_address['choice'] . '" />';
        }
        $shipping_address_options = get_option('wpshop_shipping_address_choice');
        if ($type == $shipping_address_options['choice']) {
            $output_form_fields .= '<input type="hidden" name="shipping_address" value="' . $shipping_address_options['choice'] . '" />';
        }
        $output_form_fields .= '<input type="hidden" name="edit_other_thing" value="' . false . '" /><input type="hidden" name="referer" value="' . $referer . '" />
								<input type="hidden" name="type_of_form" value="' . $type . '" /><input type="hidden" name="attribute[' . $type . '][item_id]" value="' . $current_item_edited . '" />';
        $output_form_fields .= $user_id != get_current_user_id() ? '<input type="hidden" name="user[customer_id]" value="' . $user_id . '" />' : '';
        if (empty($first)) {
            $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => ''));
        }
        return $output_form_fields;
    }
コード例 #21
0
<?php

/*	Wordpress - Ajax functionnality activation	*/
DEFINE('DOING_AJAX', true);
/*	Wordpress - Specify that we are in wordpress admin	*/
DEFINE('WP_ADMIN', true);
/*	Wordpress - Main bootstrap file that load wordpress basic files	*/
require_once '../../../../wp-load.php';
/*	Wordpress - Admin page that define some needed vars and include file	*/
require_once ABSPATH . 'wp-admin/includes/admin.php';
$order_id = !empty($_GET['order_id']) ? wpshop_tools::varSanitizer($_GET['order_id']) : null;
$invoice_ref = !empty($_GET['credit_ref']) ? wpshop_tools::varSanitizer($_GET['credit_ref']) : null;
$mode = !empty($_GET['mode']) ? wpshop_tools::varSanitizer($_GET['mode']) : 'html';
// $is_credit_slip = (!empty($_GET['credit_slip'])) ? wpshop_tools::varSanitizer($_GET['credit_slip']) : null;
if (!empty($order_id)) {
    // 	/**	Order reading	*/
    $order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
    $html_content = wps_credit::generate_credit_slip($order_id, $invoice_ref);
    if ($mode == 'pdf') {
        require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php';
        try {
            $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
            $html2pdf = new HTML2PDF('P', 'A4', 'fr');
            $html2pdf->setDefaultFont('Arial');
            $html2pdf->writeHTML($html_content);
            $html2pdf->Output('order_' . $order_id . '.pdf', 'D');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    } else {
コード例 #22
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;
 }
コード例 #23
0
 /**
  * AJAX - Selection et affectation du client à la commande en cours / Set selected user as new order owner
  */
 function ajax_pos_customer_choice()
 {
     $response = array('status' => false, 'element_type' => 'customer', 'output' => '');
     $selected_customer = !empty($_POST) && !empty($_POST['customer']) && is_int((int) $_POST['customer']) ? wpshop_tools::varSanitizer($_POST['customer']) : null;
     if (!empty($selected_customer)) {
         $_SESSION['cart']['customer_id'] = $selected_customer;
         $response['status'] = true;
         /**	Affichage du client sélectionné pour la commande courante / Display selected customer account summary	*/
         ob_start();
         $this->display_selected_customer($selected_customer);
         $response['output'] = ob_get_contents();
         ob_end_clean();
     } else {
         $response['output'] = __('No customer has been selected, please choose a customer or create a new one before try to create a new order', 'wps-pos-i18n');
     }
     wp_die(json_encode($response));
 }
コード例 #24
0
 /**
  *	Return the different button to save the item currently being added or edited
  *
  *	@return string $currentPageButton The html output code with the different button to add to the interface
  */
 function getPageFormButton($element_id = 0)
 {
     $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add';
     $currentPageButton = '';
     //$currentPageButton .= '<h2 class="cancelButton alignleft" ><a href="' . admin_url('edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES.'&amp;page=' . self::getListingSlug()) . '" class="button add-new-h2" >' . __('Back', 'wpshop') . '</a></h2>';
     if ($action == 'add' && current_user_can('wpshop_add_attributes')) {
         $currentPageButton .= '<input type="button" class="button-primary" id="add" name="add" value="' . __('Add', 'wpshop') . '" />';
     } elseif (current_user_can('wpshop_edit_attributes')) {
         $currentPageButton .= '<input type="button" class="button-primary" id="save" name="save" value="' . __('Save', 'wpshop') . '" />';
     }
     $attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE);
     $attribute = self::getElement($element_id, "'valid', 'moderated', 'notused'", 'id');
     $attribute_code = !empty($attribute->code) ? $attribute->code : '';
     if (current_user_can('wpshop_delete_attributes') && $action != 'add' && !in_array($attribute_code, $attribute_undeletable)) {
         $currentPageButton .= '<input type="button" class="button-secondary wpshop_delete_element_button wpshop_delete_element_button_' . self::currentPageCode . '" id="delete" name="delete" value="' . __('Delete', 'wpshop') . '" />';
     }
     return $currentPageButton;
 }
コード例 #25
0
 /**
  * AJAX - Load address form in Modal Box
  */
 function wps_load_address_form()
 {
     $response = '';
     $address_id = !empty($_POST['address_id']) ? wpshop_tools::varSanitizer($_POST['address_id']) : '';
     $address_type_id = !empty($_POST['address_type_id']) ? wpshop_tools::varSanitizer($_POST['address_type_id']) : '';
     $form_data = self::loading_address_form($address_type_id, $address_id, get_current_user_id());
     $response = $form_data[0];
     $title = $form_data[1];
     echo json_encode(array($response, $title));
     die;
 }
コード例 #26
0
function wps_hide_notice_messages()
{
    $status = false;
    $indicator = !empty($_POST['indicator']) ? wpshop_tools::varSanitizer($_POST['indicator']) : null;
    if (!empty($indicator)) {
        $user_id = get_current_user_id();
        $hide_notice_meta = get_user_meta($user_id, '_wps_hide_notice_messages_indicator', true);
        $hide_notice_meta = !empty($hide_notice_meta) ? $hide_notice_meta : array();
        $indicators = explode(',', $indicator);
        if (!empty($indicators) && is_array($indicators)) {
            foreach ($indicators as $i) {
                if (!empty($i)) {
                    $hide_notice_meta[$i] = true;
                }
            }
        }
        update_user_meta($user_id, '_wps_hide_notice_messages_indicator', $hide_notice_meta);
        $status = true;
    }
    $response = array('status' => $status);
    echo json_encode($response);
    die;
}
コード例 #27
0
 /**
  * Display Orders moment in the day Statistics
  */
 function wps_statistics_orders_moment($args = array('choosen_day' => '', 'return' => false))
 {
     $begin_date = !empty($_POST['begin_date']) ? wpshop_tools::varSanitizer($_POST['begin_date']) : date('Y-m-d', strtotime('1 months ago'));
     $end_date = !empty($_POST['end_date']) ? wpshop_tools::varSanitizer($_POST['end_date']) : date('Y-m-d');
     $datadate = $this->wps_stats_mdl->wps_get_orders_by_hours($begin_date, $end_date, !empty($args['choosen_day']) ? $args['choosen_day'] : '');
     $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     ob_start();
     require wpshop_tools::get_template_part(WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, "backend", "wps_statistics_orders_moment");
     $output = ob_get_contents();
     ob_end_clean();
     if (!empty($args) && !empty($args['return']) && $args['return']) {
         return $output;
     } else {
         echo $output;
     }
 }
コード例 #28
0
 /**
  * Get the shipping cost for the current cart
  *
  * @param integer $nb_of_items The number of items in cart
  * @param float $total_cart The amount of the cart
  * @param float $total_shipping_cost The amount of the shipping cost calculate from the sum of shipping cost for each product in cart
  * @param float $total_weight The total weight of all product in cart
  *
  * @return number|string The sipping cost for the current cart
  */
 function get_shipping_cost($nb_of_items, $total_cart, $total_shipping_cost, $total_weight, $selected_method = '')
 {
     global $wpdb;
     $shipping_mode_option = get_option('wps_shipping_mode');
     if (!empty($selected_method)) {
         $chosen_shipping_mode = $selected_method;
     } else {
         $chosen_shipping_mode = !empty($_SESSION['shipping_method']) ? wpshop_tools::varSanitizer($_SESSION['shipping_method']) : 'default_choice';
     }
     $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
     if (!empty($default_weight_unity)) {
         $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
         $weight_unity = $wpdb->get_var($query);
         if (!empty($weight_unity) && $weight_unity == 'kg') {
             $total_weight = $total_weight * 1000;
         }
     }
     if (!empty($_SESSION['shipping_method']) && $_SESSION['shipping_method'] == 'shipping-partners' || !empty($_SESSION['wps-pos-addon'])) {
         return 0;
     }
     /** Take the selected shipping mode **/
     $selected_shipping_mode_config = $chosen_shipping_mode == 'default_choice' ? $shipping_mode_option['modes']['default_shipping_mode'] : (!empty($shipping_mode_option['modes'][$chosen_shipping_mode]) ? $shipping_mode_option['modes'][$chosen_shipping_mode] : '');
     $shipping_cost = $total_shipping_cost;
     /** Free Shipping **/
     if (!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_shipping'])) {
         $shipping_cost = 0;
     } elseif (!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format($total_cart, 2, '.', '')) {
         $shipping_cost = 0;
     } else {
         /** Check Custom Shipping Cost **/
         if (!empty($_SESSION['shipping_address']) && !empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active'])) {
             $address_infos = get_post_meta($_SESSION['shipping_address'], '_wpshop_address_metadata', true);
             $country = !empty($address_infos['country']) ? $address_infos['country'] : '';
             /** Check Active Postcode option **/
             if (!empty($selected_shipping_mode_config['active_cp'])) {
                 $postcode = $address_infos['postcode'];
                 if (array_key_exists($country . '-' . $postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees'])) {
                     $country = $country . '-' . $postcode;
                 } elseif (array_key_exists($country . '-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees'])) {
                     $country = $country . '-OTHERS';
                 }
             }
             $shipping_cost += $this->calculate_custom_shipping_cost($country, array('weight' => $total_weight, 'price' => $total_cart), $selected_shipping_mode_config['custom_shipping_rules']['fees'], $chosen_shipping_mode);
         }
         /** Min- Max config **/
         if (!empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate'])) {
             if (!empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min']) {
                 $shipping_cost = $selected_shipping_mode_config['min_max']['min'];
             } elseif (!empty($selected_shipping_mode_config['min_max']['max']) && $shipping_cost > $selected_shipping_mode_config['min_max']['max']) {
                 $shipping_cost = $selected_shipping_mode_config['min_max']['max'];
             }
         }
     }
     return $shipping_cost;
 }
コード例 #29
0
 /**
  * AJAX - Update cart informations
  */
 function wps_orders_update_cart_informations()
 {
     $status = false;
     $order_id = !empty($_POST['order_id']) ? intval($_POST['order_id']) : '';
     $shipping_cost = !empty($_POST['shipping_cost']) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : '';
     $discount_value = !empty($_POST['discount_amount']) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : '';
     $discount_type = !empty($_POST['discount_type']) ? wpshop_tools::varSanitizer($_POST['discount_type']) : '';
     if (!empty($order_id)) {
         $order_meta = get_post_meta($order_id, '_order_postmeta', true);
         $order_meta['order_shipping_cost'] = $shipping_cost;
         //Add discounts if exists
         if (!empty($discount_value) && !empty($discount_type)) {
             $order_meta['order_discount_type'] = $discount_type;
             $order_meta['order_discount_value'] = $discount_value;
         }
         $wps_cart = new wps_cart();
         $order_meta = $wps_cart->calcul_cart_information(array(), '', $order_meta, true);
         update_post_meta($order_id, '_order_postmeta', $order_meta);
         $status = true;
     }
     echo json_encode(array('status' => $status));
     wp_die();
 }
コード例 #30
-1
 /**
  * ACCOUNT - Save account informations
  */
 function wps_save_account_informations()
 {
     global $wpdb;
     global $wpshop;
     $status = false;
     $response = '';
     $exclude_user_meta = array('user_email', 'user_pass');
     $wps_entities = new wpshop_entities();
     $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
     $user_id = get_current_user_id();
     if (!empty($element_id) && !empty($user_id)) {
         $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
         $cid = $wpdb->get_var($query);
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
         $attribute_set_id = $wpdb->get_var($query);
         if (!empty($attribute_set_id)) {
             $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
             foreach ($group as $attribute_sets) {
                 foreach ($attribute_sets as $attribute_set_field) {
                     $validate = $wpshop->validateForm($attribute_set_field['content'], $_POST['attribute']);
                     if (empty($wpshop->errors)) {
                         $user_name = !empty($_POST['attribute']['varchar']['user_login']) ? $_POST['attribute']['varchar']['user_login'] : $_POST['attribute']['varchar']['user_email'];
                         $user_pass = !empty($_POST['attribute']['varchar']['user_pass']) ? $_POST['attribute']['varchar']['user_pass'] : '';
                         $wpshop_attributes = new wpshop_attributes();
                         foreach ($attribute_set_field['content'] as $attribute) {
                             $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code');
                             if (!in_array($attribute['name'], $exclude_user_meta)) {
                                 update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']]));
                             } else {
                                 wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])));
                             }
                             //Save data in attribute tables, ckeck first if exist to know if Insert or Update
                             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $cid, $attribute_def->id);
                             $checking_attribute_exist = $wpdb->get_results($query);
                             if (!empty($checking_attribute_exist)) {
                                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])), array('entity_type_id' => $element_id, 'entity_id' => $cid, 'attribute_id' => $attribute_def->id));
                             } else {
                                 $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('entity_type_id' => $element_id, 'attribute_id' => $attribute_def->id, 'entity_id' => $cid, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])));
                             }
                         }
                         /** Update newsletter user preferences **/
                         $newsletter_preferences = array();
                         if (!empty($_POST['newsletters_site'])) {
                             $newsletter_preferences['newsletters_site'] = 1;
                         }
                         if (!empty($_POST['newsletters_site_partners'])) {
                             $newsletter_preferences['newsletters_site_partners'] = 1;
                         }
                         update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
                         $status = true;
                     } else {
                         $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>';
                         foreach ($wpshop->errors as $error) {
                             $response .= '<li>' . $error . '</li>';
                         }
                         $response .= '</div>';
                     }
                 }
             }
         }
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     wp_die();
 }