Variation specific backwards compatibility

This commit is contained in:
Mike Jolley 2016-12-22 14:18:20 +00:00
parent fd45160439
commit d5b346fc40
1 changed files with 26 additions and 22 deletions

View File

@ -31,26 +31,30 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
* @return bool * @return bool
*/ */
public function __isset( $key ) { public function __isset( $key ) {
return $valid = array(
in_array( $key, array_merge( array( 'id',
'id', 'product_attributes',
'visibility',
'sale_price_dates_from',
'sale_price_dates_to',
'post',
'download_type',
'product_image_gallery',
'variation_shipping_class',
'shipping_class',
'total_stock',
'crosssell_ids',
'parent',
);
if ( $this->is_type( 'variation' ) ) {
$valid = array_merge( $valid, array(
'variation_id', 'variation_id',
'variation_data', 'variation_data',
'variation_has_stock', 'variation_has_stock',
'variation_shipping_class_id', 'variation_shipping_class_id',
'product_attributes', ) );
'visibility', }
'sale_price_dates_from', return in_array( $key, array_merge( $valid, array_keys( $this->data ) ) ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) || metadata_exists( 'post', $this->get_parent_id(), '_' . $key );
'sale_price_dates_to',
'post',
'download_type',
'product_image_gallery',
'variation_shipping_class',
'shipping_class',
'total_stock',
'crosssell_ids',
'parent',
), array_keys( $this->data ) ) ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) || metadata_exists( 'post', $this->get_parent_id(), '_' . $key );
} }
/** /**
@ -71,9 +75,6 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
case 'id' : case 'id' :
$value = $this->is_type( 'variation' ) ? $this->get_parent_id() : $this->get_id(); $value = $this->is_type( 'variation' ) ? $this->get_parent_id() : $this->get_id();
break; break;
case 'variation_id' :
$value = $this->get_id();
break;
case 'product_attributes' : case 'product_attributes' :
$value = isset( $this->data['attributes'] ) ? $this->data['attributes'] : ''; $value = isset( $this->data['attributes'] ) ? $this->data['attributes'] : '';
break; break;
@ -118,14 +119,17 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
case 'parent' : case 'parent' :
$value = wc_get_product( $this->get_parent_id() ); $value = wc_get_product( $this->get_parent_id() );
break; break;
case 'variation_id' :
$value = $this->is_type( 'variation' ) ? $this->get_id() : '';
break;
case 'variation_data' : case 'variation_data' :
$value = wc_get_product_variation_attributes( $this->get_id() ); $value = $this->is_type( 'variation' ) ? wc_get_product_variation_attributes( $this->get_id() ) : '';
break; break;
case 'variation_has_stock' : case 'variation_has_stock' :
$value = $this->managing_stock(); $value = $this->is_type( 'variation' ) ? $this->managing_stock() : '';
break; break;
case 'variation_shipping_class_id' : case 'variation_shipping_class_id' :
$value = $this->get_shipping_class_id(); $value = $this->is_type( 'variation' ) ? $this->get_shipping_class_id() : '';
break; break;
default : default :
if ( in_array( $key, array_keys( $this->data ) ) ) { if ( in_array( $key, array_keys( $this->data ) ) ) {