2014-10-21 13:09:03 +00:00
|
|
|
<?php
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* Cart tests.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\Cart
|
|
|
|
*/
|
2014-10-21 13:09:03 +00:00
|
|
|
|
2015-03-06 15:32:40 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Cart.
|
2015-03-06 15:32:40 +00:00
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Cart extends WC_Unit_Test_Case {
|
2019-04-17 15:41:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown.
|
|
|
|
*/
|
2018-08-21 14:41:31 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->customer->set_is_vat_exempt( false );
|
2018-08-21 14:41:31 +00:00
|
|
|
}
|
2014-10-21 13:09:03 +00:00
|
|
|
|
2019-11-26 21:43:39 +00:00
|
|
|
/**
|
|
|
|
* Test whether totals are correct when discount is applied.
|
|
|
|
*/
|
|
|
|
public function test_cart_total_with_discount_and_taxes() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'TAX20',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '20percent',
|
|
|
|
);
|
|
|
|
$tax_rate_20 = WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create product with price 19.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_price( 8.99 );
|
|
|
|
$product->set_regular_price( 8.99 );
|
|
|
|
$product->set_tax_class( '20percent' );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
$coupon = WC_Helper_Coupon::create_coupon( 'off5', array( 'coupon_amount' => 5 ) );
|
|
|
|
|
|
|
|
// Create a flat rate method.
|
|
|
|
$flat_rate_settings = array(
|
|
|
|
'enabled' => 'yes',
|
|
|
|
'title' => 'Flat rate',
|
|
|
|
'availability' => 'all',
|
|
|
|
'countries' => '',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'cost' => '9.59',
|
|
|
|
);
|
|
|
|
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
|
2020-06-23 13:10:27 +00:00
|
|
|
|
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2019-11-26 21:43:39 +00:00
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
|
|
|
$this->assertEquals( '13.58', WC()->cart->get_total( 'edit' ) );
|
|
|
|
$this->assertEquals( 0.66, WC()->cart->get_total_tax() );
|
|
|
|
$this->assertEquals( 4.17, WC()->cart->get_discount_total() );
|
|
|
|
$this->assertEquals( 0.83, WC()->cart->get_discount_tax() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-11 11:34:47 +00:00
|
|
|
/**
|
|
|
|
* Test for subtotals and multiple tax rounding.
|
|
|
|
* Ticket:
|
|
|
|
* https://github.com/woocommerce/woocommerce/issues/21871
|
|
|
|
*/
|
|
|
|
public function test_cart_subtotal_issue_21871() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'no' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'no' );
|
|
|
|
update_option( 'woocommerce_tax_display_cart', 'incl' );
|
|
|
|
|
|
|
|
// Create dummy product - price will be 10.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_regular_price( 79 );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
// Add taxes.
|
|
|
|
$tax_rate_025 = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '0.2500',
|
|
|
|
'tax_rate_name' => 'TAX025',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$tax_rate_06 = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '6.0000',
|
|
|
|
'tax_rate_name' => 'TAX06',
|
|
|
|
'tax_rate_priority' => '2',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$tax_rate_015 = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '1.5000',
|
|
|
|
'tax_rate_name' => 'TAX015',
|
|
|
|
'tax_rate_priority' => '3',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$tax_rate_01 = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '1.000',
|
|
|
|
'tax_rate_name' => 'TAX01',
|
|
|
|
'tax_rate_priority' => '4',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart x1, calc and test.
|
2019-01-11 11:34:47 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '85.92', number_format( WC()->cart->total, 2, '.', '' ) );
|
|
|
|
$this->assertEquals( '85.92', number_format( WC()->cart->subtotal, 2, '.', '' ) );
|
|
|
|
$this->assertEquals( '85.92', wc_get_price_including_tax( $product ) );
|
|
|
|
|
|
|
|
WC_Helper_Product::delete_product( $product->get_id() );
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_025 );
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_06 );
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_015 );
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_01 );
|
|
|
|
}
|
|
|
|
|
2018-08-29 16:18:57 +00:00
|
|
|
/**
|
|
|
|
* Test tax rounding.
|
2019-04-17 15:41:04 +00:00
|
|
|
* Ticket: https://github.com/woocommerce/woocommerce/issues/21021.
|
2018-08-29 16:18:57 +00:00
|
|
|
*/
|
|
|
|
public function test_cart_get_total_issue_21021() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
// Set an address so that shipping can be calculated.
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2019-12-06 16:48:13 +00:00
|
|
|
|
2020-04-01 20:51:43 +00:00
|
|
|
// Create tax classes first.
|
|
|
|
WC_Tax::create_tax_class( '23percent' );
|
|
|
|
WC_Tax::create_tax_class( '5percent' );
|
|
|
|
|
2019-05-01 22:05:00 +00:00
|
|
|
$tax_rate = array(
|
2018-08-29 16:18:57 +00:00
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '23.0000',
|
|
|
|
'tax_rate_name' => 'TAX23',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '23percent',
|
|
|
|
);
|
2018-08-29 17:24:29 +00:00
|
|
|
$tax_rate_23 = WC_Tax::_insert_tax_rate( $tax_rate );
|
2018-08-29 16:18:57 +00:00
|
|
|
|
2019-05-01 22:05:00 +00:00
|
|
|
$tax_rate = array(
|
2018-08-29 16:18:57 +00:00
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '5.0000',
|
|
|
|
'tax_rate_name' => 'TAX5',
|
|
|
|
'tax_rate_priority' => '2',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '5percent',
|
|
|
|
);
|
2018-08-29 17:24:29 +00:00
|
|
|
$tax_rate_5 = WC_Tax::_insert_tax_rate( $tax_rate );
|
2018-08-29 16:18:57 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create product with price 19.
|
2018-08-29 16:18:57 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_price( 19 );
|
2018-08-29 17:43:57 +00:00
|
|
|
$product->set_regular_price( 19 );
|
|
|
|
$product->set_tax_class( '5percent' );
|
2018-08-29 16:18:57 +00:00
|
|
|
$product->save();
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create product with price 59.
|
2018-08-29 16:18:57 +00:00
|
|
|
$product2 = WC_Helper_Product::create_simple_product();
|
|
|
|
$product2->set_price( 59 );
|
2018-08-29 17:43:57 +00:00
|
|
|
$product2->set_regular_price( 59 );
|
2020-03-02 08:38:53 +00:00
|
|
|
$product2->set_tax_class( '23percent' );
|
2018-08-29 16:18:57 +00:00
|
|
|
$product2->save();
|
|
|
|
|
|
|
|
// Create a flat rate method.
|
|
|
|
$flat_rate_settings = array(
|
|
|
|
'enabled' => 'yes',
|
|
|
|
'title' => 'Flat rate',
|
|
|
|
'availability' => 'all',
|
|
|
|
'countries' => '',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'cost' => '8.05',
|
|
|
|
);
|
|
|
|
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
|
|
|
|
update_option( 'woocommerce_flat_rate', array() );
|
|
|
|
WC_Cache_Helper::get_transient_version( 'shipping', true );
|
|
|
|
WC()->shipping->load_shipping_methods();
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Set the flat_rate shipping method.
|
2018-08-29 16:18:57 +00:00
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart x1, calc and test.
|
2018-08-29 16:18:57 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
WC()->cart->calculate_totals();
|
2020-04-01 20:51:43 +00:00
|
|
|
$this->assertEquals( 27.05, WC()->cart->total );
|
2018-08-29 16:18:57 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product2 to cart.
|
2018-08-29 16:18:57 +00:00
|
|
|
WC()->cart->add_to_cart( $product2->get_id(), 1 );
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( 87.9, WC()->cart->total );
|
|
|
|
|
2018-08-29 17:24:29 +00:00
|
|
|
WC_Helper_Product::delete_product( $product->get_id() );
|
|
|
|
WC_Helper_Product::delete_product( $product2->get_id() );
|
|
|
|
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_23 );
|
|
|
|
WC_Tax::_delete_tax_rate( $tax_rate_5 );
|
2018-08-29 16:18:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 14:53:59 +00:00
|
|
|
/**
|
|
|
|
* Test for subtotal when multiple tax slabs are present and round at subtotal is enabled.
|
|
|
|
*
|
|
|
|
* Ticket: @link https://github.com/woocommerce/woocommerce/issues/23917
|
|
|
|
*/
|
|
|
|
public function test_cart_calculate_total_rounding_23917() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
|
|
|
|
2019-12-20 17:21:08 +00:00
|
|
|
$tax_rate = array(
|
2019-06-27 14:53:59 +00:00
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '24.0000',
|
|
|
|
'tax_rate_name' => 'CGST',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => 'tax_1',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2019-12-20 17:21:08 +00:00
|
|
|
$tax_rate = array(
|
2019-06-27 14:53:59 +00:00
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '24.0000',
|
|
|
|
'tax_rate_name' => 'SGST',
|
|
|
|
'tax_rate_priority' => '2',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => 'tax_2',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create a product with price 599.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_regular_price( 599 );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( 599, WC()->cart->subtotal );
|
|
|
|
$this->assertEquals( 599, WC()->cart->total );
|
|
|
|
}
|
|
|
|
|
2016-05-23 15:23:51 +00:00
|
|
|
/**
|
|
|
|
* Test some discount logic which has caused issues in the past.
|
2019-04-17 15:41:04 +00:00
|
|
|
* Ticket: https://github.com/woocommerce/woocommerce/issues/10963.
|
2016-05-23 15:23:51 +00:00
|
|
|
*
|
|
|
|
* Due to discounts being split amongst products in cart.
|
|
|
|
*/
|
2018-08-21 14:41:31 +00:00
|
|
|
public function test_cart_get_discounted_price_issue_10963() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy coupon - fixed cart, 1 value.
|
2019-05-01 22:05:00 +00:00
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
2016-05-23 15:23:51 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add coupon.
|
2016-08-12 15:41:06 +00:00
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
2016-05-23 15:23:51 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product - price will be 10.
|
2016-05-23 15:23:51 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart x1, calc and test.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2016-05-23 15:23:51 +00:00
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '9.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
|
|
|
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart x2, calc and test.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2016-05-23 15:23:51 +00:00
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '19.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
|
|
|
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart x3, calc and test.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2016-05-23 15:23:51 +00:00
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '29.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
|
|
|
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
2018-08-21 14:41:31 +00:00
|
|
|
}
|
2016-05-23 15:23:51 +00:00
|
|
|
|
2018-08-21 14:41:31 +00:00
|
|
|
/**
|
|
|
|
* Ticket: https://github.com/woocommerce/woocommerce/issues/11626
|
|
|
|
*/
|
|
|
|
public function test_cart_get_discounted_price_issue_11626() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => '13.90', // Tax exempt customer: all the prices without tax, then halved, i.e. sum = 33.09, sum_w/o_tax = 27.807, halved = 13.9035.
|
|
|
|
0 => '16.55', // Normal customer: all the prices halved, i.e. sum = 33.09, halved = 16.545.
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create dummy coupon - fixed cart, 1 value.
|
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
2016-08-05 11:11:35 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Test case 3 #11626.
|
2016-08-12 15:41:06 +00:00
|
|
|
update_post_meta( $coupon->get_id(), 'discount_type', 'percent' );
|
|
|
|
update_post_meta( $coupon->get_id(), 'coupon_amount', '50' );
|
2016-08-05 11:11:35 +00:00
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '19.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
2016-08-27 01:46:45 +00:00
|
|
|
'tax_rate_class' => '',
|
2016-08-05 11:11:35 +00:00
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
$product_ids = array();
|
|
|
|
$products_data = array(
|
2016-08-27 03:04:10 +00:00
|
|
|
'5.17',
|
|
|
|
'3.32',
|
|
|
|
'1.25',
|
|
|
|
'3.50',
|
|
|
|
'5.01',
|
|
|
|
'3.34',
|
|
|
|
'5.99',
|
|
|
|
'5.51',
|
2016-08-05 11:11:35 +00:00
|
|
|
);
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $value ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
|
|
|
|
|
|
|
foreach ( $products_data as $price ) {
|
|
|
|
$loop_product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product_ids[] = $loop_product->get_id();
|
|
|
|
$loop_product->set_regular_price( $price );
|
|
|
|
$loop_product->save();
|
|
|
|
WC()->cart->add_to_cart( $loop_product->get_id(), 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( $value, WC()->cart->total );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2018-08-21 14:41:31 +00:00
|
|
|
}
|
2016-08-05 11:11:35 +00:00
|
|
|
|
2018-08-21 14:41:31 +00:00
|
|
|
/**
|
|
|
|
* Ticket: https://github.com/woocommerce/woocommerce/issues/10573
|
|
|
|
*/
|
|
|
|
public function test_cart_get_discounted_price_issue_10573() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy coupon - fixed cart, 1 value.
|
2019-05-01 22:05:00 +00:00
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
2016-08-05 11:11:35 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product - price will be 10.
|
2018-08-21 14:41:31 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2016-08-05 11:11:35 +00:00
|
|
|
|
2018-08-21 14:41:31 +00:00
|
|
|
$product->set_regular_price( '29.95' );
|
|
|
|
$product->save();
|
|
|
|
update_post_meta( $coupon->get_id(), 'discount_type', 'percent' );
|
|
|
|
update_post_meta( $coupon->get_id(), 'coupon_amount', '10' );
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
$product = wc_get_product( $product->get_id() );
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
2016-05-23 15:56:31 +00:00
|
|
|
|
2018-08-21 14:41:31 +00:00
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$cart_item = current( WC()->cart->get_cart() );
|
|
|
|
$this->assertEquals( '24.51', number_format( $cart_item['line_total'], 2, '.', '' ) );
|
2016-05-23 15:23:51 +00:00
|
|
|
}
|
2014-10-21 13:09:03 +00:00
|
|
|
|
2017-08-02 18:41:52 +00:00
|
|
|
/**
|
|
|
|
* Test that calculation rounding is done correctly with and without taxes.
|
|
|
|
*
|
2019-04-17 15:41:04 +00:00
|
|
|
* @see https://github.com/woocommerce/woocommerce/issues/16305.
|
2017-08-02 18:41:52 +00:00
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_discount_cart_rounding() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => array( '31.12', '31.12' ), // Tax exempt customer: Total and Total + tax are the same.
|
|
|
|
0 => array( '31.12', '33.69' ), // Normal customer: Total, then Total + tax.
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test with no taxes.
|
2018-03-13 18:41:25 +00:00
|
|
|
$product = new WC_Product_Simple();
|
2017-08-02 18:41:52 +00:00
|
|
|
$product->set_regular_price( 51.86 );
|
|
|
|
$product->save();
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
$coupon = new WC_Coupon();
|
2017-08-02 18:41:52 +00:00
|
|
|
$coupon->set_code( 'testpercent' );
|
|
|
|
$coupon->set_discount_type( 'percent' );
|
|
|
|
$coupon->set_amount( 40 );
|
|
|
|
$coupon->save();
|
|
|
|
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '8.2500',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $values ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-08-02 18:41:52 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Test without taxes.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'no' );
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$cart_item = current( WC()->cart->get_cart() );
|
|
|
|
$this->assertEquals( $values[0], number_format( $cart_item['line_total'], 2, '.', '' ) );
|
|
|
|
|
|
|
|
// Clean up.
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test with taxes.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'no' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$cart_item = current( WC()->cart->get_cart() );
|
|
|
|
$this->assertEquals( $values[1], number_format( $cart_item['line_total'] + $cart_item['line_tax'], 2, '.', '' ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-08-02 18:41:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 22:26:16 +00:00
|
|
|
/**
|
|
|
|
* Test cart calculations when out of base location and using inclusive taxes and discounts.
|
|
|
|
*
|
2017-11-03 20:52:17 +00:00
|
|
|
* @see GitHub issues #17517 and #17536.
|
|
|
|
* @since 3.3
|
2017-11-02 22:26:16 +00:00
|
|
|
*/
|
2017-11-03 20:52:17 +00:00
|
|
|
public function test_out_of_base_discounts_inclusive_tax() {
|
2017-11-02 22:26:16 +00:00
|
|
|
// Set up tax options.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_default_country', 'GB' );
|
|
|
|
update_option( 'woocommerce_default_customer_address', 'base' );
|
|
|
|
update_option( 'woocommerce_tax_based_on', 'shipping' );
|
|
|
|
|
|
|
|
// 20% tax for GB.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => 'GB',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// 20% tax everywhere else.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2017-11-03 20:52:17 +00:00
|
|
|
// Create product.
|
2018-03-13 18:41:25 +00:00
|
|
|
$product = new WC_Product_Simple();
|
2017-11-06 21:18:12 +00:00
|
|
|
$product->set_regular_price( '9.99' );
|
2017-11-02 22:26:16 +00:00
|
|
|
$product->save();
|
|
|
|
|
|
|
|
// Create coupons.
|
2018-03-13 18:41:25 +00:00
|
|
|
$ten_coupon = new WC_Coupon();
|
2017-11-02 22:26:16 +00:00
|
|
|
$ten_coupon->set_code( '10off' );
|
|
|
|
$ten_coupon->set_discount_type( 'percent' );
|
|
|
|
$ten_coupon->set_amount( 10 );
|
|
|
|
$ten_coupon->save();
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
$half_coupon = new WC_Coupon();
|
2017-11-02 22:26:16 +00:00
|
|
|
$half_coupon->set_code( '50off' );
|
|
|
|
$half_coupon->set_discount_type( 'percent' );
|
|
|
|
$half_coupon->set_amount( 50 );
|
|
|
|
$half_coupon->save();
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
$full_coupon = new WC_Coupon();
|
2017-11-02 22:26:16 +00:00
|
|
|
$full_coupon->set_code( '100off' );
|
|
|
|
$full_coupon->set_discount_type( 'percent' );
|
|
|
|
$full_coupon->set_amount( 100 );
|
|
|
|
$full_coupon->save();
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
add_filter( 'woocommerce_customer_get_shipping_country', array( $this, 'force_customer_gb_country' ) );
|
|
|
|
add_filter( 'woocommerce_customer_get_shipping_postcode', array( $this, 'force_customer_gb_postcode' ) );
|
2017-11-03 20:52:17 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test in store location with no coupon.
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
2017-11-06 21:26:28 +00:00
|
|
|
$this->assertEquals( '1.66', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '9.99', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
|
|
|
|
// Test in store location with 10% coupon.
|
|
|
|
WC()->cart->add_discount( $ten_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
2017-12-05 12:10:23 +00:00
|
|
|
$this->assertEquals( '1.50', wc_format_decimal( WC()->cart->get_total_tax(), 2 ), WC()->cart->get_total_tax() );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.99', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test in store location with 50% coupon.
|
|
|
|
WC()->cart->add_discount( $half_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '4.16', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '5.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test in store location with 100% coupon.
|
|
|
|
WC()->cart->add_discount( $full_coupon->get_code() );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
2017-11-06 21:18:12 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_discount_total(), 2 ), 'Discount total in base' );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
2017-11-03 20:52:17 +00:00
|
|
|
WC()->cart->empty_cart();
|
2019-12-06 16:48:13 +00:00
|
|
|
remove_filter( 'woocommerce_customer_get_shipping_country', array( $this, 'force_customer_gb_country' ) );
|
|
|
|
remove_filter( 'woocommerce_customer_get_shipping_postcode', array( $this, 'force_customer_gb_postcode' ) );
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2017-11-03 20:52:17 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test out of store location with no coupon.
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
2017-11-06 21:26:28 +00:00
|
|
|
$this->assertEquals( '1.66', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '9.99', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
|
|
|
|
// Test out of store location with 10% coupon.
|
|
|
|
WC()->cart->add_discount( $ten_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '1.50', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '8.99', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 50% coupon.
|
|
|
|
WC()->cart->add_discount( $half_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '4.16', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '5.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 100% coupon.
|
|
|
|
WC()->cart->add_discount( $full_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
2017-11-06 21:18:12 +00:00
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_discount_total(), 2 ), 'Discount total out of base' );
|
2017-11-03 20:52:17 +00:00
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
2017-11-02 22:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
/**
|
|
|
|
* Test cart calculations when out of base location and using inclusive taxes and discounts, for tax exempt customer.
|
|
|
|
*
|
|
|
|
* @see GitHub issues #17517 and #17536.
|
|
|
|
* @since 3.5
|
|
|
|
*/
|
|
|
|
public function test_out_of_base_discounts_inclusive_tax_for_tax_exempt_customer() {
|
|
|
|
WC()->customer->set_is_vat_exempt( true );
|
|
|
|
|
|
|
|
// Set up tax options.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_default_country', 'GB' );
|
|
|
|
update_option( 'woocommerce_default_customer_address', 'base' );
|
|
|
|
update_option( 'woocommerce_tax_based_on', 'shipping' );
|
|
|
|
|
|
|
|
// 20% tax for GB.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => 'GB',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// 20% tax everywhere else.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create product.
|
|
|
|
$product = new WC_Product_Simple();
|
|
|
|
$product->set_regular_price( '9.99' );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
// Create coupons.
|
|
|
|
$ten_coupon = new WC_Coupon();
|
|
|
|
$ten_coupon->set_code( '10off' );
|
|
|
|
$ten_coupon->set_discount_type( 'percent' );
|
|
|
|
$ten_coupon->set_amount( 10 );
|
|
|
|
$ten_coupon->save();
|
|
|
|
|
|
|
|
$half_coupon = new WC_Coupon();
|
|
|
|
$half_coupon->set_code( '50off' );
|
|
|
|
$half_coupon->set_discount_type( 'percent' );
|
|
|
|
$half_coupon->set_amount( 50 );
|
|
|
|
$half_coupon->save();
|
|
|
|
|
|
|
|
$full_coupon = new WC_Coupon();
|
|
|
|
$full_coupon->set_code( '100off' );
|
|
|
|
$full_coupon->set_discount_type( 'percent' );
|
|
|
|
$full_coupon->set_amount( 100 );
|
|
|
|
$full_coupon->save();
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
add_filter( 'woocommerce_customer_get_shipping_country', array( $this, 'force_customer_gb_country' ) );
|
|
|
|
add_filter( 'woocommerce_customer_get_shipping_postcode', array( $this, 'force_customer_gb_postcode' ) );
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test in store location with no coupon.
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
|
|
|
|
// Test in store location with 10% coupon.
|
|
|
|
WC()->cart->add_discount( $ten_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ), WC()->cart->get_total_tax() );
|
|
|
|
$this->assertEquals( '7.50', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test in store location with 50% coupon.
|
|
|
|
WC()->cart->add_discount( $half_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '4.16', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '4.17', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test in store location with 100% coupon.
|
|
|
|
WC()->cart->add_discount( $full_coupon->get_code() );
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_discount_total(), 2 ), 'Discount total in base' );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
2019-12-06 16:48:13 +00:00
|
|
|
remove_filter( 'woocommerce_customer_get_shipping_country', array( $this, 'force_customer_gb_country' ) );
|
|
|
|
remove_filter( 'woocommerce_customer_get_shipping_postcode', array( $this, 'force_customer_gb_postcode' ) );
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test out of store location with no coupon.
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
|
|
|
|
// Test out of store location with 10% coupon.
|
|
|
|
WC()->cart->add_discount( $ten_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '7.50', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 50% coupon.
|
|
|
|
WC()->cart->add_discount( $half_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '4.16', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '4.17', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 100% coupon.
|
|
|
|
WC()->cart->add_discount( $full_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_discount_total(), 2 ), 'Discount total out of base' );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
}
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
/**
|
|
|
|
* Test cart calculations when out of base location with no matching taxes and using inclusive taxes and discounts.
|
|
|
|
*
|
|
|
|
* @see GitHub issue #19390.
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
public function test_out_of_base_discounts_inclusive_tax_no_oob_tax() {
|
|
|
|
// Set up tax options.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_default_country', 'GB' );
|
|
|
|
update_option( 'woocommerce_default_customer_address', 'base' );
|
|
|
|
update_option( 'woocommerce_tax_based_on', 'shipping' );
|
|
|
|
|
|
|
|
// 20% tax for GB.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => 'GB',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// 0% tax everywhere else.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '0.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create product.
|
|
|
|
$product = new WC_Product_Simple();
|
|
|
|
$product->set_regular_price( '24.99' );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
// Create coupon.
|
|
|
|
$ten_coupon = new WC_Coupon();
|
|
|
|
$ten_coupon->set_code( '10off' );
|
|
|
|
$ten_coupon->set_discount_type( 'percent' );
|
|
|
|
$ten_coupon->set_amount( 10 );
|
|
|
|
$ten_coupon->save();
|
|
|
|
|
|
|
|
$half_coupon = new WC_Coupon();
|
|
|
|
$half_coupon->set_code( '50off' );
|
|
|
|
$half_coupon->set_discount_type( 'percent' );
|
|
|
|
$half_coupon->set_amount( 50 );
|
|
|
|
$half_coupon->save();
|
|
|
|
|
|
|
|
$full_coupon = new WC_Coupon();
|
|
|
|
$full_coupon->set_code( '100off' );
|
|
|
|
$full_coupon->set_discount_type( 'percent' );
|
|
|
|
$full_coupon->set_amount( 100 );
|
|
|
|
$full_coupon->save();
|
|
|
|
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2018-03-13 18:41:25 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test out of store location with no coupon.
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
|
|
|
|
// Test out of store location with 10% coupon.
|
|
|
|
WC()->cart->add_discount( $ten_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '2.08', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '18.75', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 50% coupon.
|
|
|
|
WC()->cart->add_discount( $half_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '10.41', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '10.42', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
WC()->cart->remove_coupons();
|
|
|
|
|
|
|
|
// Test out of store location with 100% coupon.
|
|
|
|
WC()->cart->add_discount( $full_coupon->get_code() );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
|
|
|
|
$this->assertEquals( '20.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ), 'Discount total out of base' );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
$this->assertEquals( '0.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
}
|
|
|
|
|
2017-11-03 20:52:17 +00:00
|
|
|
/**
|
|
|
|
* Helper that can be hooked to a filter to force the customer's shipping country to be GB.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
2019-04-17 15:41:04 +00:00
|
|
|
* @param string $country Country code.
|
2017-11-03 20:52:17 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2019-12-06 16:48:13 +00:00
|
|
|
public function force_customer_gb_country( $country ) {
|
2017-11-03 20:52:17 +00:00
|
|
|
return 'GB';
|
|
|
|
}
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
/**
|
|
|
|
* Helper that can be hooked to a filter to force the customer's shipping postal code to be ANN NAA.
|
|
|
|
*
|
2020-01-31 17:03:54 +00:00
|
|
|
* @since 4.0.0
|
2019-12-06 16:48:13 +00:00
|
|
|
* @param string $postcode Postal code..
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function force_customer_gb_postcode( $postcode ) {
|
|
|
|
return 'ANN NAA';
|
|
|
|
}
|
|
|
|
|
2017-11-03 20:52:17 +00:00
|
|
|
/**
|
|
|
|
* Helper that can be hooked to a filter to force the customer's shipping country to be US.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
2019-04-17 15:41:04 +00:00
|
|
|
* @param string $country Country code.
|
2017-11-03 20:52:17 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2019-12-06 16:48:13 +00:00
|
|
|
public function force_customer_us_country( $country ) {
|
2020-06-23 13:10:27 +00:00
|
|
|
return WC_Helper_Shipping::force_customer_us_country( $country );
|
2017-11-03 20:52:17 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
/**
|
|
|
|
* Helper that can be hooked to a filter to force the customer's shipping state to be NY.
|
|
|
|
*
|
2020-01-31 17:03:54 +00:00
|
|
|
* @since 4.0.0
|
2019-12-06 16:48:13 +00:00
|
|
|
* @param string $state State code.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function force_customer_us_state( $state ) {
|
2020-06-23 13:10:27 +00:00
|
|
|
return WC_Helper_Shipping::force_customer_us_state( $state );
|
2019-12-06 16:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper that can be hooked to a filter to force the customer's shipping postal code to be 12345.
|
|
|
|
*
|
2020-01-31 17:03:54 +00:00
|
|
|
* @since 4.0.0
|
2019-12-06 16:48:13 +00:00
|
|
|
* @param string $postcode Postal code.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function force_customer_us_postcode( $postcode ) {
|
2020-06-23 13:10:27 +00:00
|
|
|
return WC_Helper_Shipping::force_customer_us_postcode( $postcode );
|
2019-12-06 16:48:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 19:38:09 +00:00
|
|
|
/**
|
|
|
|
* Test a rounding issue on prices that are entered inclusive tax and shipping is used.
|
|
|
|
* See: #17970.
|
|
|
|
*
|
|
|
|
* @since 3.2.6
|
|
|
|
*/
|
|
|
|
public function test_inclusive_tax_rounding() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => array( // Tax exempt customer.
|
|
|
|
'total' => '129.45', // Price -> price w/o tax, then + shipping, i.e. 149.14 -> 125.3277 + 4.12 = 129.45.
|
|
|
|
'total_tax' => '0.00', // No tax.
|
|
|
|
),
|
|
|
|
0 => array( // Normal customer.
|
|
|
|
'total' => '154.04', // Price + shipping + shipping tax, i.e. 149.14 + 4.12 * 1.19 = 154.04.
|
|
|
|
'total_tax' => '24.59', // Tax = price tax + shipping tax.
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2017-12-01 19:38:09 +00:00
|
|
|
// Store is set to enter product prices inclusive tax.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
// Set an address so that shipping can be calculated.
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2019-12-06 16:48:13 +00:00
|
|
|
|
2017-12-01 19:38:09 +00:00
|
|
|
// 19% tax.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '19.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create a flat rate method.
|
|
|
|
$flat_rate_settings = array(
|
|
|
|
'enabled' => 'yes',
|
|
|
|
'title' => 'Flat rate',
|
|
|
|
'availability' => 'all',
|
|
|
|
'countries' => '',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'cost' => '4.12',
|
|
|
|
);
|
|
|
|
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
|
|
|
|
update_option( 'woocommerce_flat_rate', array() );
|
|
|
|
WC_Cache_Helper::get_transient_version( 'shipping', true );
|
2018-10-02 15:03:17 +00:00
|
|
|
WC()->shipping()->load_shipping_methods();
|
2017-12-01 19:38:09 +00:00
|
|
|
|
|
|
|
// Create the product and add it to the cart.
|
2018-03-13 18:41:25 +00:00
|
|
|
$product = new WC_Product_Simple();
|
2017-12-01 19:38:09 +00:00
|
|
|
$product->set_regular_price( '149.14' );
|
|
|
|
$product->save();
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $values ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-12-01 19:38:09 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Set the flat_rate shipping method.
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( $values['total'], wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
$this->assertEquals( $values['total_tax'], wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-12-01 19:38:09 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 17:41:23 +00:00
|
|
|
/**
|
|
|
|
* Test a rounding issue on prices that are entered inclusive tax.
|
|
|
|
* See #20997
|
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*/
|
|
|
|
public function test_inclusive_tax_rounding_issue_20997() {
|
|
|
|
// Store is set to enter product prices inclusive tax.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_currency', 'EUR' );
|
|
|
|
update_option( 'woocommerce_price_decimal_sep', ',' );
|
|
|
|
|
|
|
|
// 22% tax.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '22.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create products and add them to cart.
|
|
|
|
$product1 = new WC_Product_Simple();
|
|
|
|
$product1->set_regular_price( '46,00' );
|
|
|
|
$product1->save();
|
|
|
|
|
|
|
|
$product2 = new WC_Product_Simple();
|
|
|
|
$product2->set_regular_price( '22,50' );
|
|
|
|
$product2->save();
|
2017-12-01 19:38:09 +00:00
|
|
|
|
2018-09-25 17:41:23 +00:00
|
|
|
$product3 = new WC_Product_Simple();
|
|
|
|
$product3->set_regular_price( '69,00' );
|
|
|
|
$product3->save();
|
|
|
|
|
|
|
|
$product4 = new WC_Product_Simple();
|
|
|
|
$product4->set_regular_price( '43,00' );
|
|
|
|
$product4->save();
|
|
|
|
|
|
|
|
$product5 = new WC_Product_Simple();
|
|
|
|
$product5->set_regular_price( '27,00' );
|
|
|
|
$product5->save();
|
|
|
|
|
|
|
|
$product6 = new WC_Product_Simple();
|
|
|
|
$product6->set_regular_price( '100.00' );
|
|
|
|
$product6->save();
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product1->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product2->get_id(), 1 );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
2020-07-01 21:13:29 +00:00
|
|
|
$expected_price = '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">€</span>68,50</bdi></span>';
|
2018-09-25 17:41:23 +00:00
|
|
|
$this->assertEquals( $expected_price, WC()->cart->get_total() );
|
|
|
|
$this->assertEquals( '12.36', wc_round_tax_total( WC()->cart->get_total_tax( 'edit' ) ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
WC()->cart->add_to_cart( $product3->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product4->get_id(), 1 );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
2020-07-01 21:13:29 +00:00
|
|
|
$expected_price = '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">€</span>112,00</bdi></span>';
|
2018-09-25 17:41:23 +00:00
|
|
|
$this->assertEquals( $expected_price, WC()->cart->get_total() );
|
|
|
|
$this->assertEquals( '20.19', wc_round_tax_total( WC()->cart->get_total_tax( 'edit' ) ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
WC()->cart->add_to_cart( $product3->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product4->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product5->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product6->get_id(), 1 );
|
2017-12-01 19:38:09 +00:00
|
|
|
WC()->cart->calculate_totals();
|
2018-09-25 17:41:23 +00:00
|
|
|
|
2020-07-01 21:13:29 +00:00
|
|
|
$expected_price = '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">€</span>239,00</bdi></span>';
|
2018-09-25 17:41:23 +00:00
|
|
|
$this->assertEquals( $expected_price, WC()->cart->get_total() );
|
|
|
|
$this->assertEquals( '43.09', wc_round_tax_total( WC()->cart->get_total_tax( 'edit' ) ) );
|
2017-12-01 19:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a rounding issue on prices that are entered exclusive tax.
|
|
|
|
* See: #17970.
|
|
|
|
*
|
|
|
|
* @since 3.2.6
|
|
|
|
*/
|
|
|
|
public function test_exclusive_tax_rounding() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => '95.84', // Tax exempt customer: Total = simple sum of prices w/o tax.
|
|
|
|
0 => '115.00', // Normal customer: Total = sum of prices with tax added.
|
|
|
|
);
|
|
|
|
|
2017-12-01 19:38:09 +00:00
|
|
|
// Store is set to enter product prices excluding tax.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'no' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
|
|
|
// 20% tax.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '0',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Add 2 products whose retail prices (inc tax) are: £65, £50.
|
|
|
|
// Their net prices are therefore: £54.1666667 and £41.6666667.
|
2018-03-13 18:41:25 +00:00
|
|
|
$product1 = new WC_Product_Simple();
|
2017-12-01 19:38:09 +00:00
|
|
|
$product1->set_regular_price( '54.1666667' );
|
|
|
|
$product1->save();
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
$product2 = new WC_Product_Simple();
|
2017-12-01 19:38:09 +00:00
|
|
|
$product2->set_regular_price( '41.6666667' );
|
|
|
|
$product2->save();
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $value ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-12-01 19:38:09 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product1->get_id(), 1 );
|
|
|
|
WC()->cart->add_to_cart( $product2->get_id(), 1 );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( $value, wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-12-01 19:38:09 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 09:49:31 +00:00
|
|
|
/**
|
|
|
|
* Test a rounding issue on prices and totals that are entered exclusive tax.
|
|
|
|
* See: #17647.
|
|
|
|
*
|
|
|
|
* @since 3.2.6
|
|
|
|
*/
|
|
|
|
public function test_exclusive_tax_rounding_and_totals() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => array( // Tax exempt customer.
|
|
|
|
'total_tax' => '0.00',
|
|
|
|
'cart_contents_tax' => '0.00',
|
|
|
|
'cart_contents_total' => '44.17',
|
|
|
|
'total' => '44.17',
|
|
|
|
),
|
|
|
|
0 => array( // Normal customer.
|
|
|
|
'total_tax' => '2.44',
|
|
|
|
'cart_contents_tax' => '2.44',
|
|
|
|
'cart_contents_total' => '44.17',
|
|
|
|
'total' => '46.61',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2017-12-07 09:49:31 +00:00
|
|
|
$product_data = array(
|
|
|
|
// price, quantity.
|
|
|
|
array( 2.13, 1 ),
|
|
|
|
array( 2.55, 0.5 ),
|
|
|
|
array( 39, 1 ),
|
|
|
|
array( 1.76, 1 ),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $product_data as $data ) {
|
|
|
|
$product = new WC_Product_Simple();
|
|
|
|
$product->set_regular_price( $data[0] );
|
|
|
|
$product->save();
|
|
|
|
$products[] = array( $product, $data[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '5.5',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'no' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'no' );
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $values ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-12-07 09:49:31 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $products as $data ) {
|
|
|
|
WC()->cart->add_to_cart( $data[0]->get_id(), $data[1] );
|
|
|
|
}
|
2017-12-07 09:49:31 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->cart->calculate_totals();
|
2017-12-07 09:49:31 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
$cart_totals = WC()->cart->get_totals();
|
2017-12-07 09:49:31 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
$this->assertEquals( $values['total_tax'], wc_format_decimal( $cart_totals['total_tax'], 2 ) );
|
|
|
|
$this->assertEquals( $values['cart_contents_tax'], wc_format_decimal( $cart_totals['cart_contents_tax'], 2 ) );
|
|
|
|
$this->assertEquals( $values['cart_contents_total'], wc_format_decimal( $cart_totals['cart_contents_total'], 2 ) );
|
|
|
|
$this->assertEquals( $values['total'], wc_format_decimal( $cart_totals['total'], 2 ) );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-12-07 09:49:31 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 18:56:56 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_remove_url.
|
2014-10-24 18:56:56 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_get_remove_url() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Get the cart page id.
|
2015-07-14 15:02:32 +00:00
|
|
|
$cart_page_url = wc_get_page_permalink( 'cart' );
|
2014-10-24 18:56:56 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Test cart item key.
|
2014-10-24 18:56:56 +00:00
|
|
|
$cart_item_key = 'test';
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Do the check.
|
2017-12-05 12:00:21 +00:00
|
|
|
$this->assertEquals( apply_filters( 'woocommerce_get_remove_url', $cart_page_url ? wp_nonce_url( add_query_arg( 'remove_item', $cart_item_key, $cart_page_url ), 'woocommerce-cart' ) : '' ), wc_get_cart_remove_url( $cart_item_key ) );
|
2014-10-24 18:56:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 22:25:52 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test add to cart simple product.
|
2014-10-24 18:35:49 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
2014-10-21 22:25:52 +00:00
|
|
|
*/
|
|
|
|
public function test_add_to_cart_simple() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-21 22:25:52 +00:00
|
|
|
|
2014-10-24 18:35:49 +00:00
|
|
|
// Add the product to the cart. Methods returns boolean on failure, string on success.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 1 ) );
|
2014-10-21 22:25:52 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check if the item is in the cart.
|
2014-10-24 18:35:49 +00:00
|
|
|
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
2014-10-21 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 22:27:14 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Check if we can add a trashed product to the cart.
|
2014-10-24 22:27:14 +00:00
|
|
|
*/
|
|
|
|
public function test_add_to_cart_trashed() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 22:27:14 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Trash product.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
wp_trash_post( $product->get_id() );
|
2014-10-24 22:27:14 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Refetch product, to be sure.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$product = wc_get_product( $product->get_id() );
|
2014-10-24 22:27:14 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$this->assertFalse( WC()->cart->add_to_cart( $product->get_id(), 1 ) );
|
2014-10-24 22:27:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 22:25:52 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test add to cart variable product.
|
2014-10-24 13:37:22 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
2014-10-21 22:25:52 +00:00
|
|
|
*/
|
|
|
|
public function test_add_to_cart_variable() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_variation_product();
|
2014-10-21 22:25:52 +00:00
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
$variation = array_shift( $variations );
|
|
|
|
|
2014-10-24 15:04:21 +00:00
|
|
|
// Add the product to the cart. Methods returns boolean on failure, string on success.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 1, $variation['variation_id'], array( 'Size' => ucfirst( $variation['attributes']['attribute_pa_size'] ) ) ) );
|
2014-10-21 22:25:52 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check if the item is in the cart.
|
2014-10-24 18:35:49 +00:00
|
|
|
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
2014-10-21 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 18:36:07 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Check if adding a product that is sold individually is corrected when adding multiple times.
|
2014-10-24 18:36:07 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_add_to_cart_sold_individually() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 18:36:07 +00:00
|
|
|
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_sold_individually( true );
|
|
|
|
$product->save();
|
2014-10-24 18:36:07 +00:00
|
|
|
|
|
|
|
// Add the product twice to cart, should be corrected to 1. Methods returns boolean on failure, string on success.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 2 ) );
|
2014-10-24 18:36:07 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check if the item is in the cart.
|
2014-10-24 18:36:07 +00:00
|
|
|
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:37:09 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test the find_product_in_cart method.
|
2014-10-24 13:37:09 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_find_product_in_cart() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 13:37:09 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-24 13:37:09 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Generate cart id.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$cart_id = WC()->cart->generate_cart_id( $product->get_id() );
|
2014-10-24 13:37:09 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Get the product from the cart.
|
2014-10-24 13:37:09 +00:00
|
|
|
$this->assertNotEquals( '', WC()->cart->find_product_in_cart( $cart_id ) );
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:26 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test the generate_cart_id method.
|
2014-10-24 13:43:26 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_generate_cart_id() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Setup data.
|
2014-10-24 13:43:26 +00:00
|
|
|
$product_id = 1;
|
|
|
|
$variation_id = 2;
|
|
|
|
$variation = array( 'Testing' => 'yup' );
|
|
|
|
$cart_item_data = array(
|
|
|
|
'string_val' => 'The string I was talking about',
|
|
|
|
'array_val' => array(
|
|
|
|
'this',
|
|
|
|
'is',
|
|
|
|
'an',
|
2016-08-27 02:08:49 +00:00
|
|
|
'array',
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
2014-10-24 13:43:26 +00:00
|
|
|
);
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Manually generate ID.
|
2014-10-24 13:43:26 +00:00
|
|
|
$id_parts = array( $product_id );
|
|
|
|
|
|
|
|
if ( $variation_id && 0 != $variation_id ) {
|
|
|
|
$id_parts[] = $variation_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_array( $variation ) && ! empty( $variation ) ) {
|
|
|
|
$variation_key = '';
|
|
|
|
foreach ( $variation as $key => $value ) {
|
|
|
|
$variation_key .= trim( $key ) . trim( $value );
|
|
|
|
}
|
|
|
|
$id_parts[] = $variation_key;
|
|
|
|
}
|
2014-10-24 13:37:09 +00:00
|
|
|
|
2014-10-24 13:43:26 +00:00
|
|
|
if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
|
|
|
|
$cart_item_data_key = '';
|
|
|
|
foreach ( $cart_item_data as $key => $value ) {
|
|
|
|
|
|
|
|
if ( is_array( $value ) ) {
|
|
|
|
$value = http_build_query( $value );
|
|
|
|
}
|
|
|
|
$cart_item_data_key .= trim( $key ) . trim( $value );
|
|
|
|
|
|
|
|
}
|
|
|
|
$id_parts[] = $cart_item_data_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$manual_cart_id = md5( implode( '_', $id_parts ) );
|
|
|
|
|
|
|
|
$this->assertEquals( $manual_cart_id, WC()->cart->generate_cart_id( $product_id, $variation_id, array( 'Testing' => 'yup' ), $cart_item_data ) );
|
|
|
|
|
|
|
|
}
|
2014-10-24 13:37:09 +00:00
|
|
|
|
2014-10-24 15:04:10 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test the set_quantity method.
|
2014-10-24 15:04:10 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_set_quantity() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 15:04:10 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add 1 product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-24 15:04:10 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Get cart id.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
$cart_id = WC()->cart->generate_cart_id( $product->get_id() );
|
2014-10-24 15:04:10 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Set quantity of product in cart to 2.
|
2017-08-10 10:38:09 +00:00
|
|
|
$this->assertTrue( WC()->cart->set_quantity( $cart_id, 2 ), $cart_id );
|
2014-10-24 15:04:10 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check if there are 2 items in cart now.
|
2014-10-24 15:04:10 +00:00
|
|
|
$this->assertEquals( 2, WC()->cart->get_cart_contents_count() );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Set quantity of product in cart to 0.
|
2014-10-24 15:04:10 +00:00
|
|
|
$this->assertTrue( WC()->cart->set_quantity( $cart_id, 0 ) );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check if there are 0 items in cart now.
|
2014-10-24 15:04:10 +00:00
|
|
|
$this->assertEquals( 0, WC()->cart->get_cart_contents_count() );
|
|
|
|
}
|
|
|
|
|
2014-10-24 19:26:38 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test check_cart_item_validity method.
|
2014-10-24 19:26:38 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_check_cart_item_validity() {
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 19:26:38 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-24 19:26:38 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Check cart validity, should pass.
|
2014-10-24 19:26:38 +00:00
|
|
|
$this->assertTrue( WC()->cart->check_cart_item_validity() );
|
|
|
|
}
|
|
|
|
|
2014-10-24 20:34:10 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_total.
|
2014-10-24 20:34:10 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_get_total() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-24 20:34:10 +00:00
|
|
|
|
|
|
|
$this->assertEquals( apply_filters( 'woocommerce_cart_total', wc_price( WC()->cart->total ) ), WC()->cart->get_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_total_ex_tax.
|
2014-10-24 20:34:10 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_get_total_ex_tax() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => array( // Tax exempt customer.
|
|
|
|
'total' => 20,
|
|
|
|
'total_ex_tax' => 20,
|
|
|
|
),
|
|
|
|
0 => array( // Normal customer.
|
|
|
|
'total' => 22,
|
|
|
|
'total_ex_tax' => 20,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2017-11-08 13:54:33 +00:00
|
|
|
// Set calc taxes option.
|
2014-10-24 20:34:10 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
2017-11-08 13:54:33 +00:00
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
2014-10-24 20:34:10 +00:00
|
|
|
|
2017-11-08 13:54:33 +00:00
|
|
|
// Create dummy product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2014-10-24 20:34:10 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $values ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2014-10-24 20:34:10 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Add 10 fee.
|
|
|
|
WC_Helper_Fee::add_cart_fee( 'taxed' );
|
2014-10-24 20:34:10 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Add product to cart (10).
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Check.
|
|
|
|
$this->assertEquals( wc_price( $values['total'] ), WC()->cart->get_total() );
|
|
|
|
$this->assertEquals( wc_price( $values['total_ex_tax'] ), WC()->cart->get_total_ex_tax() );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2014-10-24 20:34:10 +00:00
|
|
|
}
|
2014-10-24 19:26:38 +00:00
|
|
|
|
2014-10-27 12:30:50 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test needs_shipping_address method.
|
2014-10-27 12:30:50 +00:00
|
|
|
*/
|
|
|
|
public function test_needs_shipping_address() {
|
|
|
|
$needs_shipping_address = false;
|
|
|
|
|
2015-10-28 18:09:53 +00:00
|
|
|
if ( WC()->cart->needs_shipping() === true && ! wc_ship_to_billing_address_only() ) {
|
2014-10-27 12:30:50 +00:00
|
|
|
$needs_shipping_address = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals( apply_filters( 'woocommerce_cart_needs_shipping_address', $needs_shipping_address ), WC()->cart->needs_shipping_address() );
|
|
|
|
}
|
2014-10-28 10:52:44 +00:00
|
|
|
|
2014-10-30 19:58:19 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test shipping total.
|
2014-10-30 19:58:19 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_shipping_total() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create product.
|
2016-03-23 12:14:13 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_regular_price( 10 );
|
|
|
|
$product->save();
|
2014-10-30 19:58:19 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create a flat rate method.
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Shipping::create_simple_flat_rate();
|
2014-10-30 19:58:19 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-30 19:58:19 +00:00
|
|
|
|
2019-12-06 16:48:13 +00:00
|
|
|
// Set an address so that shipping can be calculated.
|
2020-06-23 13:10:27 +00:00
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
2019-12-06 16:48:13 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Set the flat_rate shipping method.
|
2014-10-30 19:58:19 +00:00
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Test if the shipping total amount is equal 20.
|
2014-10-30 19:58:19 +00:00
|
|
|
$this->assertEquals( 10, WC()->cart->shipping_total );
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Test if the cart total amount is equal 20.
|
2014-10-30 19:58:19 +00:00
|
|
|
$this->assertEquals( 20, WC()->cart->total );
|
|
|
|
}
|
|
|
|
|
2020-06-23 13:10:27 +00:00
|
|
|
/**
|
|
|
|
* Test that shipping tax rounding does not round down when price are inclusive of taxes.
|
|
|
|
*/
|
|
|
|
public function test_calculate_totals_shipping_tax_rounded_26654() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
|
|
|
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '25.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_regular_price( 0 );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
WC_Helper_Shipping::create_simple_flat_rate( 75.10 );
|
|
|
|
WC_Helper_Shipping::force_customer_us_address();
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
|
|
|
|
// Set the flat_rate shipping method.
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
|
|
|
$this->assertEquals( 18.78, WC()->cart->get_taxes_total() );
|
|
|
|
|
|
|
|
$this->assertEquals( 93.88, WC()->cart->total );
|
|
|
|
}
|
|
|
|
|
2014-10-30 18:08:33 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test cart fee.
|
2014-10-30 18:08:33 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
public function test_cart_fee() {
|
2017-08-22 20:26:55 +00:00
|
|
|
// Create product.
|
2016-05-26 12:03:40 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_regular_price( 10 );
|
|
|
|
$product->save();
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Add fee.
|
2016-03-23 12:14:13 +00:00
|
|
|
WC_Helper_Fee::add_cart_fee();
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Add product to cart.
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Test if the cart total amount is equal 20.
|
2014-10-30 18:08:33 +00:00
|
|
|
$this->assertEquals( 20, WC()->cart->total );
|
2017-08-22 20:26:55 +00:00
|
|
|
}
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
/**
|
|
|
|
* Test cart fee with taxes.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_cart_fee_taxes() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => 20, // Tax exempt customer.
|
|
|
|
0 => 22, // Normal customer.
|
|
|
|
);
|
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Set up taxes.
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_regular_price( 10 );
|
|
|
|
$product->save();
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $value ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Add fee.
|
|
|
|
WC_Helper_Fee::add_cart_fee( 'taxed' );
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Add product to cart.
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test if the cart total amount is equal 22 ($10 item + $10 fee + 10% taxes).
|
|
|
|
$this->assertEquals( $value, WC()->cart->total );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-08-22 20:26:55 +00:00
|
|
|
}
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
/**
|
|
|
|
* Test negative cart fee.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_cart_negative_fee() {
|
|
|
|
// Create product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_regular_price( 15 );
|
|
|
|
$product->save();
|
2014-10-30 18:08:33 +00:00
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Add fee.
|
|
|
|
WC_Helper_Fee::add_cart_fee( 'negative' );
|
|
|
|
|
|
|
|
// Add product to cart.
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Test if the cart total amount is equal 5.
|
|
|
|
$this->assertEquals( 5, WC()->cart->total );
|
2014-10-30 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
/**
|
|
|
|
* Test negative cart fee with taxes.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_cart_negative_fee_taxes() {
|
2018-09-06 15:41:24 +00:00
|
|
|
$expected_values = array(
|
|
|
|
1 => 5.00, // Tax exempt customer.
|
|
|
|
0 => 5.50, // Normal customer: cart total amount is equal 5.50 ($15 item - $10 negative fee + 10% tax).
|
|
|
|
);
|
|
|
|
|
2017-08-22 20:26:55 +00:00
|
|
|
// Set up taxes.
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
2018-06-13 15:30:42 +00:00
|
|
|
$product->set_regular_price( 15 );
|
|
|
|
$product->save();
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
foreach ( $expected_values as $customer_tax_exempt => $value ) {
|
|
|
|
WC()->customer->set_is_vat_exempt( $customer_tax_exempt );
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Add fee.
|
|
|
|
WC_Helper_Fee::add_cart_fee( 'negative-taxed' );
|
|
|
|
|
|
|
|
// Add product to cart.
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
2017-08-22 20:26:55 +00:00
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
// Test if the cart total amount is correct.
|
|
|
|
$this->assertEquals( $value, WC()->cart->total );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
}
|
2017-08-22 20:26:55 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 13:28:52 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test cart coupons.
|
2014-11-11 13:28:52 +00:00
|
|
|
*/
|
|
|
|
public function test_get_coupons() {
|
2019-04-17 15:41:04 +00:00
|
|
|
// Create coupon.
|
2016-03-23 12:14:13 +00:00
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
2014-11-11 13:28:52 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
// Add coupon.
|
2016-02-23 16:01:40 +00:00
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
2014-11-11 13:28:52 +00:00
|
|
|
|
|
|
|
$this->assertEquals( count( WC()->cart->get_coupons() ), 1 );
|
|
|
|
}
|
2017-03-07 19:31:20 +00:00
|
|
|
|
2017-06-29 21:05:38 +00:00
|
|
|
/**
|
|
|
|
* Test add_discount allows coupons by code but not by ID.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_add_discount_code_id() {
|
|
|
|
|
2018-03-13 18:41:25 +00:00
|
|
|
$coupon = new WC_Coupon();
|
2017-06-29 21:05:38 +00:00
|
|
|
$coupon->set_code( 'test' );
|
|
|
|
$coupon->set_amount( 100 );
|
|
|
|
$coupon->save();
|
|
|
|
|
|
|
|
$success = WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
$this->assertTrue( $success );
|
|
|
|
|
|
|
|
$success = WC()->cart->add_discount( (string) $coupon->get_id() );
|
|
|
|
$this->assertFalse( $success );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_add_invidual_use_coupon.
|
|
|
|
*/
|
2017-03-07 19:58:02 +00:00
|
|
|
public function test_add_invidual_use_coupon() {
|
|
|
|
$iu_coupon = WC_Helper_Coupon::create_coupon( 'code1' );
|
|
|
|
$iu_coupon->set_individual_use( true );
|
|
|
|
$iu_coupon->save();
|
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
|
|
|
|
|
|
|
WC()->cart->add_discount( $iu_coupon->get_code() );
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
|
|
|
|
$coupons = WC()->cart->get_coupons();
|
|
|
|
|
|
|
|
$this->assertEquals( count( $coupons ), 1 );
|
|
|
|
$this->assertEquals( 'code1', reset( $coupons )->get_code() );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_add_individual_use_coupon_removal.
|
|
|
|
*/
|
2017-03-07 19:58:02 +00:00
|
|
|
public function test_add_individual_use_coupon_removal() {
|
2019-05-01 22:05:00 +00:00
|
|
|
$coupon = WC_Helper_Coupon::create_coupon();
|
2017-03-07 19:58:02 +00:00
|
|
|
$iu_coupon = WC_Helper_Coupon::create_coupon( 'code1' );
|
|
|
|
$iu_coupon->set_individual_use( true );
|
|
|
|
$iu_coupon->save();
|
|
|
|
|
|
|
|
WC()->cart->add_discount( $coupon->get_code() );
|
|
|
|
WC()->cart->add_discount( $iu_coupon->get_code() );
|
|
|
|
|
|
|
|
$coupons = WC()->cart->get_coupons();
|
|
|
|
|
|
|
|
$this->assertEquals( count( $coupons ), 1 );
|
|
|
|
$this->assertEquals( 'code1', reset( $coupons )->get_code() );
|
|
|
|
$this->assertEquals( 1, did_action( 'woocommerce_removed_coupon' ) );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_add_individual_use_coupon_double_individual.
|
|
|
|
*/
|
2017-03-07 19:58:02 +00:00
|
|
|
public function test_add_individual_use_coupon_double_individual() {
|
2017-03-07 19:31:20 +00:00
|
|
|
$iu_coupon1 = WC_Helper_Coupon::create_coupon( 'code1' );
|
|
|
|
$iu_coupon1->set_individual_use( true );
|
|
|
|
$iu_coupon1->save();
|
|
|
|
|
|
|
|
$iu_coupon2 = WC_Helper_Coupon::create_coupon( 'code2' );
|
|
|
|
$iu_coupon2->set_individual_use( true );
|
|
|
|
$iu_coupon2->save();
|
|
|
|
|
|
|
|
WC()->cart->add_discount( $iu_coupon1->get_code() );
|
|
|
|
WC()->cart->add_discount( $iu_coupon2->get_code() );
|
|
|
|
|
|
|
|
$coupons = WC()->cart->get_coupons();
|
|
|
|
|
|
|
|
$this->assertEquals( count( $coupons ), 1 );
|
2017-03-07 21:17:36 +00:00
|
|
|
$this->assertEquals( 'code2', reset( $coupons )->get_code() );
|
2017-03-07 19:31:20 +00:00
|
|
|
}
|
2017-11-10 12:03:14 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_clone_cart.
|
|
|
|
*/
|
2017-11-10 12:03:14 +00:00
|
|
|
public function test_clone_cart() {
|
|
|
|
$cart = wc()->cart;
|
|
|
|
$new_cart = clone $cart;
|
|
|
|
$is_identical_cart = $cart === $new_cart;
|
|
|
|
|
|
|
|
// Cloned carts should not be identical.
|
|
|
|
$this->assertFalse( $is_identical_cart, 'Cloned cart not identical to original cart' );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_cloned_cart_session.
|
|
|
|
*/
|
2017-11-10 12:03:14 +00:00
|
|
|
public function test_cloned_cart_session() {
|
|
|
|
$cart = wc()->cart;
|
|
|
|
$new_cart = clone $cart;
|
|
|
|
|
|
|
|
// Allow accessing protected properties.
|
|
|
|
$reflected_cart = new ReflectionClass( $cart );
|
|
|
|
$cart_session = $reflected_cart->getProperty( 'session' );
|
|
|
|
$cart_session->setAccessible( true );
|
|
|
|
$reflected_new_cart = new ReflectionClass( $new_cart );
|
|
|
|
$new_cart_session = $reflected_new_cart->getProperty( 'session' );
|
|
|
|
$new_cart_session->setAccessible( true );
|
|
|
|
|
|
|
|
// Ensure that cloned properties are not identical.
|
|
|
|
$identical_sessions = $cart_session->getValue( $cart ) === $new_cart_session->getValue( $new_cart );
|
|
|
|
$this->assertFalse( $identical_sessions, 'Cloned cart sessions should not be identical to original cart' );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_cloned_cart_fees.
|
|
|
|
*/
|
2017-11-10 12:03:14 +00:00
|
|
|
public function test_cloned_cart_fees() {
|
|
|
|
$cart = wc()->cart;
|
|
|
|
$new_cart = clone $cart;
|
|
|
|
|
|
|
|
// Get the properties from each object.
|
2019-05-01 22:05:00 +00:00
|
|
|
$cart_fees = $cart->fees_api();
|
2017-11-10 12:03:14 +00:00
|
|
|
$new_cart_fees = $new_cart->fees_api();
|
|
|
|
|
|
|
|
// Ensure that cloned properties are not identical.
|
|
|
|
$identical_fees = $cart_fees === $new_cart_fees;
|
|
|
|
$this->assertFalse( $identical_fees, 'Cloned cart fees should not be identical to original cart.' );
|
|
|
|
}
|
2017-12-14 10:45:00 +00:00
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_cart_object_istantiation.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_cart_object_istantiation() {
|
|
|
|
$cart = new WC_Cart();
|
|
|
|
$this->assertInstanceOf( 'WC_Cart', $cart );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_get_cart_item_quantities.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_get_cart_item_quantities() {
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
$this->assertEquals( 1, array_sum( WC()->cart->get_cart_item_quantities() ) );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_get_cart_contents_weight.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_get_cart_contents_weight() {
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
$this->assertEquals( 1.1, WC()->cart->get_cart_contents_weight() );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_check_cart_items.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_check_cart_items() {
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
$this->assertEquals( true, WC()->cart->check_cart_items() );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_check_cart_item_stock.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_check_cart_item_stock() {
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
$this->assertEquals( true, WC()->cart->check_cart_item_stock() );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_get_cross_sells.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_get_cross_sells() {
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
$this->assertEquals( array(), WC()->cart->get_cross_sells() );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* test_get_tax_totals.
|
|
|
|
*/
|
2017-12-14 10:45:00 +00:00
|
|
|
public function test_get_tax_totals() {
|
|
|
|
// Set calc taxes option.
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create dummy product.
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
|
2018-09-06 15:41:24 +00:00
|
|
|
WC()->customer->set_is_vat_exempt( false );
|
|
|
|
|
2017-12-14 10:45:00 +00:00
|
|
|
// Add product to cart (10).
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Check.
|
|
|
|
$tax_totals = WC()->cart->get_tax_totals();
|
|
|
|
$this->assertArrayHasKey( 'TAX-1', $tax_totals );
|
|
|
|
$this->assertEquals( 1, $tax_totals['TAX-1']->amount );
|
|
|
|
$this->assertEquals( false, $tax_totals['TAX-1']->is_compound );
|
|
|
|
$this->assertEquals( 'TAX', $tax_totals['TAX-1']->label );
|
2018-09-06 15:41:24 +00:00
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
|
|
|
|
// Test the same for tax exempt customer.
|
|
|
|
WC()->customer->set_is_vat_exempt( true );
|
|
|
|
|
|
|
|
// Add product to cart (10).
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
|
|
|
|
// Check.
|
|
|
|
$tax_totals = WC()->cart->get_tax_totals();
|
|
|
|
$this->assertEquals( array(), $tax_totals );
|
2017-12-14 10:45:00 +00:00
|
|
|
}
|
2018-03-13 06:03:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test is_coupon_emails_allowed function on the cart, specifically test wildcard emails.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_is_coupon_emails_allowed() {
|
|
|
|
$this->assertEquals( true, WC()->cart->is_coupon_emails_allowed( array( 'customer@wc.local' ), array( '*.local' ) ) );
|
|
|
|
$this->assertEquals( false, WC()->cart->is_coupon_emails_allowed( array( 'customer@wc.local' ), array( '*.test' ) ) );
|
|
|
|
$this->assertEquals( true, WC()->cart->is_coupon_emails_allowed( array( 'customer@wc.local' ), array( 'customer@wc.local' ) ) );
|
|
|
|
$this->assertEquals( false, WC()->cart->is_coupon_emails_allowed( array( 'customer@wc.local' ), array( 'customer2@wc.local' ) ) );
|
|
|
|
}
|
2019-04-17 15:41:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check subtotals align when using filters. Ref: 23340
|
|
|
|
*/
|
|
|
|
public function test_changing_tax_class_via_filter_issue_23340() {
|
|
|
|
// Store is set to enter product prices inclusive tax.
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
|
|
|
// 5% tax.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '5.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// 20% tax.
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'VAT',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => 'reduced-rate',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
// Create products and add them to cart.
|
|
|
|
$product1 = new WC_Product_Simple();
|
|
|
|
$product1->set_regular_price( '6' );
|
|
|
|
$product1->save();
|
|
|
|
|
|
|
|
WC()->cart->add_to_cart( $product1->get_id(), 1 );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
|
|
|
|
$this->assertEquals( '5.71', WC()->cart->get_subtotal() );
|
2019-07-19 01:42:31 +00:00
|
|
|
$this->assertEquals( '6.00', WC()->cart->get_total( 'edit' ) );
|
2019-04-17 15:41:04 +00:00
|
|
|
|
|
|
|
add_filter( 'woocommerce_product_get_tax_class', array( $this, 'change_tax_class_filter' ) );
|
|
|
|
add_filter( 'woocommerce_product_variation_get_tax_class', array( $this, 'change_tax_class_filter' ) );
|
|
|
|
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
$this->assertEquals( '5.71', WC()->cart->get_subtotal() );
|
|
|
|
$this->assertEquals( '6.85', WC()->cart->get_total( 'edit' ) );
|
|
|
|
|
|
|
|
remove_filter( 'woocommerce_product_get_tax_class', array( $this, 'change_tax_class_filter' ) );
|
|
|
|
remove_filter( 'woocommerce_product_variation_get_tax_class', array( $this, 'change_tax_class_filter' ) );
|
|
|
|
}
|
|
|
|
|
2020-03-03 13:16:37 +00:00
|
|
|
/**
|
|
|
|
* Test rounding with fees as described in Github issue 25629.
|
|
|
|
*/
|
|
|
|
public function test_rounding_with_fees_25629() {
|
|
|
|
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
|
|
|
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX10',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$product->set_regular_price( 71.50 );
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
WC_Helper_Coupon::create_coupon(
|
|
|
|
'3percent',
|
|
|
|
array(
|
|
|
|
'discount_type' => 'percent',
|
|
|
|
'coupon_amount' => 3,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_fee_1_5_to_cart' ) );
|
|
|
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
|
|
|
WC()->cart->apply_coupon( '3percent' );
|
|
|
|
WC()->cart->calculate_totals();
|
|
|
|
remove_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_fee_1_5_to_cart' ) );
|
|
|
|
|
|
|
|
$this->assertEquals( 70.86, WC()->cart->get_total( 'edit' ) );
|
|
|
|
}
|
|
|
|
|
2020-04-21 22:43:15 +00:00
|
|
|
/**
|
|
|
|
* Test that adding a variation with URL parameter increases the quantity appropriately
|
|
|
|
* as described in issue 24000.
|
|
|
|
*/
|
2020-04-24 19:20:21 +00:00
|
|
|
public function test_add_variation_by_url() {
|
2020-04-21 22:43:15 +00:00
|
|
|
add_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
update_option( 'woocommerce_cart_redirect_after_add', 'no' );
|
|
|
|
WC()->cart->empty_cart();
|
2020-04-24 19:21:03 +00:00
|
|
|
WC()->session->set( 'wc_notices', null );
|
2020-04-21 22:43:15 +00:00
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_variation_product();
|
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
$variation = array_pop( $variations );
|
|
|
|
|
|
|
|
// Add variation with add_to_cart_action.
|
|
|
|
$_REQUEST['add-to-cart'] = $variation['variation_id'];
|
|
|
|
WC_Form_Handler::add_to_cart_action( false );
|
|
|
|
$notices = WC()->session->get( 'wc_notices', array() );
|
|
|
|
|
|
|
|
// Reset filter / REQUEST variables.
|
|
|
|
unset( $_REQUEST['add-to-cart'] );
|
|
|
|
remove_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
|
|
|
|
// Check if the item is in the cart.
|
2020-04-24 18:54:12 +00:00
|
|
|
$this->assertCount( 1, WC()->cart->get_cart_contents() );
|
2020-04-21 22:43:15 +00:00
|
|
|
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
|
|
|
|
2020-04-24 19:02:14 +00:00
|
|
|
// Check that there are no error notices.
|
|
|
|
$this->assertArrayNotHasKey( 'error', $notices );
|
|
|
|
|
2020-04-21 22:43:15 +00:00
|
|
|
// Add variation using parent id.
|
|
|
|
WC()->cart->add_to_cart(
|
|
|
|
$product->get_id(),
|
|
|
|
1,
|
|
|
|
$variation['variation_id'],
|
|
|
|
array(
|
|
|
|
'attribute_pa_size' => 'huge',
|
2020-04-21 23:03:21 +00:00
|
|
|
'attribute_pa_colour' => 'red',
|
2020-04-21 22:43:15 +00:00
|
|
|
'attribute_pa_number' => '2',
|
|
|
|
)
|
|
|
|
);
|
2020-04-24 19:02:14 +00:00
|
|
|
$notices = WC()->session->get( 'wc_notices', array() );
|
2020-04-21 22:43:15 +00:00
|
|
|
|
|
|
|
// Check that the second add to cart call increases the quantity of the existing cart-item.
|
2020-04-24 18:54:12 +00:00
|
|
|
$this->assertCount( 1, WC()->cart->get_cart_contents() );
|
2020-04-21 22:43:15 +00:00
|
|
|
$this->assertEquals( 2, WC()->cart->get_cart_contents_count() );
|
2020-04-24 19:02:14 +00:00
|
|
|
|
|
|
|
// Check that there are no error notices.
|
|
|
|
$this->assertArrayNotHasKey( 'error', $notices );
|
2020-04-21 22:43:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 18:52:16 +00:00
|
|
|
/**
|
|
|
|
* Test that adding a variation via URL parameter fails when specifying a value for the attribute
|
|
|
|
* that differs from a value belonging to that variant.
|
|
|
|
*/
|
2020-04-24 19:20:21 +00:00
|
|
|
public function test_add_variation_by_url_with_invalid_attribute() {
|
2020-04-24 18:52:16 +00:00
|
|
|
add_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
update_option( 'woocommerce_cart_redirect_after_add', 'no' );
|
|
|
|
WC()->cart->empty_cart();
|
2020-04-24 19:21:03 +00:00
|
|
|
WC()->session->set( 'wc_notices', null );
|
2020-04-24 18:52:16 +00:00
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_variation_product();
|
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
$variation = array_pop( $variations );
|
|
|
|
|
|
|
|
// Attempt adding variation with add_to_cart_action, specifying a different colour.
|
|
|
|
$_REQUEST['add-to-cart'] = $variation['variation_id'];
|
|
|
|
$_REQUEST['attribute_pa_colour'] = 'green';
|
|
|
|
WC_Form_Handler::add_to_cart_action( false );
|
|
|
|
$notices = WC()->session->get( 'wc_notices', array() );
|
|
|
|
|
|
|
|
// Reset filter / REQUEST variables.
|
|
|
|
unset( $_REQUEST['add-to-cart'] );
|
|
|
|
unset( $_REQUEST['attribute_pa_colour'] );
|
|
|
|
remove_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
|
|
|
|
// Check that the notices contain an error message about an invalid colour.
|
|
|
|
$this->assertArrayHasKey( 'error', $notices );
|
|
|
|
$this->assertCount( 1, $notices['error'] );
|
|
|
|
$this->assertEquals( 'Invalid value posted for colour', $notices['error'][0]['notice'] );
|
|
|
|
}
|
|
|
|
|
2020-04-24 19:20:21 +00:00
|
|
|
/**
|
|
|
|
* Test that adding a variation via URL parameter succeeds when some attributes belong to the
|
|
|
|
* variation and others are specificed via URL parameter.
|
|
|
|
*/
|
|
|
|
public function test_add_variation_by_url_with_valid_attribute() {
|
|
|
|
add_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
update_option( 'woocommerce_cart_redirect_after_add', 'no' );
|
|
|
|
WC()->cart->empty_cart();
|
2020-04-24 19:21:03 +00:00
|
|
|
WC()->session->set( 'wc_notices', null );
|
2020-04-24 19:20:21 +00:00
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_variation_product();
|
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
$variation = array_shift( $variations );
|
|
|
|
|
|
|
|
// Attempt adding variation with add_to_cart_action, specifying attributes not defined in the variation.
|
|
|
|
$_REQUEST['add-to-cart'] = $variation['variation_id'];
|
|
|
|
$_REQUEST['attribute_pa_colour'] = 'red';
|
|
|
|
$_REQUEST['attribute_pa_number'] = '1';
|
|
|
|
WC_Form_Handler::add_to_cart_action( false );
|
|
|
|
$notices = WC()->session->get( 'wc_notices', array() );
|
|
|
|
|
2020-04-24 19:22:48 +00:00
|
|
|
// Reset filter / REQUEST variables.
|
|
|
|
unset( $_REQUEST['add-to-cart'] );
|
|
|
|
unset( $_REQUEST['attribute_pa_colour'] );
|
|
|
|
unset( $_REQUEST['attribute_pa_number'] );
|
|
|
|
remove_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
|
2020-04-24 19:20:21 +00:00
|
|
|
// Check if the item is in the cart.
|
|
|
|
$this->assertCount( 1, WC()->cart->get_cart_contents() );
|
|
|
|
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
|
|
|
|
|
|
|
// Check that there are no error notices.
|
|
|
|
$this->assertArrayNotHasKey( 'error', $notices );
|
|
|
|
}
|
|
|
|
|
2020-05-05 19:16:01 +00:00
|
|
|
/**
|
|
|
|
* Test that adding a varition via URL parameter fails when an 'any' attribute is missing.
|
|
|
|
*/
|
|
|
|
public function test_add_variation_by_url_fails_with_missing_any_attribute() {
|
|
|
|
add_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
update_option( 'woocommerce_cart_redirect_after_add', 'no' );
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
WC()->session->set( 'wc_notices', null );
|
|
|
|
|
|
|
|
$product = WC_Helper_Product::create_variation_product();
|
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
$variation = array_shift( $variations );
|
|
|
|
|
|
|
|
// Attempt adding variation with add_to_cart_action, without specifying attribute_pa_colour.
|
|
|
|
$_REQUEST['add-to-cart'] = $variation['variation_id'];
|
|
|
|
$_REQUEST['attribute_pa_number'] = '0';
|
|
|
|
WC_Form_Handler::add_to_cart_action( false );
|
|
|
|
$notices = WC()->session->get( 'wc_notices', array() );
|
|
|
|
|
|
|
|
// Reset filter / REQUEST variables.
|
|
|
|
unset( $_REQUEST['add-to-cart'] );
|
|
|
|
unset( $_REQUEST['attribute_pa_number'] );
|
|
|
|
remove_filter( 'woocommerce_add_to_cart_redirect', '__return_false' );
|
|
|
|
|
|
|
|
// Verify that there is nothing in the cart.
|
|
|
|
$this->assertCount( 0, WC()->cart->get_cart_contents() );
|
|
|
|
$this->assertEquals( 0, WC()->cart->get_cart_contents_count() );
|
|
|
|
|
|
|
|
// Check that the notices contain an error message about an invalid colour.
|
|
|
|
$this->assertArrayHasKey( 'error', $notices );
|
|
|
|
$this->assertCount( 1, $notices['error'] );
|
|
|
|
$this->assertEquals( 'colour is a required field', $notices['error'][0]['notice'] );
|
|
|
|
}
|
|
|
|
|
2020-03-03 13:16:37 +00:00
|
|
|
/**
|
|
|
|
* Helper function. Adds 1.5 taxable fees to cart.
|
|
|
|
*/
|
|
|
|
public function add_fee_1_5_to_cart() {
|
|
|
|
WC()->cart->add_fee( 'Dummy fee', 1.5 / 1.1, true );
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:41:04 +00:00
|
|
|
/**
|
|
|
|
* Change tax class.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function change_tax_class_filter() {
|
|
|
|
return 'reduced-rate';
|
|
|
|
}
|
2014-10-24 22:33:30 +00:00
|
|
|
}
|