Add data and tostring handling to WC_Data

This commit is contained in:
Mike Jolley 2016-03-17 15:22:29 +00:00
parent 9ce1a21271
commit 6765967be8
1 changed files with 22 additions and 6 deletions

View File

@ -15,6 +15,12 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
abstract class WC_Data {
/**
* Core data for this object, name value pairs (name + default value).
* @var array
*/
protected $_data = array();
/**
* Stores meta in cache for future reads.
* A group must be set to to enable caching.
@ -55,12 +61,6 @@ abstract class WC_Data {
*/
abstract public function get_id();
/**
* Returns all data for this object.
* @return array
*/
abstract public function get_data();
/**
* Creates new object in the database.
*/
@ -87,6 +87,22 @@ abstract class WC_Data {
*/
abstract public function save();
/**
* Change data to JSON format.
* @return string Data in JSON format.
*/
public function __toString() {
return json_encode( $this->get_data() );
}
/**
* Returns all data for this object.
* @return array
*/
public function get_data() {
return array_merge( $this->_data, array( 'meta_data' => $this->get_meta_data() ) );
}
/**
* Get All Meta Data
* @since 2.6.0