SlideShare a Scribd company logo
WooCommerce CRUD
and Data Store
Akeda Bagus
Akeda Bagus
• Code wrangler at
Automattic.
• Currently working on
WooCommerce
extensions and
marketplace.
CRUD and Data Store
in WooCommerce?
Why we need that?
Create, Read, Update, Delete
• WooCommerce has some resource types: orders, products, customers,
coupons, etc.
• With CRUD in resource, the developer doesn’t need to know the internal
complexities when interacting with WooCommerce resource types.
• Increase DRY. It can be used in WooCommerce REST API and CLIs.
• Once abstracted, the underlying data storage of resource can be
anything (CPT, custom table, external service, or dummy storage).
• Increase test coverage.
• For more detail see https://woocommerce.wordpress.com/2016/10/27/
the-new-crud-classes-in-woocommerce-2-7/.
Resource Interaction
without Data CRUD
$order_id = 123;
// Retrieving.
$billing_name = get_post_meta( $order_id,
‘_billing_first_name’, true ) . ‘ ‘ . get_post_meta( $order_id,
‘_billing_last_name’, true );
// Updating.
update_post_meta( $order_id, ‘_billing_first_name’, ‘Akeda’ );
update_post_meta( $order_id, ‘_billing_last_name’, ‘Bagus’ );
Resource Interaction
without Data CRUD
• Developer needs to know WooCommerce meta
keys and expected value’s type to store for each
resource type.
• Data storage is tied to WP tables.
• Unit test needs to be set up with the test DB unless
all WP dependencies are mocked.
Resource Interaction
with Data CRUD
$order_id = 123;
$order = wc_get_order( $order_id );
// Retrieving.
$billing_name = $order->get_billing_first_name() . ‘ ‘ .
$order->get_billing_last_name();
// Updating.
$order->set_billing_first_name( ‘Akeda’ );
$order->set_billing_last_name( ‘Bagus’ );
$order->save();
Resource Interaction
with Data CRUD
• Developer only needs to know the Data CRUD
methods.
• Data CRUD objects handle flow of data and any
validations. Less work for developers!
• Easier to test the resource.
Resource Interaction
with Data CRUD
// Setters and getters on the resource.
// Basically set_{property} and get_{property}.
$product = wc_get_product( 123 );
$product->set_description( ‘My cool product’ );
$product->set_sku( ‘WOO123’ );
$product->set_price( 15000 );
$product->get_description(); // My cool product
$product->get_sku(); // WOO123
$product->get_price(); // 15000
Resource Interaction
with Data CRUD
// Saving and deleting with save() and delete().
$product = wc_get_product( 123 );
$product->set_price( 25000 );
// Internally, this will pass the action to the data store to
// persist the change. If no ID, it implies creation otherwise
// it will update existing product.
$product->save();
// This will delete the product from the DB.
$product->delete();
Resource Interaction
with Data CRUD
• All properties on resource types can be found at WooCommerce
GitHub’s wiki.
• https://github.com/woocommerce/woocommerce/wiki/CRUD-Objects-
in-3.0
• Once you know available properties, the pattern is easy to remember:
• get_{property} to retrieve the property.
• set_{property} to set the property.
• Use save() and delete() to create/update and delete the
resource.
Resource Interaction
with Data CRUD
• All Data CRUD objects must extend abstract WC_Data.
• WC_Data handles the communication with the data store, so the
implementation only needs to extend the abstract and define some
properties that are available via setters and getters.
• Examples of WooCommerce Data CRUD classes:
• WC_Coupon
• WC_Order
• WC_Product
• WC_Customer
Data Store
• Bridge Data CRUDs and storage layer.
• If Data CRUDs need data, they ask Data Store.
Same thing when saving and deleting.
• Data Store can be powered by CPT, custom table,
remote API, or anything. It’s easy to swap the data
store of a Data CRUD class.
• WooCommerce built-in Data CRUDs are shipped
with CPT and custom table Data Store.
Data Store
• Data Store should be started by defining interface. The implementation can
be CPT, custom table, external API, or anything.
• Methods defined in the interface can be create(), read(),
read_meta(), delete_meta(), etc.
• Every Data Store for Data CRUD object should implement that interface. For
CPT, the create() could use wp_insert_post(), while for external API
the create() could use wp_remote_post().
• A method may accepts reference to $data, which has a type of WC_Data.
• For more detail see https://github.com/woocommerce/woocommerce/wiki/
Data-Stores.
Data Store
// Example of Data Store interface.
interface WC_Object_Data_Store_Interface {
public function create( &$data );
public function read( &$data );
public function update( &$data );
public function delete( &$data, $args = array() );
public function read_meta( &$data );
public function delete_meta( &$data, $meta );
public function add_meta( &$data, $meta );
public function update_meta( &$data, $meta );
}
Data Store
// Example create() method from Coupon CPT Data Store. With CPT
// as the underlying storage, create() uses wp_insert_post().
public function create( WC_Coupon &$coupon ) {
// ...
$coupon_id = wp_insert_post( [
‘post_type’ => ‘shop_coupon’,
‘post_title’ => $coupon->get_code(),
// ...
] );
if ( $coupon_id ) {
$coupon->set_id( $coupon_id );
// ...
}
}
Data Store
// Example delete_order_item() method from order item
// Data Store which uses custom table.
public function delete_order_item( $item_id ) {
global $wpdb;
$wpdb->query( /* ... */ );
$wpdb->query( /* ... */ );
}
Data Store
// Example create() with external API request.
public function create( WC_Data &$data ) {
// ...
$result = wp_remote_post( /* ... */ );
if ( ! empty( $result[‘id’] ) ) {
$data->set_id( $result[‘id’] );
}
// ...
}
Data CRUD and Data Store Interaction
Data CRUD and Data Store Interaction
Data CRUD and Data Store Interaction
Data CRUD and Data Store Interaction
Creating your own CRUD
in your extension (CPT Data Store)
• Let’s use Restaurant as an example of a custom resource.
• First, define some properties that a Restaurant needs. For example:
• Name
• Address
• Cuisine
• Opening hours
• Map the properties in the CRUD class.
• Start Restaurant data store by using CPT as the underlying storage.
Creating your own CRUD
in your extension (CPT Data Store)
namespace GedexWCJKTRestaurantData_Objects;
class Restaurant extends WC_Data {
// Name value pairs (name => default value).
protected $data = [
‘name’ => ‘’,
‘address’ => ‘’,
‘cuisine’ => ‘’,
‘opening_hours’ => ‘9am - 10pm’,
];
public function __construct( $restaurant = 0 ) { ... }
public function get_name( $context = ‘view’ ) { ... }
public function set_name( $name ) { ... }
}
Creating your own CRUD
in your extension (CPT Data Store)
namespace GedexWCJKTRestaurantData_Objects;
class Restaurant extends WC_Data {
public function __construct( $restaurant = 0 ) {
parent::__construct( $restaurant );
if ( is_numeric( $restaurant ) && $restaurant > 0 ) {
$this->set_id( $restaurant );
} elseif ( $restaurant instanceof self ) {
$this->set_id( $restaurant->get_id() );
} else if ( ! empty( $restaurant->ID ) ) {
$this->set_id( $restaurant->ID );
} else {
$this->set_object_read( true );
}
$this->data_store = WC_Data_Store::load( ‘restaurant’ );
if ( $this->get_id() > 0 ) {
$this->data_store->read( $this );
}
}
}
Creating your own CRUD
in your extension (CPT Data Store)
namespace GedexWCJKTRestaurantData_Objects;
class Restaurant extends WC_Data {
public function get_name( $context = ‘view’ ) {
return $this->get_prop( ‘name’, $context );
}
public function set_name( $name ) {
$this->set_prop( ‘name’, $name )
}
// Do the same for other properties.
// ...
}
Creating your own CRUD
in your extension (CPT Data Store)
namespace GedexWCJKTRestaurantData_Stores;
use GedexWCJKTRestaurantData_ObjectsRestaurant;
interface Restaurant_Interface {
public function create( Restaurant &$restaurant );
public function read( Restaurant &$restaurant );
public function update( Restaurant &$restaurant );
public function delete( Restaurant &$restaurant );
}
Creating your own CRUD
in your extension (CPT Data Store)
namespace GedexWCJKTRestaurantData_Stores;
use GedexWCJKTRestaurantData_ObjectsRestaurant;
class Restaurant_CPT extends WC_Data_Store_WP
implements Restaurant_Interface
{
public function create( Restaurant &$restaurant ) { }
public function read( Restaurant &$restaurant ) { }
public function update( Restaurant &$restaurant ) { }
public function delete( Restaurant &$restaurant ) { }
}
Creating your own CRUD
in your extension (CPT Data Store)
• Let’s see in action.
More Information for Data CRUD and Data
Store
• https://github.com/woocommerce/woocommerce/wiki/
CRUD-Objects-in-3.0
• https://github.com/woocommerce/woocommerce/wiki/
Data-Stores
• Order with custom table is scheduled in Q1 2018. See
the roadmap: https://trello.com/c/2QGrEbBW/113-an-
order-database-that-can-scale-feature-plugin.
• If you develop WooCommerce extension make sure it’s
ready for this.
Thank you!

More Related Content

What's hot

50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
Azim Kurt
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
Marco Vito Moscaritolo
 
Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in Drupal
Fredric Mitchell
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Acquia
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Alessandro Nadalin
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
Rafael Dohms
 
Hibernate
HibernateHibernate
Hibernate
Leonardo Passos
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ivan Chepurnyi
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
Markus Wolff
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
Jeff Eaton
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql Azure
Maarten Balliauw
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
Ivan Chepurnyi
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
Almog Baku
 
Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017
Atenea tech
 
Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)
brockboland
 

What's hot (20)

50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in Drupal
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Hibernate
HibernateHibernate
Hibernate
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql Azure
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017
 
Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)
 

Viewers also liked

Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
WordCamp Indonesia
 
Headless CMS featuring WordPress by Dreb Bits
Headless CMS featuring WordPress by Dreb BitsHeadless CMS featuring WordPress by Dreb Bits
Headless CMS featuring WordPress by Dreb Bits
WordCamp Indonesia
 
Gutenberg for Modern Editing by Niels Lange
Gutenberg for Modern Editing by Niels LangeGutenberg for Modern Editing by Niels Lange
Gutenberg for Modern Editing by Niels Lange
WordCamp Indonesia
 
Independent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
Independent Digital Worker ( Digital Nomad ) by Victorina AugusklamasiaIndependent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
Independent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
WordCamp Indonesia
 
Lesson Learned: My Freelance Experience by Aris Setiawan
Lesson Learned: My Freelance Experience by Aris SetiawanLesson Learned: My Freelance Experience by Aris Setiawan
Lesson Learned: My Freelance Experience by Aris Setiawan
WordCamp Indonesia
 
Multisite Implementation Within Nonprofit Organization by Wigid Triyadi
Multisite Implementation Within Nonprofit Organization by Wigid TriyadiMultisite Implementation Within Nonprofit Organization by Wigid Triyadi
Multisite Implementation Within Nonprofit Organization by Wigid Triyadi
WordCamp Indonesia
 
Five Things to Worry Later for Stress-free Site Making by Hafiz Rahman
Five Things to Worry Later for Stress-free Site Making by Hafiz RahmanFive Things to Worry Later for Stress-free Site Making by Hafiz Rahman
Five Things to Worry Later for Stress-free Site Making by Hafiz Rahman
WordCamp Indonesia
 
Optimizing Your Travel Blog by Farchan Noorrachman
Optimizing Your Travel Blog by Farchan NoorrachmanOptimizing Your Travel Blog by Farchan Noorrachman
Optimizing Your Travel Blog by Farchan Noorrachman
WordCamp Indonesia
 
How to build an online shop using WooCommerce for Indonesian Market by Agus m...
How to build an online shop using WooCommerce for Indonesian Market by Agus m...How to build an online shop using WooCommerce for Indonesian Market by Agus m...
How to build an online shop using WooCommerce for Indonesian Market by Agus m...
WordCamp Indonesia
 
Experience to Share: Paragraph Improvisation by Indri handayani
Experience to Share: Paragraph Improvisation by Indri handayaniExperience to Share: Paragraph Improvisation by Indri handayani
Experience to Share: Paragraph Improvisation by Indri handayani
WordCamp Indonesia
 

Viewers also liked (10)

Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
Performance Tuning and Security Hardening using Drop-In and Must-Use Plugins ...
 
Headless CMS featuring WordPress by Dreb Bits
Headless CMS featuring WordPress by Dreb BitsHeadless CMS featuring WordPress by Dreb Bits
Headless CMS featuring WordPress by Dreb Bits
 
Gutenberg for Modern Editing by Niels Lange
Gutenberg for Modern Editing by Niels LangeGutenberg for Modern Editing by Niels Lange
Gutenberg for Modern Editing by Niels Lange
 
Independent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
Independent Digital Worker ( Digital Nomad ) by Victorina AugusklamasiaIndependent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
Independent Digital Worker ( Digital Nomad ) by Victorina Augusklamasia
 
Lesson Learned: My Freelance Experience by Aris Setiawan
Lesson Learned: My Freelance Experience by Aris SetiawanLesson Learned: My Freelance Experience by Aris Setiawan
Lesson Learned: My Freelance Experience by Aris Setiawan
 
Multisite Implementation Within Nonprofit Organization by Wigid Triyadi
Multisite Implementation Within Nonprofit Organization by Wigid TriyadiMultisite Implementation Within Nonprofit Organization by Wigid Triyadi
Multisite Implementation Within Nonprofit Organization by Wigid Triyadi
 
Five Things to Worry Later for Stress-free Site Making by Hafiz Rahman
Five Things to Worry Later for Stress-free Site Making by Hafiz RahmanFive Things to Worry Later for Stress-free Site Making by Hafiz Rahman
Five Things to Worry Later for Stress-free Site Making by Hafiz Rahman
 
Optimizing Your Travel Blog by Farchan Noorrachman
Optimizing Your Travel Blog by Farchan NoorrachmanOptimizing Your Travel Blog by Farchan Noorrachman
Optimizing Your Travel Blog by Farchan Noorrachman
 
How to build an online shop using WooCommerce for Indonesian Market by Agus m...
How to build an online shop using WooCommerce for Indonesian Market by Agus m...How to build an online shop using WooCommerce for Indonesian Market by Agus m...
How to build an online shop using WooCommerce for Indonesian Market by Agus m...
 
Experience to Share: Paragraph Improvisation by Indri handayani
Experience to Share: Paragraph Improvisation by Indri handayaniExperience to Share: Paragraph Improvisation by Indri handayani
Experience to Share: Paragraph Improvisation by Indri handayani
 

Similar to WooCommerce CRUD and Data Store by Akeda Bagus

Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
Ivan Chepurnyi
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
Career at Elsner
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
Jason Ragsdale
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
Eric Maxwell
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
andrewnacin
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
Jace Ju
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesNCCOMMS
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
Mark
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
Joey Kudish
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
Chris Scott
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
Agile Data concept introduction
Agile Data   concept introductionAgile Data   concept introduction
Agile Data concept introduction
Romans Malinovskis
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
Chris Scott
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
Michelangelo van Dam
 
Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01
Jason Noble
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 

Similar to WooCommerce CRUD and Data Store by Akeda Bagus (20)

Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Agile Data concept introduction
Agile Data   concept introductionAgile Data   concept introduction
Agile Data concept introduction
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 

Recently uploaded

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

WooCommerce CRUD and Data Store by Akeda Bagus

  • 1. WooCommerce CRUD and Data Store Akeda Bagus
  • 2. Akeda Bagus • Code wrangler at Automattic. • Currently working on WooCommerce extensions and marketplace.
  • 3. CRUD and Data Store in WooCommerce? Why we need that?
  • 4. Create, Read, Update, Delete • WooCommerce has some resource types: orders, products, customers, coupons, etc. • With CRUD in resource, the developer doesn’t need to know the internal complexities when interacting with WooCommerce resource types. • Increase DRY. It can be used in WooCommerce REST API and CLIs. • Once abstracted, the underlying data storage of resource can be anything (CPT, custom table, external service, or dummy storage). • Increase test coverage. • For more detail see https://woocommerce.wordpress.com/2016/10/27/ the-new-crud-classes-in-woocommerce-2-7/.
  • 5. Resource Interaction without Data CRUD $order_id = 123; // Retrieving. $billing_name = get_post_meta( $order_id, ‘_billing_first_name’, true ) . ‘ ‘ . get_post_meta( $order_id, ‘_billing_last_name’, true ); // Updating. update_post_meta( $order_id, ‘_billing_first_name’, ‘Akeda’ ); update_post_meta( $order_id, ‘_billing_last_name’, ‘Bagus’ );
  • 6. Resource Interaction without Data CRUD • Developer needs to know WooCommerce meta keys and expected value’s type to store for each resource type. • Data storage is tied to WP tables. • Unit test needs to be set up with the test DB unless all WP dependencies are mocked.
  • 7. Resource Interaction with Data CRUD $order_id = 123; $order = wc_get_order( $order_id ); // Retrieving. $billing_name = $order->get_billing_first_name() . ‘ ‘ . $order->get_billing_last_name(); // Updating. $order->set_billing_first_name( ‘Akeda’ ); $order->set_billing_last_name( ‘Bagus’ ); $order->save();
  • 8. Resource Interaction with Data CRUD • Developer only needs to know the Data CRUD methods. • Data CRUD objects handle flow of data and any validations. Less work for developers! • Easier to test the resource.
  • 9. Resource Interaction with Data CRUD // Setters and getters on the resource. // Basically set_{property} and get_{property}. $product = wc_get_product( 123 ); $product->set_description( ‘My cool product’ ); $product->set_sku( ‘WOO123’ ); $product->set_price( 15000 ); $product->get_description(); // My cool product $product->get_sku(); // WOO123 $product->get_price(); // 15000
  • 10. Resource Interaction with Data CRUD // Saving and deleting with save() and delete(). $product = wc_get_product( 123 ); $product->set_price( 25000 ); // Internally, this will pass the action to the data store to // persist the change. If no ID, it implies creation otherwise // it will update existing product. $product->save(); // This will delete the product from the DB. $product->delete();
  • 11. Resource Interaction with Data CRUD • All properties on resource types can be found at WooCommerce GitHub’s wiki. • https://github.com/woocommerce/woocommerce/wiki/CRUD-Objects- in-3.0 • Once you know available properties, the pattern is easy to remember: • get_{property} to retrieve the property. • set_{property} to set the property. • Use save() and delete() to create/update and delete the resource.
  • 12. Resource Interaction with Data CRUD • All Data CRUD objects must extend abstract WC_Data. • WC_Data handles the communication with the data store, so the implementation only needs to extend the abstract and define some properties that are available via setters and getters. • Examples of WooCommerce Data CRUD classes: • WC_Coupon • WC_Order • WC_Product • WC_Customer
  • 13. Data Store • Bridge Data CRUDs and storage layer. • If Data CRUDs need data, they ask Data Store. Same thing when saving and deleting. • Data Store can be powered by CPT, custom table, remote API, or anything. It’s easy to swap the data store of a Data CRUD class. • WooCommerce built-in Data CRUDs are shipped with CPT and custom table Data Store.
  • 14. Data Store • Data Store should be started by defining interface. The implementation can be CPT, custom table, external API, or anything. • Methods defined in the interface can be create(), read(), read_meta(), delete_meta(), etc. • Every Data Store for Data CRUD object should implement that interface. For CPT, the create() could use wp_insert_post(), while for external API the create() could use wp_remote_post(). • A method may accepts reference to $data, which has a type of WC_Data. • For more detail see https://github.com/woocommerce/woocommerce/wiki/ Data-Stores.
  • 15. Data Store // Example of Data Store interface. interface WC_Object_Data_Store_Interface { public function create( &$data ); public function read( &$data ); public function update( &$data ); public function delete( &$data, $args = array() ); public function read_meta( &$data ); public function delete_meta( &$data, $meta ); public function add_meta( &$data, $meta ); public function update_meta( &$data, $meta ); }
  • 16. Data Store // Example create() method from Coupon CPT Data Store. With CPT // as the underlying storage, create() uses wp_insert_post(). public function create( WC_Coupon &$coupon ) { // ... $coupon_id = wp_insert_post( [ ‘post_type’ => ‘shop_coupon’, ‘post_title’ => $coupon->get_code(), // ... ] ); if ( $coupon_id ) { $coupon->set_id( $coupon_id ); // ... } }
  • 17. Data Store // Example delete_order_item() method from order item // Data Store which uses custom table. public function delete_order_item( $item_id ) { global $wpdb; $wpdb->query( /* ... */ ); $wpdb->query( /* ... */ ); }
  • 18. Data Store // Example create() with external API request. public function create( WC_Data &$data ) { // ... $result = wp_remote_post( /* ... */ ); if ( ! empty( $result[‘id’] ) ) { $data->set_id( $result[‘id’] ); } // ... }
  • 19. Data CRUD and Data Store Interaction
  • 20. Data CRUD and Data Store Interaction
  • 21. Data CRUD and Data Store Interaction
  • 22. Data CRUD and Data Store Interaction
  • 23. Creating your own CRUD in your extension (CPT Data Store) • Let’s use Restaurant as an example of a custom resource. • First, define some properties that a Restaurant needs. For example: • Name • Address • Cuisine • Opening hours • Map the properties in the CRUD class. • Start Restaurant data store by using CPT as the underlying storage.
  • 24. Creating your own CRUD in your extension (CPT Data Store) namespace GedexWCJKTRestaurantData_Objects; class Restaurant extends WC_Data { // Name value pairs (name => default value). protected $data = [ ‘name’ => ‘’, ‘address’ => ‘’, ‘cuisine’ => ‘’, ‘opening_hours’ => ‘9am - 10pm’, ]; public function __construct( $restaurant = 0 ) { ... } public function get_name( $context = ‘view’ ) { ... } public function set_name( $name ) { ... } }
  • 25. Creating your own CRUD in your extension (CPT Data Store) namespace GedexWCJKTRestaurantData_Objects; class Restaurant extends WC_Data { public function __construct( $restaurant = 0 ) { parent::__construct( $restaurant ); if ( is_numeric( $restaurant ) && $restaurant > 0 ) { $this->set_id( $restaurant ); } elseif ( $restaurant instanceof self ) { $this->set_id( $restaurant->get_id() ); } else if ( ! empty( $restaurant->ID ) ) { $this->set_id( $restaurant->ID ); } else { $this->set_object_read( true ); } $this->data_store = WC_Data_Store::load( ‘restaurant’ ); if ( $this->get_id() > 0 ) { $this->data_store->read( $this ); } } }
  • 26. Creating your own CRUD in your extension (CPT Data Store) namespace GedexWCJKTRestaurantData_Objects; class Restaurant extends WC_Data { public function get_name( $context = ‘view’ ) { return $this->get_prop( ‘name’, $context ); } public function set_name( $name ) { $this->set_prop( ‘name’, $name ) } // Do the same for other properties. // ... }
  • 27. Creating your own CRUD in your extension (CPT Data Store) namespace GedexWCJKTRestaurantData_Stores; use GedexWCJKTRestaurantData_ObjectsRestaurant; interface Restaurant_Interface { public function create( Restaurant &$restaurant ); public function read( Restaurant &$restaurant ); public function update( Restaurant &$restaurant ); public function delete( Restaurant &$restaurant ); }
  • 28. Creating your own CRUD in your extension (CPT Data Store) namespace GedexWCJKTRestaurantData_Stores; use GedexWCJKTRestaurantData_ObjectsRestaurant; class Restaurant_CPT extends WC_Data_Store_WP implements Restaurant_Interface { public function create( Restaurant &$restaurant ) { } public function read( Restaurant &$restaurant ) { } public function update( Restaurant &$restaurant ) { } public function delete( Restaurant &$restaurant ) { } }
  • 29. Creating your own CRUD in your extension (CPT Data Store) • Let’s see in action.
  • 30. More Information for Data CRUD and Data Store • https://github.com/woocommerce/woocommerce/wiki/ CRUD-Objects-in-3.0 • https://github.com/woocommerce/woocommerce/wiki/ Data-Stores • Order with custom table is scheduled in Q1 2018. See the roadmap: https://trello.com/c/2QGrEbBW/113-an- order-database-that-can-scale-feature-plugin. • If you develop WooCommerce extension make sure it’s ready for this.