Extending crud datastore in woocommerce

Have you ever heard of crud? In programming, create, read, u pdate and delete represent the basic tasks that all of us perform with data. Woocommerce contains products, orders, customers, coupons, and other data stored in the database. Woocommerce’s recent changes to crud mean that the platform is becoming more scalable. Note: this post contains technical content, assuming a specific level of convenience for PHP code. Audio learner? The main point of this article is my speech in wooconf 2017.
In order to make the life of woocommerce developers easier, woocommerce 3.0 adds a special crud object. This will replace all the old post metacode of woocommerce and allow woocommerce site extension, which must be used by all extensions. At the same time, another set of objects, named data repository, is added to the database, which is designed to load and store woocommerce data. These abstractions are designed to help woocomerce handle more orders, products and customers. This is achieved by connecting woocommerce and using other means to store data.
Each data storage implementation determines how data is stored and retrieved in a database or other methods of storing data together. This allows woocommerce to expand to enterprise sales volumes to handle millions of orders. What you need to do is connect the filter that woocomer uses to store data to an overlay filter. In addition to the performance enhancements provided by crud and data storage abstraction, these configurations also provide greater flexibility for woocommerce to store and load data. Now, for each type of woocommerce data (product, order, customer, etc.), you can programmatically decide where the data comes from and where to go. This allows the store builder to interact with other systems, customize woocommerce as needed, or upgrade the performance of other parts of woocommerce as needed.
In addition to the performance enhancements provided by crud and data storage abstraction, these configurations also provide greater flexibility for woocommerce to store and load data. Exactly, what does that mean? Well, please consider the possibility. Store order data in wpdb and other databases. Import product data from existing databases in other systems. Share product inventory across multiple sites (example below). Import product data from other sources via API. Create cli commands, load from one data repository and save to another (built-in import \/ export). By extending data storage crud and abstract data storage, woocommerce no longer focuses on the source or storage of data. You can control all this yourself.
The following example queries the inventory quantity in a separate service and only changes the inventory quantity of each commodity object. One advantage of this is that you can sell multiple woocommerce websites with the same inventory and ensure that the inventory is not oversold. The following is the entry point install_data_store filter:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than
code text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters

class WC_Product_Inventory_Data_Store

implements WC_Object_Data_Store_Interface, WC_Product_Data_Store_Interface {

public function __construct( &$parent_data_store ) {

$this- > parent_instance = $this- > create_parent_instance( $parent_data_store );

}

view raw
class-product-inventory-data-store. php
hosted with ❤ by GitHub
For most required functions, the data repository calls the parent data repository.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters

public function update( &$product ) {

$this- > parent_instance- > update( $product );

}

view raw
class-product-inventory-data-store. php
hosted with ❤ by GitHub
The only change introduced by this data repository is how to read the manifest. In this case, it is usually read in the parent data repository, but the inventory quantity is redefined before returning.
This file contains bidirectional Unicod

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *