function display_account_last_actions() { global $wpdb; $output = ''; $user_id = get_current_user_id(); if (!empty($user_id)) { $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $user_id); $orders = $wpdb->get_results($query); if (!empty($orders)) { $orders_list = ''; foreach ($orders as $order) { $order_meta = get_post_meta($order->ID, '_order_postmeta', true); $order_number = !empty($order_meta) && !empty($order_meta['order_key']) ? $order_meta['order_key'] : ''; $order_date = !empty($order_meta) && !empty($order_meta['order_date']) ? mysql2date(get_option('date_format'), $order_meta['order_date'], true) : ''; $order_amount = !empty($order_meta) && !empty($order_meta['order_key']) ? wpshop_tools::formate_number($order_meta['order_grand_total']) . ' ' . wpshop_tools::wpshop_get_currency(false) : ''; $order_available_status = unserialize(WPSHOP_ORDER_STATUS); $order_status = !empty($order_meta) && !empty($order_meta['order_status']) ? __($order_available_status[$order_meta['order_status']], 'wpshop') : ''; ob_start(); require wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard-resume-element"); $orders_list .= ob_get_contents(); ob_end_clean(); } ob_start(); require_once wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/", "frontend", "account/account-dashboard-resume"); $output = ob_get_contents(); ob_end_clean(); } } return $output; }
/** * Add product to the end user cart */ function ajax_wpshop_add_to_cart() { global $wpdb; $wpshop_cart = new wps_cart(); $product_id = isset($_POST['wpshop_pdt']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt'])) : null; $product_qty = isset($_POST['wpshop_pdt_qty']) ? intval(wpshop_tools::varSanitizer($_POST['wpshop_pdt_qty'])) : 1; $cart_option = get_option('wpshop_cart_option', array()); $wpshop_variation_selected = !empty($_POST['wps_pdt_variations']) ? $_POST['wps_pdt_variations'] : array(); $from_administration = !empty($_POST['from_admin']) ? true : false; $order_id = !empty($_POST['wps_orders_order_id']) ? wpshop_tools::varSanitizer($_POST['wps_orders_order_id']) : null; // Check Cart Animation $cart_animation_choice = !empty($cart_option) && !empty($cart_option['animation_cart_type']) ? $cart_option['animation_cart_type'] : null; if (!empty($cart_option['total_nb_of_item_allowed']) && $cart_option['total_nb_of_item_allowed'][0] == 'yes') { $wpshop_cart->empty_cart(); } // Prepare Product to be added to cart $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $wpshop_variation_selected); $product_to_add_to_cart = $formatted_product[0]; $new_pid = $formatted_product[1]; // Check cart Type $cart_type_for_adding = 'normal'; if (!empty($_POST['wpshop_cart_type'])) { switch (wpshop_tools::varSanitizer($_POST['wpshop_cart_type'])) { case 'quotation': $wpshop_cart_type = 'quotation'; break; default: $wpshop_cart_type = 'normal'; break; } } // Check Product image $product = get_post($product_id); $product_img = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="no picture" />'; if (!empty($product_id)) { if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($product_id); $parent_post = !empty($parent_def['parent_post']) ? $parent_def['parent_post'] : array(); $product_title = !empty($parent_post) && !empty($parent_post->post_title) ? $parent_post->post_title : ''; $product_description = !empty($parent_post) && !empty($parent_post->post_content) ? $parent_post->post_content : ''; $product_img = !empty($parent_post->ID) ? get_the_post_thumbnail($parent_post->ID, 'thumbnail') : ''; } else { $product_title = $product->post_title; $product_description = $product->post_content; $product_img = get_the_post_thumbnail($product_id, 'thumbnail'); } } if (!empty($_POST['wps_orders_from_admin']) && $_POST['wps_orders_from_admin'] == true) { $order_meta = get_post_meta($order_id, '_order_postmeta', true); $return = $wpshop_cart->add_to_cart($product_to_add_to_cart, array($new_pid => $product_qty), $wpshop_cart_type, array(), true, $order_meta, $order_id); echo json_encode(array(true)); die; } else { $return = $wpshop_cart->add_to_cart($product_to_add_to_cart, array($new_pid => $product_qty), $wpshop_cart_type); } if ($return == 'success') { $cart_page_url = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_cart_page_id'))); /** Template parameters */ $template_part = 'product_added_to_cart_message'; /** Build template */ $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { /* Include the old way template part */ ob_start(); require_once wpshop_display::get_template_file($tpl_way_to_take[1]); $succes_message_box = ob_get_contents(); ob_end_clean(); } else { $succes_message_box = wpshop_display::display_template_element($template_part, array('PRODUCT_ID' => $product_id)); } unset($tpl_component); $action_after_add = $cart_option['product_added_to_cart'][0] == 'cart_page' ? true : false; if ($wpshop_cart_type == 'quotation') { $action_after_add = $cart_option['product_added_to_quotation'][0] == 'cart_page' ? true : false; } /** Product Price **/ $product_price = ''; if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($product_to_add_to_cart)) { $idp = ''; if (!empty($product_to_add_to_cart[$new_pid]['variations']) && count($product_to_add_to_cart[$new_pid]['variations']) < 2) { $idp = $product_to_add_to_cart[$new_pid]['variations'][0]; } else { if (strstr($new_pid, '__')) { $idp = $new_pid; } else { $idp = $product_to_add_to_cart[$new_pid]['id']; } } if (!empty($idp)) { $default_currency = wpshop_tools::wpshop_get_currency(false); $price_piloting_option = get_option('wpshop_shop_price_piloting'); $pr = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? $_SESSION['cart']['order_items'][$new_pid]['item_pu_ht'] * $product_qty : $_SESSION['cart']['order_items'][$new_pid]['item_pu_ttc'] * $product_qty; $product_price = wpshop_tools::formate_number($pr) . $default_currency; } } /** Check if there are linked products **/ $related_products = get_post_meta($product_id, '_wpshop_product_related_products', true); $tpl_component = array(); $linked_products = ''; if (!empty($related_products)) { $linked_products = '<h2>' . __('Linked products', 'wpshop') . '</h2>'; $linked_products .= '<div class="modal_product_related">' . do_shortcode('[wpshop_related_products pid="' . $product_id . '" sorting="no"]') . '</div>'; } else { $linked_products = ''; } $message_confirmation = sprintf(__('%s has been add to the cart', 'wpshop'), $product->post_title); $modal_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal', array('RELATED_PRODUCTS' => $linked_products, 'PRODUCT_PICTURE' => $product_img, 'PRODUCT_TITLE' => $product_title, 'PRODUCT_PRICE' => $product_price, 'PRODUCT_DESCRIPTION' => $product_description)); $modal_footer_content = wpshop_display::display_template_element('wps_new_add_to_cart_confirmation_modal_footer', array()); $response = array(true, $succes_message_box, $action_after_add, $cart_page_url, $product_id, array($cart_animation_choice, $message_confirmation), array($product_img, $product_title, $linked_products, $product_price), $modal_content, $modal_footer_content); } else { $response = array(false, $return); } wp_die(json_encode($response)); }
/** * Build an array with the different items to add to an order * * @param array $products The item list to add to the order * * @return array $item_list The item to add to order */ function add_product_to_order($product) { global $wpdb; if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) { $price_infos = wpshop_prices::check_product_price($product, true); $product['price_ht'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; $product['product_price'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; $product['tva'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; } $price_piloting = get_option('wpshop_shop_price_piloting'); if (!empty($price_piloting) && $price_piloting == 'HT') { $total_ht = $product['price_ht'] * $product['product_qty']; $tva_total_amount = $total_ht * ($product['tx_tva'] / 100); $total_ttc = $total_ht + $tva_total_amount; } else { $total_ttc = $product['product_price'] * $product['product_qty']; $total_ht = $total_ttc / (1 + $product['tx_tva'] / 100); $tva_total_amount = $total_ttc - $total_ht; } $tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null; $item_discount_type = $item_discount_value = $item_discount_amount = 0; $d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null; $d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null; $d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null; if (!empty($d_amount)) { $item_discount_type = 'discount_amount'; $item_discount_amount = $product['discount_amount']; $item_discount_value = $product['discount_amount']; } elseif (!empty($d_rate)) { $item_discount_type = 'discount_rate'; $item_discount_amount = $product['discount_rate']; $item_discount_value = $product['discount_rate']; } elseif (!empty($d_special)) { $item_discount_type = 'special_price'; $item_discount_amount = $product['special_price']; $item_discount_value = $product['special_price']; } $item = array('item_id' => $product['product_id'], 'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null, 'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array()); $array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations'); if (!empty($product['item_meta'])) { foreach ($product['item_meta'] as $key => $value) { if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) { $item['item_' . $key] = $product[$key]; } } } /** Check if it's a variation product **/ if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) { foreach ($product['item_meta']['variations'] as $k => $variation) { $product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true); if (!empty($product_variation_def)) { foreach ($product_variation_def as $attribute_code => $variation_id) { $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); if (!empty($variation_attribute_def)) { $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; if ($variation_attribute_def->data_type_to_use == 'custom') { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); $variation_name = $wpdb->get_var($query); } else { $variation_post = get_post($variation_id); $variation_name = $variation_post->post_title; } $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; } } } } } else { /** Check if it's product with one variation **/ $product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true); if (!empty($product_variation_def)) { foreach ($product_variation_def as $attribute_code => $variation_id) { $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); if (!empty($variation_attribute_def)) { $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; if ($variation_attribute_def->data_type_to_use == 'custom') { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); $variation_name = $wpdb->get_var($query); } else { $variation_post = get_post($variation_id); $variation_name = $variation_post->post_title; } $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; } } } } return $item; }
if (!empty($group_data) && !empty($group_data['attributes'])) { foreach ($group_data['attributes'] as $attribute) { if (!empty($attribute) && !empty($attribute['data_type']) && $attribute['data_type'] == 'integer' && !empty($attribute['value'])) { if ($attribute['backend_input'] == 'multiple-select' && is_array($attribute['value'])) { $j = 0; foreach ($attribute['value'] as $value) { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $value); $attribute['value'][$j] = $wpdb->get_var($query); $j++; } } else { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $attribute['value']); $attribute['value'] = $wpdb->get_var($query); } } elseif (!empty($attribute) && !empty($attribute['data_type']) && $attribute['data_type'] == 'decimal') { $attribute['value'] = wpshop_tools::formate_number($attribute['value']); } ?> <li><?php _e($attribute['frontend_label'], 'wpshop'); ?> : <?php if ($attribute['backend_input'] == 'multiple-select' && is_array($attribute['value'])) { foreach ($attribute['value'] as $v) { echo __($v, 'wpshop') . ' ' . (!empty($attribute['unit']) ? '(' . $attribute['unit'] . ')' : '') . ', '; } } else { echo __($attribute['value'], 'wpshop') . ' ' . __($attribute['unit'], 'wpshop'); } ?>
/** Resume cart Content **/ public static function resume_cart_content() { $output = ''; $currency = wpshop_tools::wpshop_get_currency(false); $cart_content = !empty($_SESSION) && !empty($_SESSION['cart']) ? $_SESSION['cart'] : array(); if (!empty($cart_content)) { $cart_items = !empty($cart_content['order_items']) ? $cart_content['order_items'] : array(); if (!empty($cart_items)) { if (!empty($cart_content['coupon_id'])) { $coupon_title = get_the_title($cart_content['coupon_id']); $coupon_value = wpshop_tools::formate_number($cart_content['order_discount_amount_total_cart']); } $order_total_before_discount = !empty($cart_content['order_grand_total_before_discount']) ? $cart_content['order_grand_total_before_discount'] : 0; $shipping_cost_ati = !empty($cart_content['order_shipping_cost']) ? $cart_content['order_shipping_cost'] : 0; $total_ati = $total_cart = !empty($cart_content['order_amount_to_pay_now']) ? $cart_content['order_amount_to_pay_now'] : 0; ob_start(); require_once wpshop_tools::get_template_part(WPS_CART_DIR, WPS_CART_TPL_DIR, "frontend", "resume-cart/resume-cart", "content"); $output = ob_get_contents(); ob_end_clean(); } else { $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; } } else { $resume_cart_body = '<div class="wps-alert-info">' . __('Your cart is empty', 'wpshop') . '</div>'; } return $output; }
<p class="wps-hightlight"><?php _e('Total ET', 'wpshop'); ?> <span class="alignright"><strong><?php echo number_format($cart_content['order_total_ht'], 2, '.', ''); ?> </strong> <?php echo wpshop_tools::wpshop_get_currency(); ?> </span></p> <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?> <span class="alignright"><strong><?php echo wpshop_tools::formate_number(!empty($cart_content['order_amount_to_pay_now']) && !empty($oid) && $cart_content['order_amount_to_pay_now'] > 0 ? $cart_content['order_amount_to_pay_now'] : (!empty($cart_content['order_grand_total']) ? $cart_content['order_grand_total'] : 0)); ?> </strong> <?php echo wpshop_tools::wpshop_get_currency(); ?> </span></p> </div> <a title="<?php _e('Finalize order', 'wps-pos-i18n'); ?> " href="<?php echo admin_url('admin-ajax.php?action=wpspos-finalize-order&width=560&height=420'); ?> " class="thickbox wps-bton-first-rounded alignright" id="wpspos-finalize-order" ><?php _e('Finalize order', 'wps-pos-i18n');
?> <span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($cart_content['order_grand_total'] - $allready_received_amount); ?> </strong> <?php echo $currency; ?> </span></p> <?php } else { ?> <p class="wps-hightlight"><?php _e('Total ATI', 'wpshop'); ?> <span class="wps-alignRight"><strong><?php echo wpshop_tools::formate_number($total_ati); ?> </strong> <?php echo $currency; ?> </span></p> <?php } ?> </div> </div> </div> </div> <?php if (empty($cart_type) || !empty($cart_type) && $cart_type != 'summary' && $cart_type != 'admin-panel') {
</span></span> <span class="wps-tva"><?php _e('ET', 'wpshop'); ?> </span> </div> <?php } ?> <?php if ($cart_option == 'full_cart' || $cart_option == 'simplified_ati') { ?> <div class="wps-cart-item-price"> <span class="wps-price"> <?php echo wpshop_tools::formate_number($item['item_total_ttc']); ?> <span><?php echo $currency; ?> </span></span> </div> <?php } ?> <?php if (empty($cart_type) || !empty($cart_type) && $cart_type != 'summary') { ?> <div class="wps-cart-item-close">
</div> <?php foreach ($orders as $order) { $order_meta = get_post_meta($order->ID, '_order_postmeta', true); ?> <div class="wps-table-content wps-table-row"> <div class="wps-table-cell"><?php echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $order_meta['order_date'], true); ?> </div> <div class="wps-table-cell"><?php echo $order_meta['order_key']; ?> </div> <div class="wps-table-cell"><?php echo wpshop_tools::formate_number($order_meta['order_grand_total']) . ' ' . $currency; ?> </div> <div class="wps-table-cell"> <span class="wps-label-<?php echo $color_label[$order_meta['order_status']]; ?> "><?php _e($order_status[$order_meta['order_status']], 'wpshop'); ?> </span> </div> <div class="wps-table-cell"> <?php if (!empty($order_meta['order_trackingLink'])) { ?>
<?php $company_infos = get_option('wpshop_company_info'); $amount = !empty($_SESSION['cart']['order_amount_to_pay_now']) ? wpshop_tools::formate_number($_SESSION['cart']['order_amount_to_pay_now']) : 0; ?> <div class="wps-boxed"> <p><?php _e('Thank you ! Your order has been placed and you will receive a confirmation email shortly.', 'wpshop'); ?> </p> <p><?php echo sprintf(__('You have to send the check with an amount of %s to about "%s" to the adress :', 'wpshop'), $amount . ' ' . wpshop_tools::wpshop_get_currency(false), !empty($company_infos['company_name']) ? $company_infos['company_name'] : ''); ?> </p> <p><?php echo !empty($company_infos['company_name']) ? $company_infos['company_name'] : ''; ?> <br/> <?php echo !empty($company_infos['company_street']) ? $company_infos['company_street'] : ''; ?> <br/> <?php echo !empty($company_infos['company_postcode']) ? $company_infos['company_postcode'] : ''; ?> <?php echo !empty($company_infos['company_city']) ? $company_infos['company_city'] : ''; ?> <br/> <?php echo !empty($company_infos['company_country']) ? $company_infos['company_country'] : '';
<?php if (!empty($discount_data['type']) && ($discount_data['type'] == 'discount_amount' || $discount_data['type'] == 'discount_rate')) { ?> <span class="wps-badge-big-bottomLeft-rouge"> -<?php echo wpshop_tools::formate_number($discount_data['value']); echo $discount_data['type'] == 'discount_amount' ? wpshop_tools::wpshop_get_currency(false) : '<span>%</span>'; ?> </span> <?php }
_e('Order summary', 'wps-pos-i18n'); ?> </h3> <ul class="wpspos-order-content-summary" > <li><span class="wpspos-order-summary-title"><?php _e('Number of product', 'wps-pos-i18n'); ?> </span><span class="wpspos-order-summary-content" ><?php echo count($order_items); ?> </span></li> <li><span class="wpspos-order-summary-title"><?php _e('Amount to pay', 'wps-pos-i18n'); ?> </span><span class="wpspos-order-summary-content" ><?php echo wpshop_tools::formate_number($cart_content['order_amount_to_pay_now']); ?> <?php echo wpshop_tools::wpshop_get_currency(); ?> </span></li> </ul> <h3><?php _e('Order payment', 'wps-pos-i18n'); ?> </h3> <form class="wpspos-order-payment-form" action="<?php echo admin_url("admin-ajax.php"); ?> " method="post" >
<?php printf(__('Orders total number : %d', 'wpshop'), count($orders)); ?> <?php echo mb_substr($order_list, 0, -2, 'UTF-8'); ?> </li> <li> <?php printf(__('Orders total amount : %s', 'wpshop'), wpshop_tools::formate_number($customer_order_real_total_amount) . ' ' . $currency); ?> <?php if (!empty($customer_order_total_amount) && $customer_order_total_amount != $customer_order_real_total_amount) { ?> ( <?php printf(__('If all orders were paid : %s', 'wpshop'), wpshop_tools::formate_number($customer_order_total_amount) . ' ' . $currency); ?> )<?php } ?> </li> </ul> <div class="wp-shop-customers-list-ordered-product" > <p><?php _e('List of ordered product', 'wpshop'); ?> </p> <?php echo implode(', ', $ordered_products); ?> </div>