Ordering tweaks/improvements and variation prices. Closes #1097.

This commit is contained in:
Mike Jolley 2012-06-10 18:15:02 +01:00
parent 7036acf989
commit f9f1bb9ddd
8 changed files with 84 additions and 57 deletions

View File

@ -853,13 +853,14 @@ function process_product_meta_variable( $post_id ) {
'posts_per_page'=> -1, 'posts_per_page'=> -1,
'post_type' => 'product_variation', 'post_type' => 'product_variation',
'fields' => 'ids', 'fields' => 'ids',
'post_status' => 'any' 'post_status' => 'publish'
)); ));
$lowest_price = $lowest_regular_price = $lowest_sale_price = $highest_price = $highest_regular_price = $highest_sale_price = ''; $lowest_price = $lowest_regular_price = $lowest_sale_price = $highest_price = $highest_regular_price = $highest_sale_price = '';
if ($children) { if ($children) {
foreach ($children as $child) { foreach ($children as $child) {
$child_price = get_post_meta($child, '_price', true); $child_price = get_post_meta($child, '_price', true);
$child_sale_price = get_post_meta($child, '_sale_price', true); $child_sale_price = get_post_meta($child, '_sale_price', true);

View File

@ -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 ) ); 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'); do_action('woocommerce_product_options_grouping');
echo '</div>'; echo '</div>';

View File

@ -297,13 +297,13 @@ function woocommerce_admin_scripts() {
endif; endif;
// Term ordering - only when sorting by menu_order (our custom meta) // Term ordering - only when sorting by term_order
if (($screen->id=='edit-product_cat' || strstr($screen->id, 'edit-pa_')) && !isset($_GET['orderby'])) : 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_register_script( 'woocommerce_term_ordering', $woocommerce->plugin_url() . '/assets/js/admin/term-ordering.js', array('jquery-ui-sortable') );
wp_enqueue_script( 'woocommerce_term_ordering' ); wp_enqueue_script( 'woocommerce_term_ordering' );
$taxonomy = (isset($_GET['taxonomy'])) ? $_GET['taxonomy'] : ''; $taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : '';
$woocommerce_term_order_params = array( $woocommerce_term_order_params = array(
'taxonomy' => $taxonomy 'taxonomy' => $taxonomy

View File

@ -849,34 +849,21 @@ class WC_Product {
$attr = sanitize_title( $attr ); $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 return implode( ', ', woocommerce_get_product_terms( $this->id, $attribute['name'], 'names' ) );
$terms = get_the_terms( $this->id, $attribute['name'] );
if ( $terms && ! is_wp_error( $terms ) ) : } else {
$terms_array = array();
foreach ( $terms as $term ) :
$terms_array[] = $term->name;
endforeach;
return implode( ', ', $terms_array );
endif;
else :
return $attribute['value']; return $attribute['value'];
endif; }
endif; }
return false; return false;
} }
@ -1193,13 +1180,14 @@ class WC_Product {
'posts_per_page'=> -1, 'posts_per_page'=> -1,
'post_type' => 'product_variation', 'post_type' => 'product_variation',
'fields' => 'ids', '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 = ''; $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) { if ($children) {
foreach ($children as $child) { foreach ( $children as $child ) {
$child_price = get_post_meta($child, '_price', true); $child_price = get_post_meta($child, '_price', true);
$child_sale_price = get_post_meta($child, '_sale_price', true); $child_sale_price = get_post_meta($child, '_sale_price', true);

View File

@ -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 - Menu count for orders requiring admin action
* Feature - 'supports' function for gateways. * Feature - 'supports' function for gateways.
* Feature - Ajax powered coupon form on checkout. * 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 - Variations maintain selections after adding to cart.
* Tweak - Improvements to the order tracking code, including better error messages * Tweak - Improvements to the order tracking code, including better error messages
* Tweak - EU states for tax * Tweak - EU states for tax

View File

@ -14,38 +14,37 @@ global $woocommerce, $product, $post;
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="variations_form cart" method="post" enctype='multipart/form-data'> <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="variations_form cart" method="post" enctype='multipart/form-data'>
<table class="variations" cellspacing="0"> <table class="variations" cellspacing="0">
<tbody> <tbody>
<?php $loop = 0; foreach ($attributes as $name => $options) : $loop++; ?> <?php $loop = 0; foreach ( $attributes as $name => $options ) : $loop++; ?>
<tr> <tr>
<td><label for="<?php echo sanitize_title($name); ?>"><?php echo $woocommerce->attribute_label($name); ?></label></td> <td><label for="<?php echo sanitize_title($name); ?>"><?php echo $woocommerce->attribute_label($name); ?></label></td>
<td><select id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>"> <td><select id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>">
<option value=""><?php echo __('Choose an option', 'woocommerce') ?>&hellip;</option> <option value=""><?php echo __('Choose an option', 'woocommerce') ?>&hellip;</option>
<?php if(is_array($options)) : ?> <?php
<?php if ( is_array( $options ) ) {
if ( empty( $_POST ) ) if ( empty( $_POST ) )
$selected_value = ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) ? $selected_attributes[ sanitize_title( $name ) ] : ''; $selected_value = ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) ? $selected_attributes[ sanitize_title( $name ) ] : '';
else else
$selected_value = isset( $_POST[ 'attribute_' . sanitize_title( $name ) ] ) ? $_POST[ 'attribute_' . sanitize_title( $name ) ] : ''; $selected_value = isset( $_POST[ 'attribute_' . sanitize_title( $name ) ] ) ? $_POST[ 'attribute_' . sanitize_title( $name ) ] : '';
// Get terms if this is a taxonomy - ordered // Get terms if this is a taxonomy - ordered
if (taxonomy_exists(sanitize_title($name))) : if ( taxonomy_exists( sanitize_title( $name ) ) ) {
$args = array('menu_order' => 'ASC');
$terms = get_terms( sanitize_title($name), $args );
foreach ($terms as $term) : $terms = get_terms( sanitize_title($name), array('menu_order' => 'ASC') );
if (!in_array($term->slug, $options)) continue;
echo '<option value="'.$term->slug.'" '.selected($selected_value, $term->slug).'>'.$term->name.'</option>'; foreach ( $terms as $term ) {
endforeach; if ( ! in_array( $term->slug, $options ) ) continue;
else : echo '<option value="' . $term->slug . '" ' . selected( $selected_value, $term->slug ) . '>' . $term->name . '</option>';
foreach ($options as $option) : }
echo '<option value="'.$option.'" '.selected($selected_value, $option).'>'.$option.'</option>'; } else {
endforeach; foreach ($options as $option)
endif; echo '<option value="' . $option . '" ' . selected( $selected_value, $option ) . '>' . $option . '</option>';
?> }
<?php endif;?> }
?>
</select> <?php </select> <?php
if ( sizeof($attributes) == $loop ) { if ( sizeof($attributes) == $loop )
echo '<a class="reset_variations" href="#reset">'.__('Clear selection', 'woocommerce').'</a>'; echo '<a class="reset_variations" href="#reset">'.__('Clear selection', 'woocommerce').'</a>';
}
?></td> ?></td>
</tr> </tr>
<?php endforeach;?> <?php endforeach;?>

View File

@ -41,19 +41,18 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p
<tr class="<?php if ( $alt == 1 ) echo 'alt'; ?>"> <tr class="<?php if ( $alt == 1 ) echo 'alt'; ?>">
<th><?php echo $woocommerce->attribute_label( $attribute['name'] ); ?></th> <th><?php echo $woocommerce->attribute_label( $attribute['name'] ); ?></th>
<td><?php <td><?php
if ( $attribute['is_taxonomy'] ) : if ( $attribute['is_taxonomy'] ) {
$post_terms = wp_get_post_terms( $product->id, $attribute['name'] );
$values = array(); echo implode( ', ', woocommerce_get_product_terms( $product->id, $attribute['name'], 'names' ) );
foreach ( $post_terms as $term )
if ( ! empty( $term->name ) ) } else {
$values[] = $term->name;
echo implode( ', ', $values );
else :
// Convert pipes to commas // Convert pipes to commas
$value = explode( '|', $attribute['value'] ); $value = explode( '|', $attribute['value'] );
$value = implode( ', ', $value ); $value = implode( ', ', $value );
echo wpautop( wptexturize( $value ) ); echo wpautop( wptexturize( $value ) );
endif;
}
?></td> ?></td>
</tr> </tr>

View File

@ -800,6 +800,47 @@ function woocommerce_terms_clauses($clauses, $taxonomies, $args ) {
return $clauses; 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 * WooCommerce Dropdown categories
* *