Display + storage

This commit is contained in:
Mike Jolley 2012-11-12 17:15:54 +00:00
parent f4a931f7cc
commit 98ddb3bbc5
10 changed files with 129 additions and 66 deletions

View File

@ -13,21 +13,23 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td class="tax_class" width="1%">
<select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>">
<?php
$item_value = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : '';
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) );
$classes_options = array();
$classes_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = $class;
foreach ( $classes_options as $value => $name )
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $item_value, false ) . '>'. esc_html( $name ) . '</option>';
?>
<?php $tax_class = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : ''; ?>
<option value="0" <?php selected( 0, $tax_class ) ?>><?php _e( 'N/A', 'woocommerce' ); ?></option>
<optgroup label="<?php _e( 'Taxable', 'woocommerce' ); ?>">
<?php
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) );
$classes_options = array();
$classes_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = $class;
foreach ( $classes_options as $value => $name )
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $tax_class, false ) . '>'. esc_html( $name ) . '</option>';
?>
</optgroup>
</select>
</td>

View File

@ -469,7 +469,7 @@ function woocommerce_order_totals_meta_box($post) {
<ul class="totals">
<li class="left">
<label><?php _e( 'Cart Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts before tax', 'woocommerce' ); ?>." href="#">[?]</a></label>
<label><?php _e( 'Cart Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts before tax - calculated by comparing subtotals to totals.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" id="_cart_discount" name="_cart_discount" placeholder="0.00" value="<?php
if ( isset( $data['_cart_discount'][0] ) )
echo esc_attr( $data['_cart_discount'][0] );
@ -477,7 +477,7 @@ function woocommerce_order_totals_meta_box($post) {
</li>
<li class="right">
<label><?php _e( 'Order Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts after tax', 'woocommerce' ); ?>." href="#">[?]</a></label>
<label><?php _e( 'Order Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts after tax - user defined.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" id="_order_discount" name="_order_discount" placeholder="0.00" value="<?php
if ( isset( $data['_order_discount'][0] ) )
echo esc_attr( $data['_order_discount'][0] );
@ -490,9 +490,17 @@ function woocommerce_order_totals_meta_box($post) {
<div class="totals_group">
<h4><?php _e( 'Shipping', 'woocommerce' ); ?></h4>
<ul class="totals">
<li class="wide">
<label><?php _e( 'Label:', 'woocommerce' ); ?></label>
<input type="text" id="_shipping_method_title" name="_shipping_method_title" placeholder="<?php _e( 'The shipping title the customer sees', 'woocommerce' ); ?>" value="<?php
if ( isset( $data['_shipping_method_title'][0] ) )
echo esc_attr( $data['_shipping_method_title'][0] );
?>" class="first" />
</li>
<li class="left">
<label><?php _e( 'Shipping Cost:', 'woocommerce' ); ?></label>
<label><?php _e( 'Cost:', 'woocommerce' ); ?></label>
<input type="text" id="_order_shipping" name="_order_shipping" placeholder="0.00 <?php _e( '(ex. tax)', 'woocommerce' ); ?>" value="<?php
if ( isset( $data['_order_shipping'][0] ) )
echo esc_attr( $data['_order_shipping'][0] );
@ -500,7 +508,7 @@ function woocommerce_order_totals_meta_box($post) {
</li>
<li class="right">
<label><?php _e( 'Shipping Method:', 'woocommerce' ); ?></label>
<label><?php _e( 'Method:', 'woocommerce' ); ?></label>
<select name="_shipping_method" id="_shipping_method" class="first">
<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option>
<?php
@ -524,14 +532,6 @@ function woocommerce_order_totals_meta_box($post) {
</select>
</li>
<li class="wide">
<label><?php _e( 'Shipping Title:', 'woocommerce' ); ?></label>
<input type="text" id="_shipping_method_title" name="_shipping_method_title" placeholder="<?php _e( 'The shipping title the customer sees', 'woocommerce' ); ?>" value="<?php
if ( isset( $data['_shipping_method_title'][0] ) )
echo esc_attr( $data['_shipping_method_title'][0] );
?>" class="first" />
</li>
</ul>
<?php do_action( 'woocommerce_admin_order_totals_after_shipping', $post->ID ) ?>
<div class="clear"></div>

View File

@ -1395,7 +1395,10 @@ class WC_Cart {
// Get tax rates
$tax_rates = $this->tax->get_rates();
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
// Store
$fee->tax = array_sum( $fee_taxes );
// Tax rows - merge the totals we just got
foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) {
$this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
@ -1758,6 +1761,7 @@ class WC_Cart {
$new_fee->amount = (float) esc_attr( $amount );
$new_fee->tax_class = $tax_class;
$new_fee->taxable = $taxable ? true : false;
$new_fee->tax = 0;
$this->fees[] = $new_fee;
}

View File

@ -475,6 +475,21 @@ class WC_Checkout {
}
}
// Store fees
foreach ( $woocommerce->cart->get_fees() as $fee ) {
$item_id = woocommerce_add_order_item( $order_id, array(
'order_item_name' => $fee->name,
'order_item_type' => 'fee'
) );
if ( $fee->taxable )
woocommerce_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
else
woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $fee->amount ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) );
}
// UPDATE USER META

View File

@ -122,12 +122,6 @@ class WC_Order {
/** @var string Grand total */
var $order_total;
/** @var array Order line items array */
var $items;
/** @var array Order Fees array */
var $fees;
/** @var array Taxes array (tax rows) */
var $taxes;
@ -409,32 +403,30 @@ class WC_Order {
$type = array_map( 'esc_attr', $type );
if ( ! $this->items ) {
$line_items = $wpdb->get_results( $wpdb->prepare( "
SELECT order_item_id, order_item_name, order_item_type
FROM {$wpdb->prefix}woocommerce_order_items
WHERE order_id = %d
AND order_item_type IN ( '" . implode( "','", $type ) . "' )
ORDER BY order_item_id
", $this->id ) );
$line_items = $wpdb->get_results( $wpdb->prepare( "
SELECT order_item_id, order_item_name, order_item_type
FROM {$wpdb->prefix}woocommerce_order_items
WHERE order_id = %d
AND order_item_type IN ( '" . implode( "','", $type ) . "' )
ORDER BY order_item_id
", $this->id ) );
$items = array();
foreach ( $line_items as $item ) {
$this->items = array();
// Place line item into array to return
$items[ $item->order_item_id ]['name'] = $item->order_item_name;
$items[ $item->order_item_id ]['type'] = $item->order_item_type;
$items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id );
foreach ( $line_items as $item ) {
// Place line item into array to return
$this->items[ $item->order_item_id ]['name'] = $item->order_item_name;
$this->items[ $item->order_item_id ]['type'] = $item->order_item_type;
$this->items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id );
// Put meta into item array
foreach( $this->items[ $item->order_item_id ]['item_meta'] as $name => $value ) {
$key = substr( $name, 0, 1 ) == '_' ? substr( $name, 1 ) : $name;
$this->items[ $item->order_item_id ][ $key ] = $value[0];
}
// Put meta into item array
foreach( $items[ $item->order_item_id ]['item_meta'] as $name => $value ) {
$key = substr( $name, 0, 1 ) == '_' ? substr( $name, 1 ) : $name;
$items[ $item->order_item_id ][ $key ] = $value[0];
}
}
return $this->items;
return $items;
}
/**
@ -892,11 +884,23 @@ class WC_Order {
);
if ( $fees = $this->get_fees() )
foreach( $fees as $fee ) {
$total_rows['shipping'] = array(
'label' => $fee['name'],
'value' => woocommerce_price( $fee['line_total'] )
);
foreach( $fees as $id => $fee ) {
if ( $this->display_cart_ex_tax || ! $this->prices_include_tax ) {
$total_rows[ 'fee_' . $id ] = array(
'label' => $fee['name'],
'value' => woocommerce_price( $fee['line_total'] )
);
} else {
$total_rows[ 'fee_' . $id ] = array(
'label' => $fee['name'],
'value' => woocommerce_price( $fee['line_total'] + $fee['line_tax'] )
);
}
}
// Tax for tax exclusive prices

View File

@ -232,11 +232,18 @@ class WC_Mijireh_Checkout extends WC_Payment_Gateway {
// add items to order
$items = $wc_order->get_items();
foreach($items as $item) {
foreach( $items as $item ) {
$product = $wc_order->get_product_from_item( $item );
$mj_order->add_item( $item['name'], $wc_order->get_item_subtotal( $item, false, false ), $item['qty'], $product->get_sku() );
}
// Handle fees
$items = $wc_order->get_fees();
foreach( $items as $item ) {
$mj_order->add_item( $item['name'], $item['line_total'], 1, '' );
}
// add billing address to order
$billing = new Mijireh_Address();

View File

@ -353,6 +353,17 @@ class WC_Paypal extends WC_Payment_Gateway {
}
}
}
// Fees
if ( sizeof( $order->get_fees() ) > 0 ) {
foreach ( $order->get_fees() as $item ) {
$item_loop++;
$paypal_args[ 'item_name_' . $item_loop ] = $item['name'];
$paypal_args[ 'quantity_' . $item_loop ] = 1;
$paypal_args[ 'amount_' . $item_loop ] = $item['line_total'];
}
}
// Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
if ( $order->get_shipping() > 0 ) {

View File

@ -51,13 +51,18 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<tr class="fee fee-<?php echo $fee->id ?>">
<th><?php echo $fee->name ?></th>
<td><?php echo woocommerce_price( $fee->amount ) ?></td>
<td><?php
if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax )
echo woocommerce_price( $fee->amount );
else
echo woocommerce_price( $fee->amount + $fee->tax );
?></td>
</tr>
<?php endforeach; ?>
<?php
// Show the tax row if showing prices exlcusive of tax only
// Show the tax row if showing prices exclusive of tax only
if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax ) {
if ( $woocommerce->cart->get_cart_tax() ) {

View File

@ -51,6 +51,20 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<?php do_action('woocommerce_review_order_after_shipping'); ?>
<?php endif; ?>
<?php foreach ( $woocommerce->cart->get_fees() as $fee ) : ?>
<tr class="fee fee-<?php echo $fee->id ?>">
<th colspan="2"><?php echo $fee->name ?></th>
<td><?php
if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax )
echo woocommerce_price( $fee->amount );
else
echo woocommerce_price( $fee->amount + $fee->tax );
?></td>
</tr>
<?php endforeach; ?>
<?php
// Show the tax row if showing prices exlcusive of tax only

View File

@ -920,6 +920,7 @@ function woocommerce_ajax_add_order_fee() {
add_action('wp_ajax_woocommerce_add_order_fee', 'woocommerce_ajax_add_order_fee');
/**
* woocommerce_ajax_remove_order_item function.
*
@ -1114,7 +1115,7 @@ function woocommerce_calc_line_taxes() {
$item_id = esc_attr( $_POST['order_item_id'] );
$tax_class = esc_attr( $_POST['tax_class'] );
if ( ! $item_id )
if ( ! $item_id || $tax_class == '0' )
return;
// Get product details