Merge pull request #12435 from woocommerce/data-store-naming

Interface naming
This commit is contained in:
Justin Shreve 2016-11-22 08:02:09 -08:00 committed by GitHub
commit 2d5da279b6
33 changed files with 43 additions and 45 deletions

View File

@ -115,7 +115,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
$this->set_object_read( true );
}
$this->data_store = WC_Data_Store::load( 'product_' . $this->get_type() );
$this->data_store = WC_Data_Store::load( 'product-' . $this->get_type() );
if ( $this->get_id() > 0 ) {
$this->data_store->read( $this );
}

View File

@ -42,9 +42,9 @@ class WC_Data_Store {
'order-item-tax' => 'WC_Order_Item_Tax_Data_Store',
'payment-token' => 'WC_Payment_Token_Data_Store',
'product' => 'WC_Product_Data_Store_CPT',
'product_grouped' => 'WC_Product_Grouped_Data_Store_CPT',
'product_variable' => 'WC_Product_Variable_Data_Store_CPT',
'product_variation' => 'WC_Product_Variation_Data_Store_CPT',
'product-grouped' => 'WC_Product_Grouped_Data_Store_CPT',
'product-variable' => 'WC_Product_Variable_Data_Store_CPT',
'product-variation' => 'WC_Product_Variation_Data_Store_CPT',
'shipping-zone' => 'WC_Shipping_Zone_Data_Store',
);
@ -63,9 +63,9 @@ class WC_Data_Store {
$this->stores = apply_filters( 'woocommerce_data_stores', $this->stores );
// If this object type can't be found, check to see if we can load one
// level up (so if product_type isn't found, we try product).
// level up (so if product-type isn't found, we try product).
if ( ! array_key_exists( $object_type, $this->stores ) ) {
$pieces = explode( '_', $object_type );
$pieces = explode( '-', $object_type );
$object_type = $pieces[0];
}

View File

@ -168,7 +168,7 @@ class WC_Product_Grouped extends WC_Product {
$product = wc_get_product( $product );
}
if ( is_a( $product, 'WC_Product_Grouped' ) ) {
$data_store = WC_Data_Store::load( 'product_' . $product->get_type() );
$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );
$data_store->sync_price( $product );
if ( $save ) {
$product->save();

View File

@ -387,7 +387,7 @@ class WC_Product_Variable extends WC_Product {
* @return bool
*/
public function is_on_sale() {
$data_store = WC_Data_Store::load( 'product_variable' );
$data_store = WC_Data_Store::load( 'product-variable' );
$prices = $data_store->read_price_data( $this );
return apply_filters( 'woocommerce_product_is_on_sale', $prices['regular_price'] !== $prices['sale_price'] && $prices['sale_price'] === $prices['price'], $this );
}
@ -489,7 +489,7 @@ class WC_Product_Variable extends WC_Product {
$product = wc_get_product( $product );
}
if ( is_a( $product, 'WC_Product_Variable' ) ) {
$data_store = WC_Data_Store::load( 'product_' . $product->get_type() );
$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );
$data_store->sync_price( $product );
$data_store->sync_stock_status( $product );
self::sync_attributes( $product ); // Legacy update of attributes.
@ -515,7 +515,7 @@ class WC_Product_Variable extends WC_Product {
$product = wc_get_product( $product );
}
if ( is_a( $product, 'WC_Product_Variable' ) ) {
$data_store = WC_Data_Store::load( 'product_' . $product->get_type() );
$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );
$data_store->sync_stock_status( $product );
if ( $save ) {

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store, WC_Abstract_Order_Data_Store_Interface {
abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface, WC_Abstract_Order_Data_Store_Interface {
/**
* Internal meta type used to store order data.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
abstract class Abstract_WC_Order_Item_Type_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store {
abstract class Abstract_WC_Order_Item_Type_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
/**
* Create a new order item in the database.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Data_Store, WC_Object_Data_Store {
class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Data_Store_Interface, WC_Object_Data_Store_Interface {
/**
* Internal meta type used to store coupon data.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Customer_Data_Store_Interface, WC_Object_Data_Store {
class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Customer_Data_Store_Interface, WC_Object_Data_Store_Interface {
/**
* Keys which are also stored in a session (so we can make sure they get updated...)

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Data_Store_Interface, WC_Object_Data_Store {
class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Data_Store_Interface, WC_Object_Data_Store_Interface {
/**
* Data stored in meta keys, but not considered "meta".

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store, WC_Order_Data_Store_Interface {
class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Data_Store_Interface {
/**
* Data stored in meta keys, but not considered "meta" for an order.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Order_Item_Coupon_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store, WC_Order_Item_Type_Data_Store_Interface {
class WC_Order_Item_Coupon_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface {
/**
* Read/populate data properties specific to this order item.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Order_Item_Fee_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store, WC_Order_Item_Type_Data_Store_Interface {
class WC_Order_Item_Fee_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface {
/**
* Read/populate data properties specific to this order item.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Order_Item_Product_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store, WC_Order_Item_Type_Data_Store_Interface, WC_Order_Item_Product_Data_Store_Interface {
class WC_Order_Item_Product_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface, WC_Order_Item_Product_Data_Store_Interface {
/**
* Read/populate data properties specific to this order item.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Order_Item_Shipping_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store, WC_Order_Item_Type_Data_Store_Interface {
class WC_Order_Item_Shipping_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface {
/**
* Read/populate data properties specific to this order item.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store, WC_Order_Item_Type_Data_Store_Interface {
class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface {
/**
* Read/populate data properties specific to this order item.
*

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store, WC_Order_Refund_Data_Store_Interface {
class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Refund_Data_Store_Interface {
/**
* Data stored in meta keys, but not considered "meta" for an order.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment_Token_Data_Store_Interface, WC_Object_Data_Store {
class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment_Token_Data_Store_Interface, WC_Object_Data_Store_Interface {
/**
* Meta type. Payment tokens are a new object type.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store, WC_Product_Data_Store_Interface {
class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface, WC_Product_Data_Store_Interface {
/**
* Data stored in meta keys, but not considered "meta".

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Product_Grouped_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store {
class WC_Product_Grouped_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store_Interface {
/**
* Helper method that updates all the post meta for a grouped product.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store, WC_Product_Variable_Data_Store_Interface {
class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Product_Variable_Data_Store_Interface {
/**
* Cached & hashed prices array for child variations.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store {
class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT implements WC_Object_Data_Store_Interface {
/**
* Callback to remove unwanted meta data.

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooCommerce
*/
class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Shipping_Zone_Data_Store_Interface, WC_Object_Data_Store {
class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Shipping_Zone_Data_Store_Interface, WC_Object_Data_Store_Interface {
/**
* Method to create a new shipping zone.

View File

@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Interface
* @author WooThemes
*/
interface WC_Coupon_Data_Store {
interface WC_Coupon_Data_Store_Interface {
/**
* Increase usage count for current coupon.
* @param WC_Coupon

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Interface
* @author WooThemes
*/
interface WC_Object_Data_Store {
interface WC_Object_Data_Store_Interface {
/**
* Method to create a new record of a WC_Data based object.
* @param WC_Data

View File

@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Class
* @author WooThemes
*/
class WC_Dummy_Data_Store_CPT implements WC_Object_Data_Store {
class WC_Dummy_Data_Store_CPT implements WC_Object_Data_Store_Interface {
public function create( &$data ) { }
public function read( &$data ) { }
public function update( &$data ) { }
@ -32,7 +32,7 @@ class WC_Dummy_Data_Store_CPT implements WC_Object_Data_Store {
* @category Class
* @author WooThemes
*/
class WC_Dummy_Data_Store_Custom_Table implements WC_Object_Data_Store {
class WC_Dummy_Data_Store_Custom_Table implements WC_Object_Data_Store_Interface {
public function create( &$data ) { }
public function read( &$data ) { }
public function update( &$data ) { }

View File

@ -1,5 +1,5 @@
<?php
class WC_Mock_WC_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store {
class WC_Mock_WC_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
protected $meta_type = 'post';
protected $object_id_field_for_meta = '';

View File

@ -28,7 +28,7 @@ class WC_Tests_Data_Store extends WC_Unit_Test_Case {
* @since 2.7.0
*/
function test_invalid_store_load_returns_null() {
$product_store = WC_Data_Store::load( 'product-test' );
$product_store = WC_Data_Store::load( 'does-not-exist' );
$this->assertNull( $product_store );
}
@ -58,14 +58,14 @@ class WC_Tests_Data_Store extends WC_Unit_Test_Case {
*/
function test_store_sub_type() {
$this->load_dummy_store();
$store = WC_Data_Store::load( 'dummy_sub' );
$store = WC_Data_Store::load( 'dummy-sub' );
$this->assertEquals( 'WC_Dummy_Data_Store_CPT', $store->get_current_class_name() );
}
/* Helper Functions. */
/**
* Loads two dummy data store classes that can be swapt out for each other. Adds to the `woocommerce_data_stores` filter.
* Loads two dummy data store classes that can be swapped out for each other. Adds to the `woocommerce_data_stores` filter.
*
* @since 2.7.0
*/

View File

@ -284,23 +284,21 @@ final class WooCommerce {
include_once( WC_ABSPATH . 'includes/class-wc-integrations.php' ); // Loads integrations
include_once( WC_ABSPATH . 'includes/class-wc-cache-helper.php' ); // Cache Helper
include_once( WC_ABSPATH . 'includes/class-wc-https.php' ); // https Helper
include_once( WC_ABSPATH . 'includes/class-wc-data-store.php' ); // WC_Data_Store for CRUD
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/interface-wc-object-data-store.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/interface-wc-coupon-data-store.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-object-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-coupon-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-product-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-product-variable-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-customer-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-customer-download-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/class-wc-payment-token-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/class-wc-shipping-zone-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-payment-token-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-shipping-zone-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-abstract-order-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-order-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-order-refund-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/class-wc-order-item-type-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/class-wc-order-item-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/class-wc-order-item-product-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-order-item-type-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-order-item-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/interfaces/wc-order-item-product-data-store-interface.php' );
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-data-store-wp.php' );
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-coupon-data-store-cpt.php' );
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-data-store-cpt.php' );