Merge branch 'master' into orphan-variations-fix-12614

# Conflicts:
#	includes/class-wc-post-data.php
This commit is contained in:
Mike Jolley 2017-01-11 15:42:20 +00:00
commit ba8f308100
13 changed files with 40 additions and 36 deletions

View File

@ -6,8 +6,6 @@ sudo: false
php:
- 5.2
- 5.3
# - 5.4
# - 5.5
- 5.6
- 7.0
- 7.1
@ -21,8 +19,6 @@ matrix:
include:
- php: 5.6
env: WP_VERSION=latest WP_MULTISITE=1
allow_failures:
- php: 7.1
before_script:
- bash tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION

View File

@ -1869,7 +1869,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) {
$availability = __( 'Available on backorder', 'woocommerce' );
} elseif ( $this->managing_stock() ) {
$availability = wc_format_stock_for_display( $this->get_stock_quantity(), $this->backorders_allowed() && $this->backorders_require_notification() );
$availability = wc_format_stock_for_display( $this );
} else {
$availability = '';
}

View File

@ -255,7 +255,7 @@ class WC_Admin_Duplicate_Product {
$post_terms_count = sizeof( $post_terms );
for ( $i = 0; $i < $post_terms_count; $i++ ) {
wp_set_object_terms( $new_id, $post_terms[ $i ]->slug, $taxonomy, true );
wp_set_object_terms( $new_id, (int) $post_terms[ $i ]->term_id, $taxonomy, true );
}
}
}

View File

@ -442,7 +442,7 @@ class WC_Admin_Post_Types {
* @param string $column
*/
public function render_shop_coupon_columns( $column ) {
global $post, $woocommerce;
global $post;
switch ( $column ) {
case 'coupon_code' :
@ -512,7 +512,7 @@ class WC_Admin_Post_Types {
* @param string $column
*/
public function render_shop_order_columns( $column ) {
global $post, $woocommerce, $the_order;
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );

View File

@ -207,22 +207,15 @@ class WC_Admin {
*/
public function admin_footer_text( $footer_text ) {
if ( ! current_user_can( 'manage_woocommerce' ) || ! function_exists( 'wc_get_screen_ids' ) ) {
return;
return $footer_text;
}
$current_screen = get_current_screen();
$wc_pages = wc_get_screen_ids();
// Set only wc pages
$wc_pages = array_flip( $wc_pages );
if ( isset( $wc_pages['profile'] ) ) {
unset( $wc_pages['profile'] );
}
if ( isset( $wc_pages['user-edit'] ) ) {
unset( $wc_pages['user-edit'] );
}
$wc_pages = array_flip( $wc_pages );
// Set only WC pages.
$wc_pages = array_diff( $wc_pages, array( 'profile', 'user-edit' ) );
// Check to make sure we're on a WooCommerce admin page
// Check to make sure we're on a WooCommerce admin page.
if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
// Change the footer text
if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {

View File

@ -490,7 +490,7 @@ class WC_Cart {
*/
if ( ! $product->has_enough_stock( $product_qty_in_cart[ $product->get_stock_managed_by_id() ] ) ) {
/* translators: 1: product name 2: quantity in stock */
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product->get_name(), $product->get_stock_quantity() ) );
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
return $error;
}
@ -924,7 +924,7 @@ class WC_Cart {
if ( ! $product_data->has_enough_stock( $quantity ) ) {
/* translators: 1: product name 2: quantity in stock */
throw new Exception( sprintf( __( 'You cannot add that amount of &quot;%1$s&quot; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce' ), $product_data->get_name(), $product_data->get_stock_quantity() ) );
throw new Exception( sprintf( __( 'You cannot add that amount of &quot;%1$s&quot; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce' ), $product_data->get_name(), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity(), $product_data ) ) );
}
// Stock check - this time accounting for whats already in-cart
@ -936,7 +936,7 @@ class WC_Cart {
'<a href="%s" class="button wc-forward">%s</a> %s',
wc_get_cart_url(),
__( 'View Cart', 'woocommerce' ),
sprintf( __( 'You cannot add that amount to the cart &mdash; we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), $product_data->get_stock_quantity(), $products_qty_in_cart[ $product_data->get_id() ] )
sprintf( __( 'You cannot add that amount to the cart &mdash; we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity(), $product_data ), wc_format_stock_quantity_for_display( $products_qty_in_cart[ $product_data->get_id() ], $product_data ) )
) );
}
}

View File

@ -82,7 +82,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
public function read( &$order ) {
$order->set_defaults();
if ( ! $order->get_id() || ! ( $post_object = get_post( $order->get_id() ) ) ) {
if ( ! $order->get_id() || ! ( $post_object = get_post( $order->get_id() ) ) || 'shop_order' !== $post_object->post_type ) {
throw new Exception( __( 'Invalid order.', 'woocommerce' ) );
}

View File

@ -85,7 +85,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
public function read( &$coupon ) {
$coupon->set_defaults();
if ( ! $coupon->get_id() || ! ( $post_object = get_post( $coupon->get_id() ) ) ) {
if ( ! $coupon->get_id() || ! ( $post_object = get_post( $coupon->get_id() ) ) || 'shop_coupon' !== $post_object->post_type ) {
throw new Exception( __( 'Invalid coupon.', 'woocommerce' ) );
}

View File

@ -113,7 +113,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
public function read( &$product ) {
$product->set_defaults();
if ( ! $product->get_id() || ! ( $post_object = get_post( $product->get_id() ) ) ) {
if ( ! $product->get_id() || ! ( $post_object = get_post( $product->get_id() ) ) || 'product' !== $post_object->post_type ) {
throw new Exception( __( 'Invalid product.', 'woocommerce' ) );
}

View File

@ -94,7 +94,9 @@ class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Shippin
$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zone_locations', array( 'zone_id' => $zone->get_id() ) );
$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zones', array( 'zone_id' => $zone->get_id() ) );
WC_Cache_Helper::incr_cache_prefix( 'shipping_zones' );
$id = $zone->get_id();
$zone->set_id( null );
do_action( 'woocommerce_delete_shipping_zone', $id );
}
}
@ -160,6 +162,7 @@ class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Shippin
public function delete_method( $instance_id ) {
global $wpdb;
$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zone_methods', array( 'instance_id' => $instance_id ) );
do_action( 'woocommerce_delete_shipping_zone_method', $instance_id );
}
/**

View File

@ -922,32 +922,45 @@ if ( ! function_exists( 'wc_make_numeric_postcode' ) ) {
/**
* Format the stock amount ready for display based on settings.
*
* @since 2.7.0
* @param int $stock_amount
* @param boolean $show_backorder_notification
* @param WC_Product $product Product object for which the stock you need to format.
* @return string
*/
function wc_format_stock_for_display( $stock_amount, $show_backorder_notification = false ) {
$display = __( 'In stock', 'woocommerce' );
function wc_format_stock_for_display( $product ) {
$display = __( 'In stock', 'woocommerce' );
$stock_amount = $product->get_stock_quantity();
switch ( get_option( 'woocommerce_stock_format' ) ) {
case 'low_amount' :
if ( $stock_amount <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
$display = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $stock_amount );
$display = sprintf( __( 'Only %s left in stock', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount, $product ) );
}
break;
case '' :
$display = sprintf( __( '%s in stock', 'woocommerce' ), $stock_amount );
$display = sprintf( __( '%s in stock', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount, $product ) );
break;
}
if ( $show_backorder_notification ) {
if ( $product->backorders_allowed() && $product->backorders_require_notification() ) {
$display .= ' ' . __( '(can be backordered)', 'woocommerce' );
}
return $display;
}
/**
* Format the stock quantity ready for display.
*
* @since 2.7.0
* @param int $stock_quantity
* @param WC_Product $product so that we can pass through the filters.
* @return string
*/
function wc_format_stock_quantity_for_display( $stock_quantity, $product ) {
return apply_filters( 'woocommerce_format_stock_quantity', $stock_quantity, $product );
}
/**
* Format a sale price for display.
* @since 2.7.0

View File

@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $post, $product, $woocommerce;
global $post, $product;
$attachment_ids = $product->get_gallery_image_ids();

View File

@ -30,7 +30,7 @@ if [ $1 == 'before' ]; then
elif [ $1 == 'during' ]; then
## Only run on 7.0 box.
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then
if [ $TRAVIS_PHP_VERSION == "7.0" ]; then
# WordPress Coding Standards.
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
# @link http://pear.php.net/package/PHP_CodeSniffer/
@ -50,8 +50,7 @@ elif [ $1 == 'during' ]; then
elif [ $1 == 'after' ]; then
## Only run on 7.0 box.
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then
# Get scrutinizer ocular and run it
if [ $TRAVIS_PHP_VERSION == "7.0" ]; then
wget https://scrutinizer-ci.com/ocular.phar
chmod +x ocular.phar
php ocular.phar code-coverage:upload --format=php-clover ./tmp/clover.xml