Use prop getters/setters instead

This commit is contained in:
Boro Sitnikovski 2017-09-05 15:17:16 +02:00
parent ff9316b093
commit 85e3cee634
3 changed files with 10 additions and 24 deletions

View File

@ -741,30 +741,10 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/**
* Sets shipping method title.
*
* @param string|array $shipping_methods
* @param array $shipping_method
*/
public function set_shipping_method( $shipping_methods ) {
/*
$valid_shipping_methods = array();
if ( ! is_array( $shipping_methods ) ) {
$shipping_methods = array( $shipping_methods );
}
foreach ( $this->get_shipping_methods() as $shipping_method ) {
if ( in_array( $shipping_method->get_name(), $shipping_methods ) ) {
$valid_shipping_methods[] = $shipping_method->get_method_id();
}
}
$this->set_prop( 'shipping_method', $valid_shipping_methods );
*/
// For the time being, we cannot use `set_prop` since it would call `get_shipping_method`
// to get the changes, but `get_shipping_method` will return a formatted method title instead
// of the method id, which is the format stored in the DB. In order to not break BC, use this hack.
// TODO: Rely only on props instead of updating post meta.
update_post_meta( $this->get_id(), '_shipping_method', $valid_shipping_methods );
public function set_shipping_method( $shipping_method ) {
$this->set_prop( 'shipping_method', $shipping_method );
}
/**
@ -772,7 +752,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
*
* @return string
*/
public function get_shipping_method() {
public function get_shipping_method( $context = 'view' ) {
if ( 'edit' === $context ) {
return $this->get_prop( 'shipping_method' );
}
$names = array();
foreach ( $this->get_shipping_methods() as $shipping_method ) {
$names[] = $shipping_method->get_name();

View File

@ -39,6 +39,7 @@ class WC_Order extends WC_Abstract_Order {
'date_modified' => null,
'discount_total' => 0,
'discount_tax' => 0,
'shipping_method' => '',
'shipping_total' => 0,
'shipping_tax' => 0,
'cart_tax' => 0,

View File

@ -173,6 +173,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
'_date_completed' => 'date_completed',
'_date_paid' => 'date_paid',
'_cart_hash' => 'cart_hash',
'_shipping_method' => 'shipping_method',
);
$props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );