Merge pull request #16869 from woocommerce/fix/16861

Fix legacy access to array props (fees, taxes, coupon totals + taxes)
This commit is contained in:
Claudiu Lodromanean 2017-09-21 09:47:29 -07:00 committed by GitHub
commit e713b5beb3
2 changed files with 71 additions and 33 deletions

View File

@ -1753,7 +1753,13 @@ class WC_Cart extends WC_Legacy_Cart {
* @return array * @return array
*/ */
public function get_fees() { public function get_fees() {
return $this->fees_api()->get_fees(); $fees = $this->fees_api()->get_fees();
if ( ! empty( $this->fees ) ) {
wc_deprecated_function( 'WC_Cart->fees', '3.2', sprintf( 'Fees should only be added through the Fees API (%s)', 'WC_Cart::add_fee()' ) );
$fees = $fees + $this->fees;
}
return $fees;
} }
/** /**

View File

@ -70,62 +70,94 @@ abstract class WC_Legacy_Cart {
* @param string $name Property name. * @param string $name Property name.
* @return mixed * @return mixed
*/ */
public function __get( $name ) { public function &__get( $name ) {
$value = '';
switch ( $name ) { switch ( $name ) {
case 'dp' : case 'dp' :
return wc_get_price_decimals(); $value = wc_get_price_decimals();
break;
case 'prices_include_tax' : case 'prices_include_tax' :
return wc_prices_include_tax(); $value = wc_prices_include_tax();
case 'round_at_subtotal' : case 'round_at_subtotal' :
return 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' ); $value = 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' );
// map old public props to methods. break;
case 'cart_contents_total' : case 'cart_contents_total' :
return $this->get_cart_contents_total(); $value = $this->get_cart_contents_total();
break;
case 'total' : case 'total' :
return $this->get_total( 'edit' ); $value = $this->get_total( 'edit' );
break;
case 'subtotal' : case 'subtotal' :
return $this->get_subtotal() + $this->get_subtotal_tax(); $value = $this->get_subtotal() + $this->get_subtotal_tax();
break;
case 'subtotal_ex_tax' : case 'subtotal_ex_tax' :
return $this->get_subtotal(); $value = $this->get_subtotal();
break;
case 'tax_total' : case 'tax_total' :
return $this->get_fee_tax() + $this->get_cart_contents_tax(); $value = $this->get_fee_tax() + $this->get_cart_contents_tax();
case 'taxes' : break;
return $this->get_taxes();
case 'shipping_taxes' :
return $this->get_shipping_taxes();
case 'fee_total' : case 'fee_total' :
return $this->get_fee_total(); $value = $this->get_fee_total();
break;
case 'discount_cart' : case 'discount_cart' :
return $this->get_discount_total(); $value = $this->get_discount_total();
break;
case 'discount_cart_tax' : case 'discount_cart_tax' :
return $this->get_discount_tax(); $value = $this->get_discount_tax();
break;
case 'shipping_total' : case 'shipping_total' :
return $this->get_shipping_total(); $value = $this->get_shipping_total();
break;
case 'shipping_tax_total' : case 'shipping_tax_total' :
return $this->get_shipping_tax(); $value = $this->get_shipping_tax();
case 'coupon_discount_amounts' : break;
return $this->get_coupon_discount_totals();
case 'coupon_discount_tax_amounts' :
return $this->get_coupon_discount_tax_totals();
case 'display_totals_ex_tax' : case 'display_totals_ex_tax' :
case 'display_cart_ex_tax' : case 'display_cart_ex_tax' :
return 'excl' === $this->tax_display_cart; $value = 'excl' === $this->tax_display_cart;
break;
case 'cart_contents_weight' : case 'cart_contents_weight' :
return $this->get_cart_contents_weight(); $value = $this->get_cart_contents_weight();
break;
case 'cart_contents_count' : case 'cart_contents_count' :
return $this->get_cart_contents_count(); $value = $this->get_cart_contents_count();
break;
case 'coupons' :
$value = $this->get_coupons();
break;
// Arrays returned by reference to allow modification without notices. TODO: Remove in 4.0.
case 'taxes' :
wc_deprecated_function( 'WC_Cart->taxes', '3.2', sprintf( 'getters (%s) and setters (%s)', 'WC_Cart::get_cart_contents_taxes()', 'WC_Cart::set_cart_contents_taxes()' ) );
$value = &$this->totals[ 'cart_contents_taxes' ];
break;
case 'shipping_taxes' :
wc_deprecated_function( 'WC_Cart->shipping_taxes', '3.2', sprintf( 'getters (%s) and setters (%s)', 'WC_Cart::get_shipping_taxes()', 'WC_Cart::set_shipping_taxes()' ) );
$value = &$this->totals[ 'shipping_taxes' ];
break;
case 'coupon_discount_amounts' :
$value = &$this->coupon_discount_totals;
break;
case 'coupon_discount_tax_amounts' :
$value = &$this->coupon_discount_tax_totals;
break;
case 'fees' : case 'fees' :
return $this->fees_api->get_fees(); $this->fees = $this->get_fees();
$value = &$this->fees;
break;
// Deprecated args. TODO: Remove in 4.0.
case 'tax' : case 'tax' :
wc_deprecated_argument( 'WC_Cart->tax', '2.3', 'Use WC_Tax:: directly' ); wc_deprecated_argument( 'WC_Cart->tax', '2.3', 'Use WC_Tax directly' );
$this->tax = new WC_Tax(); $this->tax = new WC_Tax();
return $this->tax; $value = $this->tax;
break;
case 'discount_total': case 'discount_total':
wc_deprecated_argument( 'WC_Cart->discount_total', '2.3', 'After tax coupons are no longer supported. For more information see: https://woocommerce.wordpress.com/2014/12/upcoming-coupon-changes-in-woocommerce-2-3/' ); wc_deprecated_argument( 'WC_Cart->discount_total', '2.3', 'After tax coupons are no longer supported. For more information see: https://woocommerce.wordpress.com/2014/12/upcoming-coupon-changes-in-woocommerce-2-3/' );
return 0; $value = 0;
case 'coupons' : break;
return $this->get_coupons();
} }
return $value;
} }
/** /**