Skip to content

Commit

Permalink
Merge pull request #118 from dallendalton/PI-235-WooCommerce-3.7-Support
Browse files Browse the repository at this point in the history
WooCommerce 3.7 Support
  • Loading branch information
dallendalton authored Aug 12, 2019
2 parents 4046863 + c39713b commit 485569c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
57 changes: 18 additions & 39 deletions tests/framework/product-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,28 @@ public static function create_product( $type = 'simple', $opts = array() ) {

private static function create_simple_product( $opts = array() ) {
$defaults = array(
'price' => '10',
'sku' => 'SIMPLE1',
'tax_class' => '',
'tax_status' => 'taxable',
'downloadable' => 'no',
'virtual' => 'no',
'name' => 'Dummy Product',
'price' => 10,
'sku' => 'SIMPLE1',
'manage_stock' => false,
'tax_status' => 'taxable',
'downloadable' => false,
'virtual' => false,
'stock_status' => 'instock',
'weight' => '1.1',
);

$post = array(
'post_title' => 'Dummy Product',
'post_type' => 'product',
'post_status' => 'publish',
);
$post_meta = array_replace_recursive( $defaults, $opts );
$post_meta['regular_price'] = $post_meta['price'];

$post_id = wp_insert_post( $post );

register_taxonomy(
'product_type',
'product'
);
$props = array_replace_recursive( $defaults, $opts );
$props[ 'regular_price' ] = $props[ 'price' ];
$product = new WC_Product_Simple();
$product->set_props( $props );

update_post_meta( $post_id, '_price', $post_meta['price'] );
update_post_meta( $post_id, '_regular_price', $post_meta['regular_price'] );
update_post_meta( $post_id, '_sale_price', '' );
update_post_meta( $post_id, '_sku', $post_meta['sku'] );
update_post_meta( $post_id, '_manage_stock', 'no' );
update_post_meta( $post_id, '_tax_class', $post_meta['tax_class'] );
update_post_meta( $post_id, '_tax_status', $post_meta['tax_status'] );
update_post_meta( $post_id, '_downloadable', $post_meta['downloadable'] );
update_post_meta( $post_id, '_virtual', $post_meta['virtual'] );
update_post_meta( $post_id, '_stock_status', 'instock' );

wp_set_object_terms( $post_id, 'simple', 'product_type' );

$products = get_posts( array(
'post_type' => 'product',
'_sku' => $post_meta['sku'],
) );
if ( ! empty( $opts[ 'tax_class' ] ) ) {
$product->set_tax_class( $opts[ 'tax_class' ] );
}

$factory = new WC_Product_Factory();
return $factory->get_product( $products[0]->ID );
$product->save( );
return wc_get_product( $product->get_id() );
}

private static function create_subscription_product( $opts = array() ) {
Expand Down
4 changes: 4 additions & 0 deletions tests/framework/woocommerce-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static function prepare_woocommerce() {
// WooCommerce 3.2 checks for a valid class
update_option( 'woocommerce_tax_classes', "Reduced rate\nZero Rate\nClothing Rate - 20010" );

if ( version_compare( WC()->version, '3.7.0', '>=' ) ) {
WC_Tax::create_tax_class( 'Clothing Rate - 20010' );
}

// Allow calculate_totals to run in specs for WooCommerce < 3.2
if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
define( 'WOOCOMMERCE_CART', true );
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/test-class-subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ function test_correct_taxes_for_subscription_recurring_order_with_trial_and_sign

TaxJar_Shipping_Helper::delete_simple_flat_rate();
}

function test_correct_taxes_for_subscription_recurring_order_with_multiple_products() {
wp_set_current_user( $this->user );

Expand Down

0 comments on commit 485569c

Please sign in to comment.