2013-07-08 16:01:26 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) )
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
|
|
|
|
if ( ! class_exists( 'WP_List_Table' ) )
|
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
|
|
|
|
|
|
|
/**
|
2014-02-14 13:02:37 +00:00
|
|
|
* WC_Report_Stock
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin/Reports
|
|
|
|
* @version 2.1.0
|
2013-07-08 16:01:26 +00:00
|
|
|
*/
|
|
|
|
class WC_Report_Stock extends WP_List_Table {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __construct function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2013-07-09 10:48:56 +00:00
|
|
|
public function __construct(){
|
2013-07-08 16:01:26 +00:00
|
|
|
parent::__construct( array(
|
|
|
|
'singular' => __( 'Stock', 'woocommerce' ),
|
|
|
|
'plural' => __( 'Stock', 'woocommerce' ),
|
|
|
|
'ajax' => false
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2013-07-09 10:48:56 +00:00
|
|
|
/**
|
|
|
|
* No items found text
|
|
|
|
*/
|
|
|
|
public function no_items() {
|
|
|
|
_e( 'No products found.', 'woocommerce' );
|
|
|
|
}
|
|
|
|
|
2013-07-08 16:01:26 +00:00
|
|
|
/**
|
|
|
|
* Don't need this
|
|
|
|
*/
|
2013-07-09 10:48:56 +00:00
|
|
|
public function display_tablenav( $position ) {
|
|
|
|
if ( $position != 'top' )
|
|
|
|
parent::display_tablenav( $position );
|
|
|
|
}
|
2013-07-08 16:01:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the report
|
|
|
|
*/
|
|
|
|
public function output_report() {
|
|
|
|
$this->prepare_items();
|
|
|
|
echo '<div id="poststuff" class="woocommerce-reports-wide">';
|
|
|
|
$this->display();
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* column_default function.
|
|
|
|
*
|
|
|
|
* @access public
|
2013-07-09 10:48:56 +00:00
|
|
|
* @param mixed $item
|
2013-07-08 16:01:26 +00:00
|
|
|
* @param mixed $column_name
|
|
|
|
*/
|
2013-07-09 10:48:56 +00:00
|
|
|
function column_default( $item, $column_name ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $product;
|
2013-07-08 16:01:26 +00:00
|
|
|
|
2013-07-09 10:48:56 +00:00
|
|
|
if ( ! $product || $product->id !== $item->id )
|
2014-08-19 10:09:29 +00:00
|
|
|
$product = wc_get_product( $item->id );
|
2013-07-08 16:01:26 +00:00
|
|
|
|
|
|
|
switch( $column_name ) {
|
|
|
|
case 'product' :
|
2013-07-09 10:48:56 +00:00
|
|
|
if ( $sku = $product->get_sku() )
|
|
|
|
echo $sku . ' - ';
|
|
|
|
|
2013-07-08 16:01:26 +00:00
|
|
|
echo $product->get_title();
|
2013-07-09 10:48:56 +00:00
|
|
|
|
|
|
|
// Get variation data
|
|
|
|
if ( $product->is_type( 'variation' ) ) {
|
|
|
|
$list_attributes = array();
|
|
|
|
$attributes = $product->get_variation_attributes();
|
|
|
|
|
|
|
|
foreach ( $attributes as $name => $attribute ) {
|
2013-09-12 13:41:02 +00:00
|
|
|
$list_attributes[] = wc_attribute_label( str_replace( 'attribute_', '', $name ) ) . ': <strong>' . $attribute . '</strong>';
|
2013-07-09 10:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '<div class="description">' . implode( ', ', $list_attributes ) . '</div>';
|
|
|
|
}
|
2013-07-08 16:01:26 +00:00
|
|
|
break;
|
2013-07-09 10:48:56 +00:00
|
|
|
case 'parent' :
|
|
|
|
if ( $item->parent )
|
|
|
|
echo get_the_title( $item->parent );
|
|
|
|
else
|
|
|
|
echo '-';
|
|
|
|
break;
|
|
|
|
case 'stock_status' :
|
|
|
|
if ( $product->is_in_stock() ) {
|
|
|
|
echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
|
|
|
|
} else {
|
|
|
|
echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
|
|
|
|
}
|
|
|
|
break;
|
2013-07-08 16:01:26 +00:00
|
|
|
case 'stock_level' :
|
|
|
|
echo $product->get_stock_quantity();
|
|
|
|
break;
|
2013-07-09 10:48:56 +00:00
|
|
|
case 'wc_actions' :
|
|
|
|
?><p>
|
|
|
|
<?php
|
|
|
|
$actions = array();
|
|
|
|
$action_id = $product->is_type( 'variation' ) ? $item->parent : $item->id;
|
|
|
|
|
|
|
|
$actions['edit'] = array(
|
|
|
|
'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ),
|
|
|
|
'name' => __( 'Edit', 'woocommerce' ),
|
|
|
|
'action' => "edit"
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $product->is_visible() )
|
|
|
|
$actions['view'] = array(
|
|
|
|
'url' => get_permalink( $action_id ),
|
|
|
|
'name' => __( 'View', 'woocommerce' ),
|
|
|
|
'action' => "view"
|
|
|
|
);
|
|
|
|
|
|
|
|
$actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product );
|
|
|
|
|
|
|
|
foreach ( $actions as $action ) {
|
2014-02-13 09:37:39 +00:00
|
|
|
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'] ) );
|
2013-07-09 10:48:56 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</p><?php
|
|
|
|
break;
|
2013-07-08 16:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_columns function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function get_columns(){
|
|
|
|
$columns = array(
|
2013-07-09 10:48:56 +00:00
|
|
|
'product' => __( 'Product', 'woocommerce' ),
|
|
|
|
'parent' => __( 'Parent', 'woocommerce' ),
|
|
|
|
'stock_level' => __( 'Units in stock', 'woocommerce' ),
|
|
|
|
'stock_status' => __( 'Stock status', 'woocommerce' ),
|
|
|
|
'wc_actions' => __( 'Actions', 'woocommerce' ),
|
2013-07-08 16:01:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prepare_items function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function prepare_items() {
|
|
|
|
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
|
2013-07-09 10:48:56 +00:00
|
|
|
$current_page = absint( $this->get_pagenum() );
|
2014-05-31 20:45:47 +00:00
|
|
|
$per_page = apply_filters( 'woocommerce_admin_stock_report_products_per_page', 20 );
|
2013-07-09 10:48:56 +00:00
|
|
|
|
|
|
|
$this->get_items( $current_page, $per_page );
|
2013-07-08 16:01:26 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-09 10:48:56 +00:00
|
|
|
* Pagination
|
2013-07-08 16:01:26 +00:00
|
|
|
*/
|
2013-07-09 10:48:56 +00:00
|
|
|
$this->set_pagination_args( array(
|
|
|
|
'total_items' => $this->max_items,
|
|
|
|
'per_page' => $per_page,
|
|
|
|
'total_pages' => ceil( $this->max_items / $per_page )
|
|
|
|
) );
|
2013-07-08 16:01:26 +00:00
|
|
|
}
|
|
|
|
}
|