Consistant method names Closes #3901, return doubles instead of number formatted strings.

This commit is contained in:
Mike Jolley 2013-10-17 12:43:44 +01:00
parent 2cd74e1acf
commit a112cb1d7d
5 changed files with 159 additions and 140 deletions

View File

@ -417,20 +417,8 @@ class WC_Order {
return get_metadata( 'order_item', $order_item_id, $key, $single ); return get_metadata( 'order_item', $order_item_id, $key, $single );
} }
/** Total Getters *******************************************************/ /** Total Getters *******************************************************/
/**
* Gets shipping and product tax.
*
* @access public
* @return float
*/
public function get_total_tax() {
return apply_filters( 'woocommerce_order_amount_total_tax', number_format( (double) $this->order_tax + (double) $this->order_shipping_tax, 2, '.', '' ), $this );
}
/** /**
* Gets the total (product) discount amount - these are applied before tax. * Gets the total (product) discount amount - these are applied before tax.
* *
@ -438,10 +426,9 @@ class WC_Order {
* @return float * @return float
*/ */
public function get_cart_discount() { public function get_cart_discount() {
return apply_filters( 'woocommerce_order_amount_cart_discount', number_format( (double) $this->cart_discount, 2, '.', '' ), $this ); return apply_filters( 'woocommerce_order_amount_cart_discount', (double) $this->cart_discount, $this );
} }
/** /**
* Gets the total (product) discount amount - these are applied before tax. * Gets the total (product) discount amount - these are applied before tax.
* *
@ -449,10 +436,9 @@ class WC_Order {
* @return float * @return float
*/ */
public function get_order_discount() { public function get_order_discount() {
return apply_filters( 'woocommerce_order_amount_order_discount', number_format( (double) $this->order_discount, 2, '.', '' ), $this ); return apply_filters( 'woocommerce_order_amount_order_discount', (double) $this->order_discount, $this );
} }
/** /**
* Gets the total discount amount - both kinds * Gets the total discount amount - both kinds
* *
@ -460,22 +446,19 @@ class WC_Order {
* @return float * @return float
*/ */
public function get_total_discount() { public function get_total_discount() {
if ( $this->order_discount || $this->cart_discount ) return apply_filters( 'woocommerce_order_amount_total_discount', $this->get_cart_discount() + $this->get_order_discount(), $this );
return apply_filters( 'woocommerce_order_amount_total_discount', number_format( (double) $this->order_discount + (double) $this->cart_discount, 2, '.', '' ), $this );
} }
/** /**
* Gets shipping total. * Gets shipping tax amount.
* *
* @access public * @access public
* @return float * @return float
*/ */
public function get_shipping() { public function get_cart_tax() {
return apply_filters( 'woocommerce_order_amount_shipping', number_format( (double) $this->order_shipping, 2, '.', '' ), $this ); return apply_filters( 'woocommerce_order_amount_cart_tax', (double) $this->order_tax, $this );
} }
/** /**
* Gets shipping tax amount. * Gets shipping tax amount.
* *
@ -483,9 +466,28 @@ class WC_Order {
* @return float * @return float
*/ */
public function get_shipping_tax() { public function get_shipping_tax() {
return apply_filters( 'woocommerce_order_amount_shipping_tax', number_format( (double) $this->order_shipping_tax, 2, '.', '' ), $this ); return apply_filters( 'woocommerce_order_amount_shipping_tax', (double) $this->order_shipping_tax, $this );
} }
/**
* Gets shipping and product tax.
*
* @access public
* @return float
*/
public function get_total_tax() {
return apply_filters( 'woocommerce_order_amount_total_tax', $this->get_cart_tax() + $this->get_shipping_tax(), $this );
}
/**
* Gets shipping total.
*
* @access public
* @return float
*/
public function get_total_shipping() {
return apply_filters( 'woocommerce_order_amount_total_shipping', (double) $this->order_shipping, $this );
}
/** /**
* Gets order total. * Gets order total.
@ -494,20 +496,133 @@ class WC_Order {
* @return float * @return float
*/ */
public function get_total() { public function get_total() {
return apply_filters( 'woocommerce_order_amount_total', number_format( (double) $this->order_total, 2, '.', '' ), $this ); return apply_filters( 'woocommerce_order_amount_total', (double) $this->order_total, $this );
} }
/**
* Get item subtotal - this is the cost before discount.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_item_subtotal( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = ( $item['line_subtotal'] + $item['line_subtotal_tax'] / $item['qty'] );
else
$price = ( $item['line_subtotal'] / $item['qty'] );
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
return apply_filters( 'woocommerce_order_amount_item_subtotal', $price, $this );
}
/**
* Get line subtotal - this is the cost before discount.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_line_subtotal( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = $item['line_subtotal'] + $item['line_subtotal_tax'];
else
$price = $item['line_subtotal'];
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
return apply_filters( 'woocommerce_order_amount_line_subtotal', $price, $this );
}
/**
* Calculate item cost - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_item_total( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = ( ( $item['line_total'] + $item['line_tax'] ) / $item['qty'] );
else
$price = $item['line_total'] / $item['qty'];
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
return apply_filters( 'woocommerce_order_amount_item_total', $price, $this );
}
/**
* Calculate line total - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @return float
*/
public function get_line_total( $item, $inc_tax = false ) {
$line_total = $inc_tax ? number_format( $item['line_total'] + $item['line_tax'] , 2, '.', '' ) : number_format( $item['line_total'] , 2, '.', '' );
return apply_filters( 'woocommerce_order_amount_line_total', $line_total, $this );
}
/**
* Calculate item tax - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $round (default: true)
* @return float
*/
public function get_item_tax( $item, $round = true ) {
$price = $item['line_tax'] / $item['qty'];
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
return apply_filters( 'woocommerce_order_amount_item_tax', $price, $this );
}
/**
* Calculate line tax - useful for gateways.
*
* @access public
* @param mixed $item
* @return float
*/
public function get_line_tax( $item ) {
return apply_filters( 'woocommerce_order_amount_line_tax', number_format( $item['line_tax'], 2, '.', ''), $this );
}
/**
* Gets shipping total.
*
* @deprecated As of 2.1, use of get_total_shipping() is preferred
* @access public
* @return float
*/
public function get_shipping() {
_deprecated_function( 'get_shipping', '2.1', 'get_total_shipping' );
return $this->get_total_shipping();
}
/** /**
* get_order_total function. Alias for get_total() * get_order_total function. Alias for get_total()
* *
* @deprecated As of 2.1, use of get_total() is preferred
* @access public * @access public
* @return void * @return void
*/ */
public function get_order_total() { public function get_order_total() {
_deprecated_function( 'get_order_total', '2.1', 'get_total' );
return $this->get_total(); return $this->get_total();
} }
/** End Total Getters *******************************************************/
/** /**
* Gets formatted shipping method title. * Gets formatted shipping method title.
* *
@ -529,103 +644,6 @@ class WC_Order {
return apply_filters( 'woocommerce_order_shipping_method', implode( ', ', $labels ), $this ); return apply_filters( 'woocommerce_order_shipping_method', implode( ', ', $labels ), $this );
} }
/**
* Get item subtotal - this is the cost before discount.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_item_subtotal( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = ( $item['line_subtotal'] + $item['line_subtotal_tax'] / $item['qty'] );
else
$price = ( $item['line_subtotal'] / $item['qty'] );
return apply_filters( 'woocommerce_order_amount_item_subtotal', (($round) ? number_format( $price, 2, '.', '') : $price ), $this );
}
/**
* Get line subtotal - this is the cost before discount.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_line_subtotal( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = $item['line_subtotal'] + $item['line_subtotal_tax'];
else
$price = $item['line_subtotal'];
return apply_filters( 'woocommerce_order_amount_line_subtotal', ( ($round) ? number_format( $price, 2, '.', '') : $price ), $this );
}
/**
* Calculate item cost - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @param bool $round (default: true)
* @return float
*/
public function get_item_total( $item, $inc_tax = false, $round = true ) {
if ( $inc_tax )
$price = ( ( $item['line_total'] + $item['line_tax'] ) / $item['qty'] );
else
$price = $item['line_total'] / $item['qty'];
return apply_filters( 'woocommerce_order_amount_item_total', ( ($round) ? number_format( $price, 2, '.', '') : $price ), $this );
}
/**
* Calculate item tax - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $round (default: true)
* @return float
*/
public function get_item_tax( $item, $round = true ) {
$price = $item['line_tax'] / $item['qty'];
return apply_filters( 'woocommerce_order_amount_item_tax', ( ($round) ? number_format( $price, 2, '.', '') : $price ), $this );
}
/**
* Calculate line total - useful for gateways.
*
* @access public
* @param mixed $item
* @param bool $inc_tax (default: false)
* @return float
*/
public function get_line_total( $item, $inc_tax = false ) {
if ( $inc_tax )
return apply_filters( 'woocommerce_order_amount_line_total', number_format( $item['line_total'] + $item['line_tax'] , 2, '.', ''), $this );
else
return apply_filters( 'woocommerce_order_amount_line_total', number_format( $item['line_total'] , 2, '.', ''), $this );
}
/**
* Calculate line tax - useful for gateways.
*
* @access public
* @param mixed $item
* @return float
*/
public function get_line_tax( $item ) {
return apply_filters( 'woocommerce_order_amount_line_tax', number_format( $item['line_tax'], 2, '.', ''), $this );
}
/** End Total Getters *******************************************************/
/** /**
* Gets line subtotal - formatted for display. * Gets line subtotal - formatted for display.
* *
@ -713,7 +731,7 @@ class WC_Order {
} }
// Add Shipping Costs // Add Shipping Costs
$subtotal += $this->get_shipping(); $subtotal += $this->get_total_shipping();
// Remove non-compound taxes // Remove non-compound taxes
foreach ( $this->get_taxes() as $tax ) { foreach ( $this->get_taxes() as $tax ) {

View File

@ -262,14 +262,14 @@ class WC_Gateway_Mijireh extends WC_Payment_Gateway {
$mj_order->email = $wc_order->billing_email; $mj_order->email = $wc_order->billing_email;
// set order totals // set order totals
$mj_order->total = $wc_order->get_order_total(); $mj_order->total = $wc_order->get_total();
$mj_order->discount = $wc_order->get_total_discount(); $mj_order->discount = $wc_order->get_total_discount();
if ( get_option( 'woocommerce_prices_include_tax' ) == 'yes' ) { if ( get_option( 'woocommerce_prices_include_tax' ) == 'yes' ) {
$mj_order->shipping = $wc_order->get_shipping() + $wc_order->get_shipping_tax(); $mj_order->shipping = $wc_order->get_total_shipping() + $wc_order->get_shipping_tax();
$mj_order->show_tax = false; $mj_order->show_tax = false;
} else { } else {
$mj_order->shipping = $wc_order->get_shipping(); $mj_order->shipping = $wc_order->get_total_shipping();
$mj_order->tax = $wc_order->get_total_tax(); $mj_order->tax = $wc_order->get_total_tax();
} }

View File

@ -341,17 +341,17 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$paypal_args['item_name_1'] = sprintf( __( 'Order %s' , 'woocommerce'), $order->get_order_number() ) . " - " . implode( ', ', $item_names ); $paypal_args['item_name_1'] = sprintf( __( 'Order %s' , 'woocommerce'), $order->get_order_number() ) . " - " . implode( ', ', $item_names );
$paypal_args['quantity_1'] = 1; $paypal_args['quantity_1'] = 1;
$paypal_args['amount_1'] = number_format( $order->get_total() - $order->get_shipping() - $order->get_shipping_tax() + $order->get_order_discount(), 2, '.', '' ); $paypal_args['amount_1'] = number_format( $order->get_total() - $order->get_total_shipping() - $order->get_shipping_tax() + $order->get_order_discount(), 2, '.', '' );
// Shipping Cost // Shipping Cost
// No longer using shipping_1 because // No longer using shipping_1 because
// a) paypal ignore it if *any* shipping rules are within paypal // a) paypal ignore it if *any* shipping rules are within paypal
// b) paypal ignore anything over 5 digits, so 999.99 is the max // b) paypal ignore anything over 5 digits, so 999.99 is the max
// $paypal_args['shipping_1'] = number_format( $order->get_shipping() + $order->get_shipping_tax() , 2, '.', '' ); // $paypal_args['shipping_1'] = number_format( $order->get_total_shipping() + $order->get_shipping_tax() , 2, '.', '' );
if ( ( $order->get_shipping() + $order->get_shipping_tax() ) > 0 ) { if ( ( $order->get_total_shipping() + $order->get_shipping_tax() ) > 0 ) {
$paypal_args['item_name_2'] = __( 'Shipping via', 'woocommerce' ) . ' ' . ucwords( $order->get_shipping_method() ); $paypal_args['item_name_2'] = __( 'Shipping via', 'woocommerce' ) . ' ' . ucwords( $order->get_shipping_method() );
$paypal_args['quantity_2'] = '1'; $paypal_args['quantity_2'] = '1';
$paypal_args['amount_2'] = number_format( $order->get_shipping() + $order->get_shipping_tax() , 2, '.', '' ); $paypal_args['amount_2'] = number_format( $order->get_total_shipping() + $order->get_shipping_tax() , 2, '.', '' );
} }
} else { } else {
@ -401,11 +401,11 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
} }
// Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
if ( $order->get_shipping() > 0 ) { if ( $order->get_total_shipping() > 0 ) {
$item_loop++; $item_loop++;
$paypal_args[ 'item_name_' . $item_loop ] = __( 'Shipping via', 'woocommerce' ) . ' ' . ucwords( $order->shipping_method_title ); $paypal_args[ 'item_name_' . $item_loop ] = __( 'Shipping via', 'woocommerce' ) . ' ' . ucwords( $order->shipping_method_title );
$paypal_args[ 'quantity_' . $item_loop ] = '1'; $paypal_args[ 'quantity_' . $item_loop ] = '1';
$paypal_args[ 'amount_' . $item_loop ] = number_format( $order->get_shipping(), 2, '.', '' ); $paypal_args[ 'amount_' . $item_loop ] = number_format( $order->get_total_shipping(), 2, '.', '' );
} }
} }

View File

@ -201,7 +201,7 @@ class WC_Google_Analytics extends WC_Integration {
'" . esc_js( get_bloginfo( 'name' ) ) . "', // affiliation or store name '" . esc_js( get_bloginfo( 'name' ) ) . "', // affiliation or store name
'" . esc_js( $order->get_total() ) . "', // total - required '" . esc_js( $order->get_total() ) . "', // total - required
'" . esc_js( $order->get_total_tax() ) . "', // tax '" . esc_js( $order->get_total_tax() ) . "', // tax
'" . esc_js( $order->get_shipping() ) . "', // shipping '" . esc_js( $order->get_total_shipping() ) . "', // shipping
'" . esc_js( $order->billing_city ) . "', // city '" . esc_js( $order->billing_city ) . "', // city
'" . esc_js( $order->billing_state ) . "', // state or province '" . esc_js( $order->billing_state ) . "', // state or province
'" . esc_js( $order->billing_country ) . "' // country '" . esc_js( $order->billing_country ) . "' // country

View File

@ -74,13 +74,14 @@ add_action( 'init', 'woocommerce_legacy_paypal_ipn' );
global $wc_map_deprecated_filters; global $wc_map_deprecated_filters;
$wc_map_deprecated_filters = array( $wc_map_deprecated_filters = array(
'woocommerce_cart_item_class' => 'woocommerce_cart_table_item_class', 'woocommerce_cart_item_class' => 'woocommerce_cart_table_item_class',
'woocommerce_cart_item_product_id' => 'hook_woocommerce_in_cart_product_id', 'woocommerce_cart_item_product_id' => 'hook_woocommerce_in_cart_product_id',
'woocommerce_cart_item_thumbnail' => 'hook_woocommerce_in_cart_product_thumbnail', 'woocommerce_cart_item_thumbnail' => 'hook_woocommerce_in_cart_product_thumbnail',
'woocommerce_cart_item_price' => 'woocommerce_cart_item_price_html', 'woocommerce_cart_item_price' => 'woocommerce_cart_item_price_html',
'woocommerce_cart_item_name' => 'woocommerce_in_cart_product_title', 'woocommerce_cart_item_name' => 'woocommerce_in_cart_product_title',
'woocommerce_order_item_class' => 'woocommerce_order_table_item_class', 'woocommerce_order_item_class' => 'woocommerce_order_table_item_class',
'woocommerce_order_item_name' => 'woocommerce_order_table_product_title' 'woocommerce_order_item_name' => 'woocommerce_order_table_product_title',
'woocommerce_order_amount_shipping' => 'woocommerce_order_amount_total_shipping'
); );
foreach ( $wc_map_deprecated_filters as $new => $old ) foreach ( $wc_map_deprecated_filters as $new => $old )