-
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
Open
maxfrederiksen-mondido
wants to merge
11
commits into
master
Choose a base branch
from
MDO-970-upgrade-support-hpos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c55c64
followed guide to refactor up until declaring extension compatibility
maxfrederiksen-mondido a6970c2
refactoring
maxfrederiksen-mondido 6c381aa
remove unused var
maxfrederiksen-mondido 5204b5c
remvove whitespace
maxfrederiksen-mondido 8ae2067
declare compatibility + refactor
maxfrederiksen-mondido da3bf91
Comments, fixes and refactorings
maxfrederiksen-mondido 0b9d8dd
refactor hpos class structure
maxfrederiksen-mondido 9f6480e
github sync bug + indentation
maxfrederiksen-mondido d350fd4
fix whitespace
maxfrederiksen-mondido 5a90eb9
indent bracket
maxfrederiksen-mondido 2c25fe7
add version check for using new hpos file
maxfrederiksen-mondido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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(); | ||
} | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.