Hardcode the get_type per product class

This commit is contained in:
Mike Jolley 2016-10-17 12:22:23 +01:00
parent 70e13702ae
commit 4c0cc54f79
7 changed files with 58 additions and 43 deletions

View File

@ -84,6 +84,13 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
case 'post' :
$value = get_post( $this->get_id() );
break;
case 'product_type' : // @todo What do we do with 3rd party use of product_type now it's hardcoded?
$value = $this->get_type();
break;
default :
$value = get_post_meta( $this->id, '_' . $key, true );

View File

@ -32,7 +32,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
'permalink' => '',
'date_created' => '',
'date_modified' => '',
'type' => '',
'status' => '',
'featured' => 'no',
'catalog_visibility' => 'hidden',
@ -115,6 +114,24 @@ class WC_Product extends WC_Abstract_Legacy_Product {
return apply_filters( 'woocommerce_product_get_name', $this->data['name'], $this );
}
/**
* Get internal type.
* @since 2.7.0
* @return string
*/
public function get_type() {
return 'simple';
}
// @todo below.
/**
* Get product slug.
*
@ -154,15 +171,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
return $this->data['date_modified'];
}
/**
* Return the product type.
*
* @return string
*/
public function get_type() {
return $this->data['type'];
}
/**
* Get product status.
*
@ -564,15 +572,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
$this->data['date_modified'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
}
/**
* Set the product type.
*
* @return string
*/
public function set_type( $type ) {
$this->data['type'] = $type;
}
/**
* Set product status.
*
@ -1220,7 +1219,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
* @return bool
*/
public function is_type( $type ) {
return ( $this->product_type == $type || ( is_array( $type ) && in_array( $this->product_type, $type ) ) ) ? true : false;
return ( $this->get_type() === $type || ( is_array( $type ) && in_array( $this->get_type(), $type ) ) );
}
/**

View File

@ -18,14 +18,11 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Product_External extends WC_Product {
/**
* Constructor.
*
* @access public
* @param mixed $product
* Get internal type.
* @return string
*/
public function __construct( $product ) {
$this->product_type = 'external';
parent::__construct( $product );
public function get_type() {
return 'external';
}
/**

View File

@ -21,14 +21,11 @@ class WC_Product_Grouped extends WC_Product {
public $children;
/**
* Constructor.
*
* @access public
* @param mixed $product
* Get internal type.
* @return string
*/
public function __construct( $product ) {
$this->product_type = 'grouped';
parent::__construct( $product );
public function get_type() {
return 'grouped';
}
/**

View File

@ -10,7 +10,6 @@ if ( ! defined( 'ABSPATH' ) ) {
* The default product type kinda product.
*
* @class WC_Product_Simple
* @version 2.0.0
* @package WooCommerce/Classes/Products
* @category Class
* @author WooThemes
@ -23,11 +22,22 @@ class WC_Product_Simple extends WC_Product {
* @param mixed $product
*/
public function __construct( $product ) {
$this->product_type = 'simple';
$this->supports[] = 'ajax_add_to_cart';
parent::__construct( $product );
}
/**
* Get internal type.
* @return string
*/
public function get_type() {
return 'simple';
}
/**
* Get the add to url used mainly in loops.
*

View File

@ -24,13 +24,11 @@ class WC_Product_Variable extends WC_Product {
private $prices_array = array();
/**
* Constructor.
*
* @param mixed $product
* Get internal type.
* @return string
*/
public function __construct( $product ) {
$this->product_type = 'variable';
parent::__construct( $product );
public function get_type() {
return 'variable';
}
/**

View File

@ -85,7 +85,6 @@ class WC_Product_Variation extends WC_Product {
throw new Exception( sprintf( 'No parent product set for variation #%d', $this->variation_id ), 422 );
}
$this->product_type = 'variation';
$this->parent = ! empty( $args['parent'] ) ? $args['parent'] : wc_get_product( $this->id );
$this->post = ! empty( $this->parent->post ) ? $this->parent->post : array();
@ -95,6 +94,14 @@ class WC_Product_Variation extends WC_Product {
}
}
/**
* Get internal type.
* @return string
*/
public function get_type() {
return 'variation';
}
/**
* __isset function.
*