-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to support HPOS #71
base: master
Are you sure you want to change the base?
Changes from 5 commits
3c55c64
a6970c2
6c381aa
5204b5c
8ae2067
da3bf91
0b9d8dd
9f6480e
d350fd4
5a90eb9
2c25fe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} // Exit if accessed directly | ||
|
||
use Automattic\WooCommerce\Utilities\OrderUtil; | ||
|
||
interface OrderStorageTechnologyFactory { | ||
eric-thelin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function get_meta($order, $meta_key, $meta_value); | ||
eric-thelin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function add_meta_data($order, $meta_key, $meta_value); | ||
public function update_meta_data($order, $meta_key, $meta_value); | ||
public function delete_meta_data($order, $meta_key); | ||
public function save($order); | ||
} | ||
|
||
class HPOSOrderStorage implements OrderStorageTechnologyFactory { | ||
public function get_meta($order, $meta_key, $meta_value) { | ||
return $order->get_meta($meta_key, $meta_value); | ||
} | ||
|
||
public function add_meta_data($order, $meta_key, $meta_value) { | ||
$order->add_meta_data($meta_key, $meta_value); | ||
} | ||
|
||
public function update_meta_data($order, $meta_key, $meta_value) { | ||
$order->update_meta_data($meta_key, $meta_value); | ||
} | ||
|
||
public function delete_meta_data($order, $meta_key) { | ||
$order->delete_meta_data($meta_key); | ||
} | ||
|
||
public function save($order) { | ||
$order->save(); | ||
} | ||
} | ||
|
||
class CPTOrderStorage implements OrderStorageTechnologyFactory { | ||
public function get_meta($order, $meta_key, $meta_value) { | ||
return get_post_meta($order->get_id(), $meta_key, $meta_value); | ||
} | ||
|
||
public function add_meta_data($order, $meta_key, $meta_value) { | ||
add_post_meta($order->get_id(), $meta_key, $meta_value); | ||
} | ||
|
||
public function update_meta_data($order, $meta_key, $meta_value) { | ||
update_post_meta($order->get_id(), $meta_key, $meta_value); | ||
} | ||
|
||
public function delete_meta_data($order, $meta_key) { | ||
delete_post_meta($order->get_id(), $meta_key); | ||
} | ||
|
||
public function save($order) { | ||
return; // Do nothing, CPT doesn't use save | ||
} | ||
} | ||
|
||
class OrderStorageTechnology { | ||
public static function current() { | ||
eric-thelin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (OrderUtil::custom_orders_table_usage_is_enabled()) { | ||
return new HPOSOrderStorage(); | ||
} else { | ||
return new CPTOrderStorage(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ public function __construct() { | |
register_deactivation_hook( __FILE__, array( $this, 'flush_rewrite_rules' ) ); | ||
|
||
// Actions | ||
add_action( 'before_woocommerce_init', function() { | ||
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this call should move to either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like it fits here since it's something that should be added before woocommerce init. Which is also for a one-off compatibility file, so i feel like it fits here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea was just to move the mention of the custom orders table to either
However, if you prefer the current solution I am fine with that. |
||
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); | ||
} | ||
} ); | ||
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( | ||
$this, | ||
'plugin_action_links' | ||
|
@@ -124,6 +129,7 @@ public function woocommerce_loaded() { | |
include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-mondido-card.php' ); | ||
include_once( dirname( __FILE__ ) . '/includes/class-wc-mondido-api.php' ); | ||
include_once( dirname( __FILE__ ) . '/includes/class-wc-mondido-transaction.php' ); | ||
include_once( dirname( __FILE__ ) . '/includes/class-wc-mondido-hpos-compatibility.php' ); | ||
|
||
include_once( dirname( __FILE__ ) . '/includes/class-wc-mondido-admin-actions.php' ); | ||
include_once( dirname( __FILE__ ) . '/includes/class-wc-mondido-subscriptions.php' ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pair of lines with delete + update is repeating itself in multiple places. In order to reduce duplication we could introduce a
replace_meta_data
method on the order storage.