Product Sync module
Learn more about the Product Sync module.
This module syncs the product information to Digital River when any product is created, updated, or deleted. Products can be manually synced from the Admin dashboard via Tools -> Available Tools
Specifications
This module will leverage SKU API provided by Digital River.
Whenever a product in WooCommerce is created, updated, or deleted, this module will call the Digital River SKU API and update the SKU information.
SKU API will also need the ECCN, HS Code, Country of origin, and Tax code. These fields will be added and provided by ProductMetaFields
module.
The ProductSync
module does not manage the addition and validation of required meta fields. That process is managed in the ProductMetaFields
module.
Modify the SKU Request object
To modify the SKURequest
object before sync:
Grab the
SKURequest
object from the filter:add_filter( 'digitalriver.pre_sync_sku_request', 'filter_method' )
The
SKURequest
object will be passed as the first argument tofilter_method()
.Make any changes to the object and then return the object.
Replace the Sync Handler with a custom class
To replace the SyncHandler
with a custom class:
Grab the
SyncHandler
object from the filter:add_filter( 'digitalriver.sync_handler', 'filter_method' )
The
SKURequest
object will be passed as the first argument tofilter_method()
.Swap out the object if necessary and then return the object.
Product Sync Methods
Product Sync class
This class describes the module's entry point.
Method
Args, Returns, and Descriptions
name
Arg: -
Return: string
Description: Returns the name of the module
init
Arg: -
Return: void
Description: Initializes the module and register necessary hooks
assets
Arg: String $page_hook
Return: void
Description: Enqueues the scripts and stylesheets in the tools.php
sync
Arg: int $post_id
Return: bool
Description: Syncs the product to Digital River and return the status of the sync
delete
Arg: int $post_id
Return: void
Description: Deletes the product from Digital River using ProductSyncHandler
get
Arg: int $post_id
Return: SKU
Description: Fetches the product from digitalriver
using ProductSyncHandler
sync_status
Arg: -
Return: void
Description: Gets the sync status of the product. Product ID should always be the parent product ID.
sync_variations
Arg: WC_Product
$product
Return: void
Description: Syncs all variations for variable product
sync_tool_box
Arg: -
Return: void
Description: Displays the manual product sync toolbox
sync_handler
Arg: -
Return: ProductSyncHandler
Description: Returns an instance of the ProductSyncHandler
from the SyncContainer
Sync Container class
This class defines all the services required for this module.
Method
Args, Returns, and Descriptions
__construct
Arg: PimpleContainer
Return: void
Description: Accepts a Dependency Injection container as an argument and assigns it to a container attribute
define_services
Arg: -
Return: void
Description: Defines all the classes present within the module
Sync Meta Box class
This class adds the metabox to the Product Edit screen and contains a button to trigger the product sync action.
Method
Args, Returns, and Descriptions
init
Arg: -
Return: void
Description: Initializes the object and registers the necessary hooks for displaying the metabox
assets
Arg: String $page_hook
Return: void
Description: Enqueues the scripts and stylesheets in the tools.php
add
Arg: -
Return: void
Description: Adds the metabox to the product edit page and triggers the render callback
callback
Arg: -
Return: void
Description: Displays the metabox contents with the render callback
Sync Handler class
This class handles the actual sync process between WooCommerce and Digital River.
Method
Args, Returns, and Descriptions
init
Arg: ApiInstance
$api_instance, SkuRequest
$sku_request, MetaFields
$meta_handler
Return: void
Description: Constructs the object by passing its dependencies
upsert
Arg: -
Return: bool
Description: Uses the ApiInstance
to insert or update the $product
to Digital River. Returns the status of the sync operation.
delete
Arg: -
Return: void
Description: Uses the ApiInstance
to delete the $product
from Digital River
get
Arg: -
Return: SKU
Description: Uses the ApiInstance
to get the SKU from Digital River
product
Arg: WC_Product
$product
Return: ProductSyncHandler
Description: Sets the product to sync and returns the SyncHandler object and is useful for chaining methods
sku_request
Arg: -
Return: SKURequest/null
Description: Prepares the SKURequest
model and sets necessary fields (ECCN, Tax code, Country of origin, HS Code) from the $product
meta fields and returns the request. Returns null
if data is invalid
Endpoint/Sync class
This class exposes the /digitalriver/v1/sync
endpoint and syncs products to Digital River when a request is sent to that endpoint.
Method
Args, Returns, and Descriptions
__construct
Arg: ProductSync
$sync_objCursor
$cursor
Return: void
Description: Constructs the object by passing its dependencies
init
Arg: -
Return: void
Description: Makes a call to the register()
method on rest_api_init
register
Arg: -
Return: void
Description: Registers the /digitalriver/v1/sync
endpoint and defines the callback
sync_products
Arg: WP_REST_Request
Return: WP_REST_Response
Description: Initiates the product sync with the REST route callback
Last updated