From f9f1bb9dddca479924b20b24ee9f0990218e7e9b Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Sun, 10 Jun 2012 18:15:02 +0100 Subject: [PATCH] Ordering tweaks/improvements and variation prices. Closes #1097. --- .../writepanel-product-type-variable.php | 3 +- .../writepanels/writepanel-product_data.php | 3 -- admin/woocommerce-admin-init.php | 6 +-- classes/class-wc-product.php | 32 +++++---------- readme.txt | 2 + .../single-product/add-to-cart/variable.php | 37 ++++++++--------- .../single-product/product-attributes.php | 17 ++++---- woocommerce-core-functions.php | 41 +++++++++++++++++++ 8 files changed, 84 insertions(+), 57 deletions(-) diff --git a/admin/post-types/writepanels/writepanel-product-type-variable.php b/admin/post-types/writepanels/writepanel-product-type-variable.php index 763d8eaaf29..feab2efdf48 100644 --- a/admin/post-types/writepanels/writepanel-product-type-variable.php +++ b/admin/post-types/writepanels/writepanel-product-type-variable.php @@ -853,13 +853,14 @@ function process_product_meta_variable( $post_id ) { 'posts_per_page'=> -1, 'post_type' => 'product_variation', 'fields' => 'ids', - 'post_status' => 'any' + 'post_status' => 'publish' )); $lowest_price = $lowest_regular_price = $lowest_sale_price = $highest_price = $highest_regular_price = $highest_sale_price = ''; if ($children) { foreach ($children as $child) { + $child_price = get_post_meta($child, '_price', true); $child_sale_price = get_post_meta($child, '_sale_price', true); diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php index 8bde9bd608d..0116633fedc 100644 --- a/admin/post-types/writepanels/writepanel-product_data.php +++ b/admin/post-types/writepanels/writepanel-product_data.php @@ -503,9 +503,6 @@ function woocommerce_product_data_box() { woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __('Grouping', 'woocommerce'), 'value' => $post->post_parent, 'options' => $post_parents ) ); - // Ordering - removed due to adding page-attributes panel (same field) - //woocommerce_wp_text_input( array( 'id' => 'menu_order', 'label' => _x('Sort Order', 'ordering', 'woocommerce'), 'value' => $post->menu_order ) ); - do_action('woocommerce_product_options_grouping'); echo ''; diff --git a/admin/woocommerce-admin-init.php b/admin/woocommerce-admin-init.php index bf92037cdd7..480ea524940 100644 --- a/admin/woocommerce-admin-init.php +++ b/admin/woocommerce-admin-init.php @@ -297,13 +297,13 @@ function woocommerce_admin_scripts() { endif; - // Term ordering - only when sorting by menu_order (our custom meta) - if (($screen->id=='edit-product_cat' || strstr($screen->id, 'edit-pa_')) && !isset($_GET['orderby'])) : + // Term ordering - only when sorting by term_order + if ( ( $screen->id == 'edit-product_cat' || strstr( $screen->id, 'edit-pa_' ) ) && ! isset( $_GET['orderby'] ) ) : wp_register_script( 'woocommerce_term_ordering', $woocommerce->plugin_url() . '/assets/js/admin/term-ordering.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'woocommerce_term_ordering' ); - $taxonomy = (isset($_GET['taxonomy'])) ? $_GET['taxonomy'] : ''; + $taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : ''; $woocommerce_term_order_params = array( 'taxonomy' => $taxonomy diff --git a/classes/class-wc-product.php b/classes/class-wc-product.php index 8b25e141ae9..12a5b01d2d4 100644 --- a/classes/class-wc-product.php +++ b/classes/class-wc-product.php @@ -849,34 +849,21 @@ class WC_Product { $attr = sanitize_title( $attr ); - if (isset($attributes[$attr]) || isset($attributes['pa_' . $attr])) : + if ( isset( $attributes[ $attr ] ) || isset( $attributes[ 'pa_' . $attr ] ) ) { - $attribute = isset($attributes[$attr]) ? $attributes[$attr] : $attributes['pa_' . $attr]; + $attribute = isset( $attributes[ $attr ] ) ? $attributes[ $attr ] : $attributes[ 'pa_' . $attr ]; - if ($attribute['is_taxonomy']) : + if ( $attribute['is_taxonomy'] ) { - // Get string with terms - $terms = get_the_terms( $this->id, $attribute['name'] ); + return implode( ', ', woocommerce_get_product_terms( $this->id, $attribute['name'], 'names' ) ); - if ( $terms && ! is_wp_error( $terms ) ) : - - $terms_array = array(); - - foreach ( $terms as $term ) : - $terms_array[] = $term->name; - endforeach; - - return implode( ', ', $terms_array ); - - endif; - - else : + } else { return $attribute['value']; - endif; + } - endif; + } return false; } @@ -1193,13 +1180,14 @@ class WC_Product { 'posts_per_page'=> -1, 'post_type' => 'product_variation', 'fields' => 'ids', - 'post_status' => 'any' + 'post_status' => 'publish' )); $this->min_variation_price = $this->min_variation_regular_price = $this->min_variation_sale_price = $this->max_variation_price = $this->max_variation_regular_price = $this->max_variation_sale_price = ''; if ($children) { - foreach ($children as $child) { + foreach ( $children as $child ) { + $child_price = get_post_meta($child, '_price', true); $child_sale_price = get_post_meta($child, '_sale_price', true); diff --git a/readme.txt b/readme.txt index 90f8e73bdf5..8201619b2b2 100644 --- a/readme.txt +++ b/readme.txt @@ -153,6 +153,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Feature - Menu count for orders requiring admin action * Feature - 'supports' function for gateways. * Feature - Ajax powered coupon form on checkout. +* Tweak - woocommerce_get_product_terms for getting terms in the user defined order. +* Tweak - Variations that are disabled are not taken into consideration when displaying parent price. * Tweak - Variations maintain selections after adding to cart. * Tweak - Improvements to the order tracking code, including better error messages * Tweak - EU states for tax diff --git a/templates/single-product/add-to-cart/variable.php b/templates/single-product/add-to-cart/variable.php index 7c10ca4814c..2a4d1f2b4b3 100644 --- a/templates/single-product/add-to-cart/variable.php +++ b/templates/single-product/add-to-cart/variable.php @@ -14,38 +14,37 @@ global $woocommerce, $product, $post;
- $options) : $loop++; ?> + $options ) : $loop++; ?> diff --git a/templates/single-product/product-attributes.php b/templates/single-product/product-attributes.php index bb2e3af5c96..fd05393c87e 100644 --- a/templates/single-product/product-attributes.php +++ b/templates/single-product/product-attributes.php @@ -41,19 +41,18 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php index 95753d84666..d4623a7e412 100644 --- a/woocommerce-core-functions.php +++ b/woocommerce-core-functions.php @@ -800,6 +800,47 @@ function woocommerce_terms_clauses($clauses, $taxonomies, $args ) { return $clauses; } +/** + * woocommerce_get_product_terms function. + * + * Gets product terms in the order they are defined in the backend. + * + * @access public + * @param mixed $object_id + * @param mixed $taxonomy + * @param mixed $fields ids, names, slugs, all + * @return array + */ +function woocommerce_get_product_terms( $object_id, $taxonomy, $fields = 'all' ) { + + $terms = array(); + $object_terms = wp_get_object_terms( $object_id, $taxonomy ); + $all_terms = array_flip( get_terms( $taxonomy, array( 'menu_order' => 'ASC', 'fields' => 'ids' ) ) ); + + switch ( $fields ) { + case 'names' : + foreach ( $object_terms as $term ) + $terms[ $all_terms[ $term->term_id ] ] = $term->name; + break; + case 'ids' : + foreach ( $object_terms as $term ) + $terms[ $all_terms[ $term->term_id ] ] = $term->term_id; + break; + case 'slugs' : + foreach ( $object_terms as $term ) + $terms[ $all_terms[ $term->term_id ] ] = $term->slug; + break; + case 'all' : + foreach ( $object_terms as $term ) + $terms[ $all_terms[ $term->term_id ] ] = $term; + break; + } + + ksort( $terms ); + + return $terms; +} + /** * WooCommerce Dropdown categories *
'.__('Clear selection', 'woocommerce').''; - } ?>
attribute_label( $attribute['name'] ); ?> id, $attribute['name'] ); - $values = array(); - foreach ( $post_terms as $term ) - if ( ! empty( $term->name ) ) - $values[] = $term->name; - echo implode( ', ', $values ); - else : + if ( $attribute['is_taxonomy'] ) { + + echo implode( ', ', woocommerce_get_product_terms( $product->id, $attribute['name'], 'names' ) ); + + } else { + // Convert pipes to commas $value = explode( '|', $attribute['value'] ); $value = implode( ', ', $value ); echo wpautop( wptexturize( $value ) ); - endif; + + } ?>