Refactor so that trait don't have class specific functions.
This commit is contained in:
parent
60cd7b3651
commit
1de30e8963
|
@ -780,7 +780,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
protected function get_values_for_total( $field ) {
|
||||
$items = array_map(
|
||||
function ( $item ) use ( $field ) {
|
||||
return wc_add_number_precision( $item[ $field ] );
|
||||
return wc_add_number_precision( $item[ $field ], false );
|
||||
},
|
||||
array_values( $this->get_items() )
|
||||
);
|
||||
|
@ -1531,8 +1531,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$cart_subtotal_tax = 0;
|
||||
$cart_total_tax = 0;
|
||||
|
||||
$cart_subtotal = wc_remove_number_precision( $this->get_rounded_items_total( 'subtotal' ) );
|
||||
$cart_total = wc_remove_number_precision( $this->get_rounded_items_total() );
|
||||
$cart_subtotal = wc_remove_number_precision(
|
||||
$this->get_rounded_items_total(
|
||||
$this->get_values_for_total( 'subtotal' )
|
||||
)
|
||||
);
|
||||
|
||||
$cart_total = wc_remove_number_precision(
|
||||
$this->get_rounded_items_total(
|
||||
$this->get_values_for_total( 'total' )
|
||||
)
|
||||
);
|
||||
|
||||
// Sum shipping costs.
|
||||
foreach ( $this->get_shipping_methods() as $shipping ) {
|
||||
|
|
|
@ -684,7 +684,7 @@ final class WC_Cart_Totals {
|
|||
$this->cart->cart_contents[ $item_key ]['line_tax'] = wc_remove_number_precision( $item->total_tax );
|
||||
}
|
||||
|
||||
$items_total = $this->get_rounded_items_total();
|
||||
$items_total = $this->get_rounded_items_total( $this->get_values_for_total( 'total' ) );
|
||||
|
||||
$this->set_total( 'items_total', round( $items_total ) );
|
||||
$this->set_total( 'items_total_tax', array_sum( array_values( wp_list_pluck( $this->items, 'total_tax' ) ) ) );
|
||||
|
@ -747,7 +747,7 @@ final class WC_Cart_Totals {
|
|||
$this->cart->cart_contents[ $item_key ]['line_subtotal_tax'] = wc_remove_number_precision( $item->subtotal_tax );
|
||||
}
|
||||
|
||||
$items_subtotal = $this->get_rounded_items_total( 'subtotal' );
|
||||
$items_subtotal = $this->get_rounded_items_total( $this->get_values_for_total( 'subtotal' ) );
|
||||
|
||||
$this->set_total( 'items_subtotal', round( $items_subtotal ) );
|
||||
$this->set_total( 'items_subtotal_tax', wc_round_tax_total( array_sum( $merged_subtotal_taxes ), 0 ) );
|
||||
|
|
|
@ -34,15 +34,15 @@ trait WC_Item_Totals {
|
|||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $field Field to round and sum based on setting. Will likely be `total` or `subtotal`. Values must be without precision.
|
||||
* @param array $values Values to round. Should be with precision.
|
||||
*
|
||||
* @return float|int Appropriately rounded value.
|
||||
*/
|
||||
protected function get_rounded_items_total( $field = 'total' ) {
|
||||
public static function get_rounded_items_total( $values ) {
|
||||
return array_sum(
|
||||
array_map(
|
||||
array( $this, 'round_item_subtotal' ),
|
||||
$this->get_values_for_total( $field )
|
||||
array( self::class, 'round_item_subtotal' ),
|
||||
$values
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ trait WC_Item_Totals {
|
|||
* @param float $value Item subtotal value.
|
||||
* @return float
|
||||
*/
|
||||
protected function round_item_subtotal( $value ) {
|
||||
if ( ! $this->round_at_subtotal() ) {
|
||||
public static function round_item_subtotal( $value ) {
|
||||
if ( ! self::round_at_subtotal() ) {
|
||||
$value = round( $value );
|
||||
}
|
||||
return $value;
|
||||
|
@ -67,7 +67,8 @@ trait WC_Item_Totals {
|
|||
* @since 3.9.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function round_at_subtotal() {
|
||||
protected static function round_at_subtotal() {
|
||||
return 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue