Fix notices and rounding issues in orders

This commit is contained in:
Mike Jolley 2013-10-25 20:02:21 +01:00
parent a099f3f37c
commit c7429357c7
6 changed files with 42 additions and 47 deletions

View File

@ -35,8 +35,8 @@ class WC_Meta_Box_Order_Downloads {
if ( $download_permissions && sizeof( $download_permissions ) > 0 ) foreach ( $download_permissions as $download ) {
if ( ! $product || $product->id != $download->product_id ) {
$product = get_product( absint( $download->product_id ) );
$file_count = 0;
$product = get_product( absint( $download->product_id ) );
$file_count = 1;
}
// don't show permissions to files that have since been removed
@ -207,11 +207,13 @@ class WC_Meta_Box_Order_Downloads {
$product_ids_count = sizeof( $product_ids );
for ( $i = 0; $i < $product_ids_count; $i ++ ) {
if ( ! isset( $product_ids[ $i ] ) )
continue;
$data = array(
'user_id' => absint( $customer_user ),
'user_email' => woocommerce_clean( $customer_email ),
'downloads_remaining' => woocommerce_clean( $downloads_remaining[$i] )
'downloads_remaining' => woocommerce_clean( $downloads_remaining[ $i ] )
);
$format = array( '%d', '%s', '%s' );
@ -219,16 +221,16 @@ class WC_Meta_Box_Order_Downloads {
$expiry = ( array_key_exists( $i, $access_expires ) && $access_expires[ $i ] != '' ) ? date_i18n( 'Y-m-d', strtotime( $access_expires[ $i ] ) ) : null;
if ( ! is_null( $expiry ) ) {
$data['access_expires'] = $expiry;
$format[] = '%s';
$data['access_expires'] = $expiry;
$format[] = '%s';
}
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions",
$data,
array(
'order_id' => $post_id,
'product_id' => absint( $product_ids[$i] ),
'download_id' => woocommerce_clean( $download_ids[$i] )
'product_id' => absint( $product_ids[ $i ] ),
'download_id' => woocommerce_clean( $download_ids[ $i ] )
),
$format, array( '%d', '%d', '%s' )
);

View File

@ -143,18 +143,24 @@ class WC_Meta_Box_Order_Items {
$subtotal += woocommerce_clean( $line_subtotal[ $item_id ] );
}
if ( isset( $line_subtotal_tax[ $item_id ] ) )
if ( isset( $line_subtotal_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $line_subtotal_tax[ $item_id ], false ) );
$subtotal += woocommerce_clean( $line_subtotal_tax[ $item_id ] );
}
if ( isset( $line_total[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $line_total[ $item_id ], false ) );
$total += woocommerce_clean( $line_total[ $item_id ] );
}
if ( isset( $line_tax[ $item_id ] ) )
if ( isset( $line_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $line_tax[ $item_id ], false ) );
$total += woocommerce_clean( $line_tax[ $item_id ] );
}
// Clear meta cache
wp_cache_delete( $item_id, 'order_item_meta' );
}

View File

@ -138,7 +138,6 @@ class WC_Order {
*/
public function get_formatted_billing_address() {
if ( ! $this->formatted_billing_address ) {
global $woocommerce;
// Formatted Addresses
$address = apply_filters( 'woocommerce_order_formatted_billing_address', array(
@ -153,7 +152,7 @@ class WC_Order {
'country' => $this->billing_country
), $this );
$this->formatted_billing_address = $woocommerce->countries->get_formatted_address( $address );
$this->formatted_billing_address = WC()->countries->get_formatted_address( $address );
}
return $this->formatted_billing_address;
}
@ -191,7 +190,6 @@ class WC_Order {
public function get_formatted_shipping_address() {
if ( ! $this->formatted_shipping_address ) {
if ( $this->shipping_address_1 ) {
global $woocommerce;
// Formatted Addresses
$address = apply_filters( 'woocommerce_order_formatted_shipping_address', array(
@ -206,7 +204,7 @@ class WC_Order {
'country' => $this->shipping_country
), $this );
$this->formatted_shipping_address = $woocommerce->countries->get_formatted_address( $address );
$this->formatted_shipping_address = WC()->countries->get_formatted_address( $address );
}
}
return $this->formatted_shipping_address;
@ -247,7 +245,7 @@ class WC_Order {
* @return void
*/
public function get_items( $type = '' ) {
global $wpdb, $woocommerce;
global $wpdb;
if ( empty( $type ) )
$type = array( 'line_item' );
@ -291,7 +289,7 @@ class WC_Order {
* @return string
*/
public function get_item_count( $type = '' ) {
global $wpdb, $woocommerce;
global $wpdb;
if ( empty( $type ) )
$type = array( 'line_item' );
@ -652,16 +650,17 @@ class WC_Order {
* @return string
*/
public function get_formatted_line_subtotal( $item, $tax_display = '' ) {
if ( ! $tax_display )
$tax_display = $this->tax_display_cart;
$subtotal = 0;
if (!isset($item['line_subtotal']) || !isset($item['line_subtotal_tax'])) return;
if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) )
return;
if ( $tax_display == 'excl' ) {
if ( $this->prices_include_tax ) $ex_tax_label = 1; else $ex_tax_label = 0;
$ex_tax_label = $this->prices_include_tax ? 1 : 0;
$subtotal = woocommerce_price( $this->get_line_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label ) );
} else {
$subtotal = woocommerce_price( $this->get_line_subtotal( $item, true ) );
@ -693,31 +692,28 @@ class WC_Order {
* @return string
*/
public function get_subtotal_to_display( $compound = false, $tax_display = '' ) {
global $woocommerce;
if ( ! $tax_display )
$tax_display = $this->tax_display_cart;
$subtotal = 0;
if ( ! $compound ) {
foreach ( $this->get_items() as $item ) {
if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) ) return;
if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) )
return;
$subtotal += $this->get_line_subtotal( $item );
$subtotal += $item['line_subtotal'];
if ( $tax_display == 'incl' ) {
$subtotal += $item['line_subtotal_tax'];
}
}
$subtotal = woocommerce_price( $subtotal );
if ( $tax_display == 'excl' && $this->prices_include_tax )
$subtotal .= ' <small>' . $woocommerce->countries->ex_tax_or_vat() . '</small>';
$subtotal .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
} else {
@ -746,7 +742,6 @@ class WC_Order {
$subtotal = $subtotal - $this->get_cart_discount();
$subtotal = woocommerce_price( $subtotal );
}
return apply_filters( 'woocommerce_order_subtotal_to_display', $subtotal, $compound, $this );
@ -760,8 +755,6 @@ class WC_Order {
* @return string
*/
public function get_shipping_to_display( $tax_display = '' ) {
global $woocommerce;
if ( ! $tax_display )
$tax_display = $this->tax_display_cart;
@ -775,7 +768,7 @@ class WC_Order {
$shipping = woocommerce_price( $this->order_shipping );
if ( $this->order_shipping_tax > 0 && $this->prices_include_tax )
$tax_text = $woocommerce->countries->ex_tax_or_vat() . ' ';
$tax_text = WC()->countries->ex_tax_or_vat() . ' ';
} else {
@ -783,7 +776,7 @@ class WC_Order {
$shipping = woocommerce_price( $this->order_shipping + $this->order_shipping_tax );
if ( $this->order_shipping_tax > 0 && ! $this->prices_include_tax )
$tax_text = $woocommerce->countries->inc_tax_or_vat() . ' ';
$tax_text = WC()->countries->inc_tax_or_vat() . ' ';
}
@ -841,8 +834,6 @@ class WC_Order {
* @return array
*/
public function get_order_item_totals( $tax_display = '' ) {
global $woocommerce;
if ( ! $tax_display )
$tax_display = $this->tax_display_cart;
@ -1053,7 +1044,6 @@ class WC_Order {
* @return string
*/
public function get_cancel_order_url() {
global $woocommerce;
return apply_filters('woocommerce_get_cancel_order_url', wp_nonce_url( add_query_arg( array( 'cancel_order' => 'true', 'order' => $this->order_key, 'order_id' => $this->id ), trailingslashit( home_url() ) ), 'woocommerce-cancel_order' ) );
}
@ -1121,6 +1111,7 @@ class WC_Order {
WHERE user_email = %s
AND order_key = %s
AND product_id = %s
ORDER BY permission_id
", $this->billing_email, $this->order_key, $product_id ) );
$files = array();
@ -1260,9 +1251,7 @@ class WC_Order {
* @return void
*/
public function cancel_order( $note = '' ) {
global $woocommerce;
unset( $woocommerce->session->order_awaiting_payment );
unset( WC()->session->order_awaiting_payment );
$this->update_status('cancelled', $note);
@ -1281,12 +1270,11 @@ class WC_Order {
* @return void
*/
public function payment_complete() {
global $woocommerce;
do_action( 'woocommerce_pre_payment_complete', $this->id );
if ( ! empty( $woocommerce->session->order_awaiting_payment ) )
unset( $woocommerce->session->order_awaiting_payment );
if ( ! empty( WC()->session->order_awaiting_payment ) )
unset( WC()->session->order_awaiting_payment );
if ( $this->id && ( $this->status == 'on-hold' || $this->status == 'pending' || $this->status == 'failed' ) ) {
@ -1391,7 +1379,6 @@ class WC_Order {
* @return void
*/
public function increase_coupon_usage_counts() {
global $woocommerce;
if ( get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) == 'yes' )
return;
@ -1422,7 +1409,6 @@ class WC_Order {
* @return void
*/
public function decrease_coupon_usage_counts() {
global $woocommerce;
if ( get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) != 'yes' )
return;

View File

@ -39,7 +39,8 @@ function woocommerce_sanitize_taxonomy_name( $taxonomy ) {
*/
function woocommerce_get_filename_from_url( $file_url ) {
$parts = parse_url( $file_url );
return basename( $parts['path'] );
if ( isset( $parts['path'] ) )
return basename( $parts['path'] );
}
/**

View File

@ -63,10 +63,10 @@ $order = new WC_Order( $order_id );
foreach ( $download_files as $download_id => $file ) {
$i++;
$links[] = '<small><a href="' . esc_url( $file['download_url'] ) . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</a></small>';
$links[] = '<small><a href="' . esc_url( $file['download_url'] ) . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_files ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</a></small>';
}
echo implode( '<br/>', $links );
echo '<br/>' . implode( '<br/>', $links );
}
?>
</td>

View File

@ -773,10 +773,10 @@ function woocommerce_revoke_access_to_download() {
global $wpdb;
$download_id = $_POST['download_id'];
$product_id = intval( $_POST['product_id'] );
$order_id = intval( $_POST['order_id'] );
$product_id = intval( $_POST['product_id'] );
$order_id = intval( $_POST['order_id'] );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %d;", $order_id, $product_id, $download_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s;", $order_id, $product_id, $download_id ) );
do_action( 'woocommerce_ajax_revoke_access_to_product_download', $download_id, $product_id, $order_id );