2016-08-12 09:39:21 +00:00
|
|
|
/*global wc_add_to_cart_variation_params */
|
2013-02-07 10:12:08 +00:00
|
|
|
/*!
|
|
|
|
* Variations Plugin
|
|
|
|
*/
|
|
|
|
;(function ( $, window, document, undefined ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
$.fn.wc_variation_form = function() {
|
2015-10-28 14:27:02 +00:00
|
|
|
var $form = this,
|
|
|
|
$single_variation = $form.find( '.single_variation' ),
|
2015-10-28 18:52:31 +00:00
|
|
|
$product = $form.closest( '.product' ),
|
2015-10-28 14:27:02 +00:00
|
|
|
$product_id = parseInt( $form.data( 'product_id' ), 10 ),
|
|
|
|
$product_variations = $form.data( 'product_variations' ),
|
|
|
|
$use_ajax = $product_variations === false,
|
|
|
|
$xhr = false,
|
|
|
|
$reset_variations = $form.find( '.reset_variations' ),
|
|
|
|
template = wp.template( 'variation-template' ),
|
|
|
|
unavailable_template = wp.template( 'unavailable-variation-template' ),
|
2015-10-28 14:59:40 +00:00
|
|
|
$single_variation_wrap = $form.find( '.single_variation_wrap' );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-12-04 13:45:47 +00:00
|
|
|
// Always visible since 2.5.0
|
|
|
|
$single_variation_wrap.show();
|
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Unbind any existing events
|
|
|
|
$form.unbind( 'check_variations update_variation_values found_variation' );
|
|
|
|
$form.find( '.reset_variations' ).unbind( 'click' );
|
|
|
|
$form.find( '.variations select' ).unbind( 'change focusin' );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Bind new events to form
|
|
|
|
$form
|
2012-12-10 13:11:05 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// On clicking the reset variation button
|
2016-02-01 12:16:17 +00:00
|
|
|
.on( 'click', '.reset_variations', function( event ) {
|
|
|
|
event.preventDefault();
|
2015-07-09 14:56:20 +00:00
|
|
|
$form.find( '.variations select' ).val( '' ).change();
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_data' );
|
2015-07-09 14:56:20 +00:00
|
|
|
} )
|
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// When the variation is hidden
|
2016-02-01 12:16:17 +00:00
|
|
|
.on( 'hide_variation', function( event ) {
|
|
|
|
event.preventDefault();
|
2016-02-08 16:21:02 +00:00
|
|
|
$form.find( '.single_add_to_cart_button' ).removeClass( 'wc-variation-is-unavailable' ).addClass( 'disabled wc-variation-selection-needed' );
|
2016-05-19 10:17:34 +00:00
|
|
|
$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-enabled' ).addClass( 'woocommerce-variation-add-to-cart-disabled' );
|
2015-10-28 13:04:28 +00:00
|
|
|
} )
|
|
|
|
|
|
|
|
// When the variation is revealed
|
|
|
|
.on( 'show_variation', function( event, variation, purchasable ) {
|
2016-02-01 12:16:17 +00:00
|
|
|
event.preventDefault();
|
2015-10-28 13:04:28 +00:00
|
|
|
if ( purchasable ) {
|
2016-02-08 16:21:02 +00:00
|
|
|
$form.find( '.single_add_to_cart_button' ).removeClass( 'disabled wc-variation-selection-needed wc-variation-is-unavailable' );
|
2016-05-19 10:17:34 +00:00
|
|
|
$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-disabled' ).addClass( 'woocommerce-variation-add-to-cart-enabled' );
|
2015-10-28 13:04:28 +00:00
|
|
|
} else {
|
2016-02-08 16:21:02 +00:00
|
|
|
$form.find( '.single_add_to_cart_button' ).removeClass( 'wc-variation-selection-needed' ).addClass( 'disabled wc-variation-is-unavailable' );
|
2016-05-19 10:17:34 +00:00
|
|
|
$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-enabled' ).addClass( 'woocommerce-variation-add-to-cart-disabled' );
|
2016-02-08 16:21:02 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
|
|
|
|
.on( 'click', '.single_add_to_cart_button', function( event ) {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
if ( $this.is('.disabled') ) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ( $this.is('.wc-variation-is-unavailable') ) {
|
|
|
|
window.alert( wc_add_to_cart_variation_params.i18n_unavailable_text );
|
|
|
|
} else if ( $this.is('.wc-variation-selection-needed') ) {
|
|
|
|
window.alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text );
|
|
|
|
}
|
2015-10-28 13:04:28 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
|
2015-07-28 12:34:04 +00:00
|
|
|
// Reload product variations data
|
|
|
|
.on( 'reload_product_variations', function() {
|
|
|
|
$product_variations = $form.data( 'product_variations' );
|
|
|
|
$use_ajax = $product_variations === false;
|
|
|
|
} )
|
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Reset product data
|
2015-07-10 10:37:05 +00:00
|
|
|
.on( 'reset_data', function() {
|
2016-05-11 17:25:56 +00:00
|
|
|
$product.find( '.product_meta' ).find( '.sku' ).wc_reset_content();
|
2015-10-28 13:04:28 +00:00
|
|
|
$('.product_weight').wc_reset_content();
|
|
|
|
$('.product_dimensions').wc_reset_content();
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_image' );
|
2015-10-28 13:53:51 +00:00
|
|
|
$single_variation.slideUp( 200 ).trigger( 'hide_variation' );
|
2015-07-09 14:56:20 +00:00
|
|
|
} )
|
|
|
|
|
|
|
|
// Reset product image
|
2015-07-10 10:37:05 +00:00
|
|
|
.on( 'reset_image', function() {
|
2015-10-28 13:53:51 +00:00
|
|
|
$form.wc_variations_image_update( false );
|
2015-07-09 14:56:20 +00:00
|
|
|
} )
|
2015-05-14 17:56:26 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// On changing an attribute
|
2015-07-10 10:37:05 +00:00
|
|
|
.on( 'change', '.variations select', function() {
|
2015-07-09 14:56:20 +00:00
|
|
|
$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change();
|
|
|
|
$form.find( '.wc-no-matching-variations' ).remove();
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( $use_ajax ) {
|
|
|
|
if ( $xhr ) {
|
|
|
|
$xhr.abort();
|
2015-07-10 05:13:30 +00:00
|
|
|
}
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
var all_attributes_chosen = true;
|
|
|
|
var some_attributes_chosen = false;
|
|
|
|
var data = {};
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
$form.find( '.variations select' ).each( function() {
|
|
|
|
var attribute_name = $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' );
|
2016-07-22 11:42:21 +00:00
|
|
|
var value = $( this ).val() || '';
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2016-07-22 11:42:21 +00:00
|
|
|
if ( value.length === 0 ) {
|
2015-07-09 14:56:20 +00:00
|
|
|
all_attributes_chosen = false;
|
|
|
|
} else {
|
|
|
|
some_attributes_chosen = true;
|
|
|
|
}
|
2014-10-20 08:59:01 +00:00
|
|
|
|
2016-07-22 11:42:21 +00:00
|
|
|
data[ attribute_name ] = value;
|
2015-07-09 14:56:20 +00:00
|
|
|
});
|
2015-07-10 05:13:30 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( all_attributes_chosen ) {
|
|
|
|
// Get a matchihng variation via ajax
|
2016-07-07 08:16:46 +00:00
|
|
|
data.product_id = $product_id;
|
|
|
|
data.custom_data = $form.data( 'custom_data' );
|
2015-07-09 14:56:20 +00:00
|
|
|
|
2016-07-07 08:07:20 +00:00
|
|
|
$form.block( {
|
2016-06-06 13:37:49 +00:00
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
2016-07-07 08:07:20 +00:00
|
|
|
} );
|
2016-06-06 13:37:49 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
$xhr = $.ajax( {
|
2016-08-11 00:17:43 +00:00
|
|
|
url: wc_add_to_cart_variation_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_variation' ),
|
2015-07-09 14:56:20 +00:00
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
success: function( variation ) {
|
|
|
|
if ( variation ) {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'found_variation', [ variation ] );
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_data' );
|
2015-10-28 13:53:51 +00:00
|
|
|
$form.find( '.single_variation' ).after( '<p class="wc-no-matching-variations woocommerce-info">' + wc_add_to_cart_variation_params.i18n_no_matching_variations_text + '</p>' );
|
2015-07-09 14:56:20 +00:00
|
|
|
$form.find( '.wc-no-matching-variations' ).slideDown( 200 );
|
|
|
|
}
|
2016-06-06 13:37:49 +00:00
|
|
|
},
|
|
|
|
complete: function() {
|
2016-07-07 08:07:20 +00:00
|
|
|
$form.unblock();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} else {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_data' );
|
2015-05-14 17:56:26 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( some_attributes_chosen ) {
|
|
|
|
if ( $reset_variations.css( 'visibility' ) === 'hidden' ) {
|
|
|
|
$reset_variations.css( 'visibility', 'visible' ).hide().fadeIn();
|
|
|
|
}
|
2015-05-14 17:56:26 +00:00
|
|
|
} else {
|
2015-07-09 14:56:20 +00:00
|
|
|
$reset_variations.css( 'visibility', 'hidden' );
|
2015-05-14 17:56:26 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'woocommerce_variation_select_change' );
|
|
|
|
$form.trigger( 'check_variations', [ '', false ] );
|
2014-03-17 05:19:58 +00:00
|
|
|
$( this ).blur();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-10-02 01:45:11 +00:00
|
|
|
// added to get around variation image flicker issue
|
2015-10-02 08:26:53 +00:00
|
|
|
$( '.product.has-default-attributes > .images' ).fadeTo( 200, 1 );
|
2015-10-27 19:24:32 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Custom event for when variation selection has been changed
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'woocommerce_variation_has_changed' );
|
2015-07-09 14:56:20 +00:00
|
|
|
} )
|
2014-12-10 21:43:26 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Upon gaining focus
|
2015-07-10 10:37:05 +00:00
|
|
|
.on( 'focusin touchstart', '.variations select', function() {
|
2016-11-17 17:53:07 +00:00
|
|
|
if ( 'ontouchstart' in window || navigator.maxTouchPoints ) {
|
|
|
|
$( this ).find( 'option:selected' ).attr( 'selected', 'selected' );
|
2015-10-27 19:59:26 +00:00
|
|
|
|
2016-11-17 17:53:07 +00:00
|
|
|
if ( ! $use_ajax ) {
|
|
|
|
$form.trigger( 'woocommerce_variation_select_focusin' );
|
|
|
|
$form.trigger( 'check_variations', [ $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' ), true ] );
|
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
|
|
|
|
// Show single variation details (price, stock, image)
|
|
|
|
.on( 'found_variation', function( event, variation ) {
|
2015-10-28 14:59:40 +00:00
|
|
|
var $sku = $product.find( '.product_meta' ).find( '.sku' ),
|
|
|
|
$weight = $product.find( '.product_weight' ),
|
|
|
|
$dimensions = $product.find( '.product_dimensions' ),
|
|
|
|
$qty = $single_variation_wrap.find( '.quantity' ),
|
|
|
|
purchasable = true;
|
2015-10-28 13:04:28 +00:00
|
|
|
|
|
|
|
// Display SKU
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( variation.sku ) {
|
2015-10-28 13:04:28 +00:00
|
|
|
$sku.wc_set_content( variation.sku );
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2015-10-28 13:04:28 +00:00
|
|
|
$sku.wc_reset_content();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-12-10 13:11:05 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Display weight
|
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
|
|
|
if ( variation.weight_html ) {
|
|
|
|
$weight.wc_set_content( variation.weight_html );
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2015-10-28 13:04:28 +00:00
|
|
|
$weight.wc_reset_content();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-12-10 13:11:05 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Display dimensions
|
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
|
|
|
if ( variation.dimensions_html ) {
|
|
|
|
$dimensions.wc_set_content( variation.dimensions_html );
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2015-10-28 13:04:28 +00:00
|
|
|
$dimensions.wc_reset_content();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Show images
|
|
|
|
$form.wc_variations_image_update( variation );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-10-28 14:59:40 +00:00
|
|
|
// Output correct templates
|
2016-01-25 20:14:45 +00:00
|
|
|
var $template_html = '';
|
2016-02-01 12:16:17 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( ! variation.variation_is_visible ) {
|
2016-02-17 15:50:38 +00:00
|
|
|
$template_html = unavailable_template();
|
2016-01-25 20:14:45 +00:00
|
|
|
// w3 total cache inline minification adds CDATA tags around our HTML (sigh)
|
|
|
|
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
|
|
|
|
$template_html = $template_html.replace( '/*]]>*/', '' );
|
|
|
|
$single_variation.html( $template_html );
|
2015-10-28 14:59:40 +00:00
|
|
|
$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change();
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2016-01-25 20:14:45 +00:00
|
|
|
$template_html = template( {
|
2015-12-04 13:31:36 +00:00
|
|
|
variation: variation
|
2016-01-25 20:14:45 +00:00
|
|
|
} );
|
|
|
|
// w3 total cache inline minification adds CDATA tags around our HTML (sigh)
|
|
|
|
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
|
|
|
|
$template_html = $template_html.replace( '/*]]>*/', '' );
|
|
|
|
$single_variation.html( $template_html );
|
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
|
|
|
$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.id ).change();
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Hide or show qty input
|
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
|
|
|
if ( variation.sold_individually ) {
|
2015-10-28 14:59:40 +00:00
|
|
|
$qty.find( 'input.qty' ).val( '1' ).attr( 'min', '1' ).attr( 'max', '' );
|
|
|
|
$qty.hide();
|
2015-07-31 11:04:55 +00:00
|
|
|
} else {
|
2015-10-28 14:59:40 +00:00
|
|
|
$qty.find( 'input.qty' ).attr( 'min', variation.min_qty ).attr( 'max', variation.max_qty );
|
|
|
|
$qty.show();
|
2015-07-31 11:04:55 +00:00
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Enable or disable the add to cart button
|
|
|
|
if ( ! variation.is_purchasable || ! variation.is_in_stock || ! variation.variation_is_visible ) {
|
|
|
|
purchasable = false;
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
// Reveal
|
2015-10-28 15:43:06 +00:00
|
|
|
if ( $.trim( $single_variation.text() ) ) {
|
|
|
|
$single_variation.slideDown( 200 ).trigger( 'show_variation', [ variation, purchasable ] );
|
|
|
|
} else {
|
|
|
|
$single_variation.show().trigger( 'show_variation', [ variation, purchasable ] );
|
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
})
|
2014-10-20 08:59:01 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Check variations
|
|
|
|
.on( 'check_variations', function( event, exclude, focus ) {
|
|
|
|
if ( $use_ajax ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-20 08:59:01 +00:00
|
|
|
|
2015-10-28 13:53:51 +00:00
|
|
|
var all_attributes_chosen = true,
|
2015-07-09 14:56:20 +00:00
|
|
|
some_attributes_chosen = false,
|
2015-10-28 13:53:51 +00:00
|
|
|
current_settings = {},
|
|
|
|
$form = $( this ),
|
|
|
|
$reset_variations = $form.find( '.reset_variations' );
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
$form.find( '.variations select' ).each( function() {
|
|
|
|
var attribute_name = $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' );
|
2016-07-22 11:42:21 +00:00
|
|
|
var value = $( this ).val() || '';
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2016-07-22 11:42:21 +00:00
|
|
|
if ( value.length === 0 ) {
|
2015-07-09 14:56:20 +00:00
|
|
|
all_attributes_chosen = false;
|
2014-03-17 05:19:58 +00:00
|
|
|
} else {
|
2015-07-09 14:56:20 +00:00
|
|
|
some_attributes_chosen = true;
|
|
|
|
}
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( exclude && attribute_name === exclude ) {
|
|
|
|
all_attributes_chosen = false;
|
|
|
|
current_settings[ attribute_name ] = '';
|
|
|
|
} else {
|
|
|
|
// Add to settings array
|
2016-07-22 11:42:21 +00:00
|
|
|
current_settings[ attribute_name ] = value;
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
});
|
2012-08-22 06:51:19 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
var matching_variations = wc_variation_form_matcher.find_matching_variations( $product_variations, current_settings );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( all_attributes_chosen ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
var variation = matching_variations.shift();
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( variation ) {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'found_variation', [ variation ] );
|
2014-03-17 05:19:58 +00:00
|
|
|
} else {
|
2015-07-09 14:56:20 +00:00
|
|
|
// Nothing found - reset fields
|
|
|
|
$form.find( '.variations select' ).val( '' );
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2015-07-10 05:13:30 +00:00
|
|
|
if ( ! focus ) {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_data' );
|
2015-07-10 05:13:30 +00:00
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-10 10:37:05 +00:00
|
|
|
window.alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text );
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'update_variation_values', [ matching_variations ] );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( ! focus ) {
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'reset_data' );
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2014-02-22 04:08:08 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( ! exclude ) {
|
2015-10-28 13:53:51 +00:00
|
|
|
$single_variation.slideUp( 200 ).trigger( 'hide_variation' );
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
|
|
|
if ( some_attributes_chosen ) {
|
|
|
|
if ( $reset_variations.css( 'visibility' ) === 'hidden' ) {
|
|
|
|
$reset_variations.css( 'visibility', 'visible' ).hide().fadeIn();
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
|
|
|
$reset_variations.css( 'visibility', 'hidden' );
|
|
|
|
}
|
|
|
|
} )
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Disable option fields that are unavaiable for current set of attributes
|
|
|
|
.on( 'update_variation_values', function( event, variations ) {
|
|
|
|
if ( $use_ajax ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Loop through selects and disable/enable options based on selections
|
|
|
|
$form.find( '.variations select' ).each( function( index, el ) {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2016-10-11 17:26:08 +00:00
|
|
|
var current_attr_name, current_attr_select = $( el ),
|
|
|
|
show_option_none = $( el ).data( 'show_option_none' ),
|
|
|
|
option_gt_filter = 'no' === show_option_none ? '' : ':gt(0)';
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Reset options
|
|
|
|
if ( ! current_attr_select.data( 'attribute_options' ) ) {
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.data( 'attribute_options', current_attr_select.find( 'option' + option_gt_filter ).get() );
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.find( 'option' + option_gt_filter ).remove();
|
2015-07-09 14:56:20 +00:00
|
|
|
current_attr_select.append( current_attr_select.data( 'attribute_options' ) );
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.find( 'option' + option_gt_filter ).removeClass( 'attached' );
|
|
|
|
current_attr_select.find( 'option' + option_gt_filter ).removeClass( 'enabled' );
|
|
|
|
current_attr_select.find( 'option' + option_gt_filter ).removeAttr( 'disabled' );
|
2014-09-26 16:22:43 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Get name from data-attribute_name, or from input name if it doesn't exist
|
2015-07-10 10:37:05 +00:00
|
|
|
if ( typeof( current_attr_select.data( 'attribute_name' ) ) !== 'undefined' ) {
|
2015-07-09 14:56:20 +00:00
|
|
|
current_attr_name = current_attr_select.data( 'attribute_name' );
|
|
|
|
} else {
|
|
|
|
current_attr_name = current_attr_select.attr( 'name' );
|
|
|
|
}
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Loop through variations
|
|
|
|
for ( var num in variations ) {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-10 10:37:05 +00:00
|
|
|
if ( typeof( variations[ num ] ) !== 'undefined' ) {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
var attributes = variations[ num ].attributes;
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
for ( var attr_name in attributes ) {
|
|
|
|
if ( attributes.hasOwnProperty( attr_name ) ) {
|
|
|
|
var attr_val = attributes[ attr_name ];
|
2013-02-01 11:49:29 +00:00
|
|
|
|
2015-07-10 10:37:05 +00:00
|
|
|
if ( attr_name === current_attr_name ) {
|
2013-02-01 11:49:29 +00:00
|
|
|
|
2015-07-10 10:37:05 +00:00
|
|
|
var variation_active = '';
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-10 10:37:05 +00:00
|
|
|
if ( variations[ num ].variation_is_active ) {
|
2015-07-09 14:56:20 +00:00
|
|
|
variation_active = 'enabled';
|
2015-07-10 10:37:05 +00:00
|
|
|
}
|
2014-09-26 16:22:43 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( attr_val ) {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Decode entities
|
|
|
|
attr_val = $( '<div/>' ).html( attr_val ).text();
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Add slashes
|
2015-07-10 10:37:05 +00:00
|
|
|
attr_val = attr_val.replace( /'/g, '\\\'' );
|
|
|
|
attr_val = attr_val.replace( /"/g, '\\\"' );
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Compare the meerkat
|
|
|
|
current_attr_select.find( 'option[value="' + attr_val + '"]' ).addClass( 'attached ' + variation_active );
|
2013-02-01 11:49:29 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
} else {
|
2012-08-08 10:53:36 +00:00
|
|
|
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.find( 'option' + option_gt_filter ).addClass( 'attached ' + variation_active );
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2014-02-22 04:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2014-02-22 04:08:08 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Detach unattached
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.find( 'option' + option_gt_filter + ':not(.attached)' ).remove();
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Grey out disabled
|
2016-10-11 17:26:08 +00:00
|
|
|
current_attr_select.find( 'option' + option_gt_filter + ':not(.enabled)' ).attr( 'disabled', 'disabled' );
|
2012-08-21 15:41:18 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
});
|
2013-10-10 15:34:44 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
// Custom event for when variations have been updated
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'woocommerce_update_variation_values' );
|
2015-07-09 14:56:20 +00:00
|
|
|
});
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-07-14 09:28:49 +00:00
|
|
|
$form.trigger( 'wc_variation_form' );
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
return $form;
|
|
|
|
};
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
/**
|
|
|
|
* Matches inline variation objects to chosen attributes
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
var wc_variation_form_matcher = {
|
|
|
|
find_matching_variations: function( product_variations, settings ) {
|
|
|
|
var matching = [];
|
|
|
|
for ( var i = 0; i < product_variations.length; i++ ) {
|
|
|
|
var variation = product_variations[i];
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( wc_variation_form_matcher.variations_match( variation.attributes, settings ) ) {
|
|
|
|
matching.push( variation );
|
2015-07-10 05:13:30 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
|
|
|
return matching;
|
|
|
|
},
|
|
|
|
variations_match: function( attrs1, attrs2 ) {
|
|
|
|
var match = true;
|
|
|
|
for ( var attr_name in attrs1 ) {
|
|
|
|
if ( attrs1.hasOwnProperty( attr_name ) ) {
|
|
|
|
var val1 = attrs1[ attr_name ];
|
|
|
|
var val2 = attrs2[ attr_name ];
|
|
|
|
if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
|
|
|
|
match = false;
|
|
|
|
}
|
2014-03-17 05:19:58 +00:00
|
|
|
}
|
2015-07-09 14:56:20 +00:00
|
|
|
}
|
|
|
|
return match;
|
|
|
|
}
|
2014-02-22 04:08:08 +00:00
|
|
|
};
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-10-28 13:04:28 +00:00
|
|
|
/**
|
|
|
|
* Stores the default text for an element so it can be reset later
|
|
|
|
*/
|
|
|
|
$.fn.wc_set_content = function( content ) {
|
|
|
|
if ( undefined === this.attr( 'data-o_content' ) ) {
|
|
|
|
this.attr( 'data-o_content', this.text() );
|
|
|
|
}
|
|
|
|
this.text( content );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the default text for an element so it can be reset later
|
|
|
|
*/
|
|
|
|
$.fn.wc_reset_content = function() {
|
|
|
|
if ( undefined !== this.attr( 'data-o_content' ) ) {
|
|
|
|
this.text( this.attr( 'data-o_content' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a default attribute for an element so it can be reset later
|
|
|
|
*/
|
|
|
|
$.fn.wc_set_variation_attr = function( attr, value ) {
|
|
|
|
if ( undefined === this.attr( 'data-o_' + attr ) ) {
|
|
|
|
this.attr( 'data-o_' + attr, ( ! this.attr( attr ) ) ? '' : this.attr( attr ) );
|
|
|
|
}
|
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
|
|
|
if ( false === value ) {
|
|
|
|
this.removeAttr( attr );
|
|
|
|
} else {
|
|
|
|
this.attr( attr, value );
|
|
|
|
}
|
2015-10-28 13:04:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset a default attribute for an element so it can be reset later
|
|
|
|
*/
|
|
|
|
$.fn.wc_reset_variation_attr = function( attr ) {
|
|
|
|
if ( undefined !== this.attr( 'data-o_' + attr ) ) {
|
|
|
|
this.attr( attr, this.attr( 'data-o_' + attr ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets product images for the chosen variation
|
|
|
|
*/
|
|
|
|
$.fn.wc_variations_image_update = function( variation ) {
|
|
|
|
var $form = this,
|
|
|
|
$product = $form.closest('.product'),
|
2016-10-13 14:25:42 +00:00
|
|
|
$gallery_img = $product.find( '.flex-control-nav li:eq(0) img' ),
|
|
|
|
$product_img_wrap = $product.find( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:eq(0)' ),
|
|
|
|
$product_img = $product.find( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:eq(0) .wp-post-image' );
|
2015-10-28 13:04:28 +00:00
|
|
|
|
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
|
|
|
if ( variation && variation.image && variation.image.src.length > 1 ) {
|
|
|
|
$product_img.wc_set_variation_attr( 'src', variation.image.src );
|
|
|
|
$product_img.wc_set_variation_attr( 'height', variation.image.src_h );
|
|
|
|
$product_img.wc_set_variation_attr( 'width', variation.image.src_w );
|
|
|
|
$product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
|
|
|
|
$product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
|
|
|
|
$product_img.wc_set_variation_attr( 'title', variation.image.title );
|
|
|
|
$product_img.wc_set_variation_attr( 'alt', variation.image.alt );
|
|
|
|
$product_img.wc_set_variation_attr( 'data-large-image', variation.image.full_src );
|
|
|
|
$product_img.wc_set_variation_attr( 'data-large-image-width', variation.image.full_src_w );
|
|
|
|
$product_img.wc_set_variation_attr( 'data-large-image-height', variation.image.full_src_h );
|
|
|
|
$product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
|
2015-10-28 13:04:28 +00:00
|
|
|
} else {
|
2016-10-13 14:25:42 +00:00
|
|
|
$product_img_wrap.wc_reset_variation_attr( 'data-thumb' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'large-image' );
|
2015-10-28 13:04:28 +00:00
|
|
|
$product_img.wc_reset_variation_attr( 'src' );
|
2016-10-13 14:25:42 +00:00
|
|
|
$product_img.wc_reset_variation_attr( 'width' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'height' );
|
2015-11-23 16:35:11 +00:00
|
|
|
$product_img.wc_reset_variation_attr( 'srcset' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'sizes' );
|
2016-10-13 14:25:42 +00:00
|
|
|
$product_img.wc_reset_variation_attr( 'title' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'alt' );
|
|
|
|
$gallery_img.wc_reset_variation_attr( 'src' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'data-large-image' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'data-large-image-width' );
|
|
|
|
$product_img.wc_reset_variation_attr( 'data-large-image-height' );
|
|
|
|
|
|
|
|
window.setTimeout( function() {
|
|
|
|
$( window ).trigger( 'resize' );
|
|
|
|
}, 10 );
|
2015-10-28 13:04:28 +00:00
|
|
|
}
|
2016-10-13 14:25:42 +00:00
|
|
|
$('body').trigger( 'woocommerce_init_gallery' );
|
2015-10-28 13:04:28 +00:00
|
|
|
};
|
|
|
|
|
2014-02-22 04:08:08 +00:00
|
|
|
$( function() {
|
2015-07-09 14:56:20 +00:00
|
|
|
if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) {
|
2015-07-09 15:21:17 +00:00
|
|
|
$( '.variations_form' ).each( function() {
|
|
|
|
$( this ).wc_variation_form().find('.variations select:eq(0)').change();
|
|
|
|
});
|
2015-07-10 05:13:30 +00:00
|
|
|
}
|
2014-02-22 04:08:08 +00:00
|
|
|
});
|
2013-02-07 10:12:08 +00:00
|
|
|
|
2015-07-14 09:28:49 +00:00
|
|
|
})( jQuery, window, document );
|