/**
  * Output the different tabs into an entity sheet
  *
  * @param string $element_code The current element type represented by the code
  * @param integer $element_id The current element identifier to dislay tabs for
  * @param array $element_definition An array with the different configuration for the current element
  *
  * @return string The html code to output directly tabs
  */
 public static function attribute_of_entity_to_tab($element_code, $element_id, $element_definition)
 {
     $attributeContentOutput = '';
     /**	Get the different attribute affected to the entity	*/
     $element_atribute_list = wpshop_attributes::getElementWithAttributeAndValue($element_code, $element_id, WPSHOP_CURRENT_LOCALE, '', 'frontend');
     if (is_array($element_atribute_list) && count($element_atribute_list) > 0) {
         foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
             $attributeToShowNumber = 0;
             $attributeOutput = '';
             foreach ($attributeSetContent['attributes'] as $attributeId => $attributeDefinition) {
                 /**	Check the value type to check if empty or not	*/
                 if ($attributeDefinition['data_type'] == 'int') {
                     $attributeDefinition['value'] = (int) $attributeDefinition['value'];
                 } else {
                     if ($attributeDefinition['data_type'] == 'decimal') {
                         $attributeDefinition['value'] = (double) $attributeDefinition['value'];
                     }
                 }
                 /** Check if the attribute is set to be displayed in frontend	*/
                 $attribute_display_state = wpshop_attributes::check_attribute_display($attributeDefinition['is_visible_in_front'], $element_definition['custom_display'], 'attribute', $attributeDefinition['code'], 'complete_sheet');
                 /**	Output the field if the value is not null	*/
                 if ((is_array($attributeDefinition['value']) || !empty($attributeDefinition['value'])) && $attribute_display_state) {
                     $attribute_display = wpshop_attributes::wps_attribute_values_display($attributeDefinition);
                     $attribute_value = $attribute_display[0];
                     $attributeDefinition['value'] = $attribute_display[1];
                     $attribute_unit_list = $attribute_display[2];
                     /** Template parameters	*/
                     $template_part = 'product_attribute_display';
                     $tpl_component = array();
                     $tpl_component['PDT_ENTITY_CODE'] = self::currentPageCode;
                     $tpl_component['ATTRIBUTE_CODE'] = $attributeDefinition['attribute_code'];
                     $tpl_component['ATTRIBUTE_LABEL'] = __($attributeDefinition['frontend_label'], 'wpshop');
                     $tpl_component['ATTRIBUTE_VALUE'] = !is_array($attribute_value) ? stripslashes($attribute_value) : $attribute_value;
                     $tpl_component['ATTRIBUTE_VALUE_UNIT'] = $attribute_unit_list;
                     /** Build template	*/
                     $attributeOutput .= wpshop_display::display_template_element($template_part, $tpl_component);
                     unset($tpl_component);
                     $attributeToShowNumber++;
                 }
             }
             /** Check if the attribute set section is set to be displayed in frontend	*/
             $attribute_set_display_state = wpshop_attributes::check_attribute_display($attributeSetContent['display_on_frontend'], $element_definition['custom_display'], 'attribute_set_section', $attributeSetContent['code'], 'complete_sheet');
             if (!$attribute_set_display_state) {
                 $attributeToShowNumber = 0;
                 $attributeOutput = '';
             }
             $element_atribute_list[$element_id][$attributeSetSectionName]['count'] = $attributeToShowNumber;
             $element_atribute_list[$element_id][$attributeSetSectionName]['output'] = $attributeOutput;
         }
         /** Gestion de l'affichage	*/
         $tab_list = $content_list = '';
         foreach ($element_atribute_list[$element_id] as $attributeSetSectionName => $attributeSetContent) {
             if (!empty($attributeSetContent['count']) > 0) {
                 /** Template parameters	*/
                 $template_part = 'product_attribute_tabs';
                 $tpl_component = array();
                 $tpl_component['ATTRIBUTE_SET_CODE'] = $attributeSetContent['code'];
                 $tpl_component['ATTRIBUTE_SET_NAME'] = __($attributeSetSectionName, 'wpshop');
                 /** 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
                     $tab_list .= ob_get_contents();
                     ob_end_clean();
                 } else {
                     $tab_list .= wpshop_display::display_template_element($template_part, $tpl_component);
                 }
                 unset($tpl_component);
                 /** Template parameters	*/
                 $template_part = 'product_attribute_tabs_detail';
                 $tpl_component = array();
                 $tpl_component['ATTRIBUTE_SET_CODE'] = $attributeSetContent['code'];
                 $tpl_component['ATTRIBUTE_SET_CONTENT'] = $attributeSetContent['output'];
                 /** 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
                     $content_list .= ob_get_contents();
                     ob_end_clean();
                 } else {
                     $content_list .= wpshop_display::display_template_element($template_part, $tpl_component);
                 }
                 unset($tpl_component);
             }
         }
         if ($tab_list != '') {
             /** Template parameters	*/
             $template_part = 'product_attribute_container';
             $tpl_component = array();
             $tpl_component['PDT_TABS'] = apply_filters('wpshop_extra_tabs_menu_before', '') . $tab_list . apply_filters('wpshop_extra_tabs_menu_after', '');
             $tpl_component['PDT_TAB_DETAIL'] = apply_filters('wpshop_extra_tabs_content_before', '') . $content_list . apply_filters('wpshop_extra_tabs_content_after', '');
             /** 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
                 $attributeContentOutput = ob_get_contents();
                 ob_end_clean();
             } else {
                 $attributeContentOutput = wpshop_display::display_template_element($template_part, $tpl_component);
             }
             unset($tpl_component);
         }
     }
     return $attributeContentOutput;
 }
示例#2
0
/**
 * 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));
}
 /**
  * Return the output for a product attachement gallery (picture or document)
  *
  * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
  * @param string $content The gallery content build previously
  *
  * @return string The attachement gallery output
  */
 public static function display_attachment_gallery($attachement_type, $content)
 {
     $galery_output = '';
     /*
      * Get the template part for given galery type
      */
     switch ($attachement_type) {
         case 'picture':
             $template_part = 'product_attachment_picture_galery';
             break;
         case 'document':
             $template_part = 'product_attachment_galery';
             break;
     }
     /*
      * Template parameters
      */
     $tpl_component = array();
     $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
     $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
     /*
      * 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
         $galery_output = ob_get_contents();
         ob_end_clean();
     } else {
         $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
     }
     unset($tpl_component);
     return $galery_output;
 }
 /**
  *	Display a category in a list
  *
  *	@param object $category The category definition
  *	@param string $output_type The output type defined from plugin option
  *
  *	@return mixed $content Output the category list
  */
 public static function category_mini_output($category, $output_type = 'list')
 {
     $content = '';
     /*	Get the different informations for output	*/
     $category_meta_information = !empty($category) && !empty($category->term_id) ? get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category->term_id) : '';
     $categoryThumbnail = '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail" />';
     /*	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'));
         $categoryThumbnail = !empty($image_post) ? $image_post : '<img src="' . WPSHOP_DEFAULT_CATEGORY_PICTURE . '" alt="No picture" class="category_thumbnail" />';
     }
     $category_title = !empty($category) && !empty($category->name) ? $category->name : '';
     $category_more_informations = !empty($category) && !empty($category->description) ? $category->description : '';
     $category_link = !empty($category) && !empty($category->term_id) ? get_term_link((int) $category->term_id, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES) : '';
     $item_width = null;
     /*	Make some treatment in case we are in grid mode	*/
     if ($output_type == 'grid') {
         /*	Determine the width of a component in a line grid	*/
         $element_width = 100 / WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
         $item_width = round($element_width) - 1 . '%';
     }
     /*
      * Template parameters
      */
     $template_part = 'category_mini_' . $output_type;
     $tpl_component = array();
     $tpl_component['CATEGORY_LINK'] = $category_link;
     $tpl_component['CATEGORY_THUMBNAIL'] = $categoryThumbnail;
     $tpl_component['CATEGORY_TITLE'] = $category_title;
     $tpl_component['CATEGORY_DESCRIPTION'] = $category_more_informations;
     $tpl_component['ITEM_WIDTH'] = $item_width;
     $tpl_component['CATEGORY_ID'] = !empty($category) && !empty($category->term_id) ? $category->term_id : '';
     $tpl_component['CATEGORY_DISPLAY_TYPE'] = $output_type;
     /*
      * 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
         $content = ob_get_contents();
         ob_end_clean();
     } else {
         $content = wpshop_display::display_template_element($template_part, $tpl_component);
     }
     unset($tpl_component);
     return $content;
 }
 public static function get_product_complete_sheet_attachments($product_id)
 {
     /**	Get attachement file for the current product	*/
     $product_picture_galery_content = $product_document_galery_content = '';
     $picture_number = $document_number = $index_li = 0;
     $attachments = self::get_attachments($product_id, 'attachments');
     if (is_array($attachments) && count($attachments) > 0) {
         $picture_increment = $document_increment = 1;
         foreach ($attachments as $attachment) {
             $tpl_component = array();
             $tpl_component['ATTACHMENT_ITEM_GUID'] = wp_get_attachment_url($attachment->ID);
             $tpl_component['ATTACHMENT_ITEM_TITLE'] = $attachment->post_title;
             if (is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) {
                 $tpl_component['ATTACHMENT_ITEM_TYPE'] = 'document';
                 $tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = !($document_increment % WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE) ? 'wpshop_gallery_document_last' : '';
                 /** Template parameters	*/
                 $template_part = 'product_attachment_item_document';
                 $tpl_component['PRODUCT_ID'] = $product_id;
                 /** 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 wpshop_display::get_template_file($tpl_way_to_take[1]);
                     $product_document_galery_content .= ob_get_contents();
                     ob_end_clean();
                 } else {
                     $product_document_galery_content .= wpshop_display::display_template_element($template_part, $tpl_component);
                 }
                 $document_number++;
                 $document_increment++;
             }
             unset($tpl_component);
         }
     }
     return $product_document_galery = $document_number >= 1 ? self::display_attachment_gallery('document', $product_document_galery_content) : '';
 }