PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/woocommerce/includes/admin/reports/class-wc-report-stock.php

https://gitlab.com/webkod3r/tripolis
PHP | 194 lines | 115 code | 34 blank | 45 comment | 13 complexity | de73c941f9975debcf50a328dac749a2 MD5 | raw file
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'WP_List_Table' ) ) {
  6. require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  7. }
  8. /**
  9. * WC_Report_Stock.
  10. *
  11. * @author WooThemes
  12. * @category Admin
  13. * @package WooCommerce/Admin/Reports
  14. * @version 2.1.0
  15. */
  16. class WC_Report_Stock extends WP_List_Table {
  17. /**
  18. * Max items.
  19. *
  20. * @var int
  21. */
  22. protected $max_items;
  23. /**
  24. * Constructor.
  25. */
  26. public function __construct() {
  27. parent::__construct( array(
  28. 'singular' => __( 'Stock', 'woocommerce' ),
  29. 'plural' => __( 'Stock', 'woocommerce' ),
  30. 'ajax' => false
  31. ) );
  32. }
  33. /**
  34. * No items found text.
  35. */
  36. public function no_items() {
  37. _e( 'No products found.', 'woocommerce' );
  38. }
  39. /**
  40. * Don't need this.
  41. *
  42. * @param string $position
  43. */
  44. public function display_tablenav( $position ) {
  45. if ( $position != 'top' ) {
  46. parent::display_tablenav( $position );
  47. }
  48. }
  49. /**
  50. * Output the report.
  51. */
  52. public function output_report() {
  53. $this->prepare_items();
  54. echo '<div id="poststuff" class="woocommerce-reports-wide">';
  55. $this->display();
  56. echo '</div>';
  57. }
  58. /**
  59. * Get column value.
  60. *
  61. * @param mixed $item
  62. * @param string $column_name
  63. */
  64. public function column_default( $item, $column_name ) {
  65. global $product;
  66. if ( ! $product || $product->id !== $item->id ) {
  67. $product = wc_get_product( $item->id );
  68. }
  69. switch( $column_name ) {
  70. case 'product' :
  71. if ( $sku = $product->get_sku() ) {
  72. echo $sku . ' - ';
  73. }
  74. echo $product->get_title();
  75. // Get variation data
  76. if ( $product->is_type( 'variation' ) ) {
  77. $list_attributes = array();
  78. $attributes = $product->get_variation_attributes();
  79. foreach ( $attributes as $name => $attribute ) {
  80. $list_attributes[] = wc_attribute_label( str_replace( 'attribute_', '', $name ) ) . ': <strong>' . $attribute . '</strong>';
  81. }
  82. echo '<div class="description">' . implode( ', ', $list_attributes ) . '</div>';
  83. }
  84. break;
  85. case 'parent' :
  86. if ( $item->parent ) {
  87. echo get_the_title( $item->parent );
  88. } else {
  89. echo '-';
  90. }
  91. break;
  92. case 'stock_status' :
  93. if ( $product->is_in_stock() ) {
  94. echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
  95. } else {
  96. echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
  97. }
  98. break;
  99. case 'stock_level' :
  100. echo $product->get_stock_quantity();
  101. break;
  102. case 'wc_actions' :
  103. ?><p>
  104. <?php
  105. $actions = array();
  106. $action_id = $product->is_type( 'variation' ) ? $item->parent : $item->id;
  107. $actions['edit'] = array(
  108. 'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ),
  109. 'name' => __( 'Edit', 'woocommerce' ),
  110. 'action' => "edit"
  111. );
  112. if ( $product->is_visible() ) {
  113. $actions['view'] = array(
  114. 'url' => get_permalink( $action_id ),
  115. 'name' => __( 'View', 'woocommerce' ),
  116. 'action' => "view"
  117. );
  118. }
  119. $actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product );
  120. foreach ( $actions as $action ) {
  121. printf( '<a class="button tips %s" href="%s" data-tip="%s ' . __( 'product', 'woocommerce' ) . '">%s</a>', $action['action'], esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
  122. }
  123. ?>
  124. </p><?php
  125. break;
  126. }
  127. }
  128. /**
  129. * Get columns.
  130. *
  131. * @return array
  132. */
  133. public function get_columns() {
  134. $columns = array(
  135. 'product' => __( 'Product', 'woocommerce' ),
  136. 'parent' => __( 'Parent', 'woocommerce' ),
  137. 'stock_level' => __( 'Units in stock', 'woocommerce' ),
  138. 'stock_status' => __( 'Stock status', 'woocommerce' ),
  139. 'wc_actions' => __( 'Actions', 'woocommerce' ),
  140. );
  141. return $columns;
  142. }
  143. /**
  144. * Prepare customer list items.
  145. */
  146. public function prepare_items() {
  147. $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
  148. $current_page = absint( $this->get_pagenum() );
  149. $per_page = apply_filters( 'woocommerce_admin_stock_report_products_per_page', 20 );
  150. $this->get_items( $current_page, $per_page );
  151. /**
  152. * Pagination.
  153. */
  154. $this->set_pagination_args( array(
  155. 'total_items' => $this->max_items,
  156. 'per_page' => $per_page,
  157. 'total_pages' => ceil( $this->max_items / $per_page )
  158. ) );
  159. }
  160. }