/** * * @param unknown_type $selected_product * @return string */ function custom_product_list($selected_product = array()) { global $wpdb; /* Start the table definition */ $tableId = 'wpshop_product_list'; $tableTitles = array(); $tableTitles[] = ''; $tableTitles[] = __('Id', 'wpshop'); $tableTitles[] = __('Quantity', 'wpshop'); $tableTitles[] = __('Reference', 'wpshop'); $tableTitles[] = __('Product name', 'wpshop'); $tableTitles[] = __('Actions', 'wpshop'); $tableTitles[] = __('Price', 'wpshop'); $tableClasses = array(); $tableClasses[] = 'wpshop_product_selector_column'; $tableClasses[] = 'wpshop_product_identifier_column'; $tableClasses[] = 'wpshop_product_quantity_column'; $tableClasses[] = 'wpshop_product_sku_column'; $tableClasses[] = 'wpshop_product_name_column'; $tableClasses[] = 'wpshop_product_link_column'; $tableClasses[] = 'wpshop_product_price_column'; /* Get post list */ $has_result = false; $current_line_index = 0; $posts = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1)); if (!empty($posts)) { $has_result = true; foreach ($posts as $post) { $tableRowsId[$current_line_index] = 'product_' . $post->ID; $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); unset($tableRowValue); $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => !empty($post_info['product_reference']) ? $post_info['product_reference'] : ''); $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . (!empty($post_info[WPSHOP_PRODUCT_PRICE_HT]) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . (!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC]) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); $tableRows[] = $tableRowValue; $current_line_index++; } wp_reset_query(); } $posts = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1)); if (!empty($posts)) { $has_result = true; foreach ($posts as $post) { $tableRowsId[$current_line_index] = 'product_' . $post->ID; $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); unset($tableRowValue); $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />'); $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>'); $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => !empty($post_info['product_reference']) ? $post_info['product_reference'] : ''); $parent_product = wpshop_products::get_parent_variation($post->ID); if (!empty($parent_product) && !empty($parent_product['parent_post'])) { $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); $option_name = $wpdb->get_var($query); $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); $option_value = $wpdb->get_var($query); $parent_post = $parent_product['parent_post']; $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); } else { $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); } $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/> <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . (!empty($post_info[WPSHOP_PRODUCT_PRICE_HT]) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . (!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC]) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); $tableRows[] = $tableRowValue; $current_line_index++; } wp_reset_query(); } if (!$has_result) { $tableRowsId[] = 'no_product_found'; unset($tableRowValue); $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); $tableRows[] = $tableRowValue; } return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' <script type="text/javascript" > wpshop(document).ready(function(){ jQuery("#' . $tableId . '").dataTable( { "sPaginationType": "full_numbers", "iDisplayLength": 5 }); }); </script>'; }
/** * Return the list page content, containing the table that present the item list * * @return string $listItemOutput The html code that output the item list */ public static function unit_group_list() { $listItemOutput = ''; /* Start the table definition */ $tableId = self::getDbTable() . '_group_list'; $tableSummary = __('Existing attributes listing', 'wpshop'); $tableTitles = array(); $tableTitles[] = __('Attribute unit group name', 'wpshop'); $tableClasses = array(); $tableClasses[] = 'wpshop_' . self::currentPageCode . '_label_column'; $line = 0; $elementList = self::get_unit_group(); if (is_array($elementList) && count($elementList) > 0) { foreach ($elementList as $element) { $tableRowsId[$line] = self::getDbTable() . '_' . $element->id; $elementLabel = __($element->name, 'wpshop'); $subRowActions = ''; $attributeSlugUrl = self::getListingSlug(); if (current_user_can('wpshop_add_attributes_unit_group')) { $attributeSlugUrl = self::getEditionSlug(); } if (current_user_can('wpshop_edit_attributes_unit_group')) { $editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&action=edit&id=' . $element->id); $subRowActions .= ' <a href="#" id="edit_attribute_unit_group_' . $element->id . '" class="edit_attribute_unit_group" >' . __('Edit', 'wpshop') . '</a>'; } elseif (current_user_can('wpshop_view_attributes_unit_group')) { $editAction = admin_url('admin.php?page=' . $attributeSlugUrl . '&action=edit&id=' . $element->id); } if (current_user_can('wpshop_delete_attributes_unit_group')) { if ($subRowActions != '') { $subRowActions .= ' | '; } $subRowActions .= ' <a href="#" id="delete_attribute_unit_group_' . $element->id . '" class="delete_attribute_unit_group" >' . __('Delete', 'wpshop') . '</a>'; } $rowActions = ' <div id="rowAction' . $element->id . '" class="wpshopRowAction" >' . $subRowActions . ' </div>'; unset($tableRowValue); $tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => str_replace('\\', '', $elementLabel) . $rowActions); $tableRows[] = $tableRowValue; $line++; } } else { unset($tableRowValue); $tableRowValue[] = array('class' => self::currentPageCode . '_label_cell', 'value' => __('No element to ouput here', 'wpshop')); $tableRows[] = $tableRowValue; } if (current_user_can('wpshop_add_attributes_unit_group')) { $listItemOutput .= ' <input type="button" value="' . __('Add an unit group', 'wpshop') . '" class="button-secondary alignleft" name="add_attribute_unit_group" id="add_attribute_unit_group" />'; } $listItemOutput .= wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary, true) . ' <script type="text/javascript" > wpshop(document).ready(function(){ jQuery("#' . $tableId . '").dataTable(); jQuery("#wpshop_unit_list_tab").show();'; if (current_user_can('wpshop_delete_attributes_unit_group')) { $listItemOutput .= ' wpshop(".delete_attribute_unit_group").click(function(){ if(confirm(wpshopConvertAccentTojs("' . __('Are you sure you want to delete this unit group', 'wpshop') . ' ?"))){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "delete_attribute_unit_group", "elementIdentifier": wpshop(this).attr("id").replace("delete_attribute_unit_group_", "") }); } });'; } if (current_user_can('wpshop_edit_attributes_unit_group')) { $listItemOutput .= ' wpshop(".edit_attribute_unit_group").click(function(){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "edit_attribute_unit_group", "elementIdentifier": wpshop(this).attr("id").replace("edit_attribute_unit_group_", "") }); });'; } if (current_user_can('wpshop_add_attributes_unit_group')) { $listItemOutput .= ' wpshop("#add_attribute_unit_group").click(function(){ wpshop("#wpshop_unit_group_list").load(WPSHOP_AJAX_FILE_URL, { "post": "true", "elementCode": "attribute_unit_management", "action": "add_attribute_unit_group" }); });'; } $listItemOutput .= ' }); </script>'; return $listItemOutput; }