Tweaked sale queries, fixed admin styling

This commit is contained in:
Mike Jolley 2011-09-23 09:38:09 +01:00
parent 793dce823c
commit c9cb278739
6 changed files with 56 additions and 67 deletions

View File

@ -604,6 +604,7 @@ function process_product_meta_variable( $post_id ) {
endforeach;
endfor;
endif;
}

View File

@ -520,32 +520,28 @@ function woocommerce_process_product_meta( $post_id, $post ) {
endif;
// Update parent if grouped so price sorting works
// Update parent if grouped so price sorting works and stays in sync
if ($post->post_parent || $product_type=='grouped') :
if ($post->post_parent) :
$post_parent = $post->post_parent;
else :
$post_parent = $post_id;
endif;
$post_parent = ($post->post_parent>0) ? $post->post_parent : $post_id;
$children_by_price = get_posts( array(
'post_parent' => $post_parent,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'price',
'posts_per_page' => 1,
'post_type' => 'product'
'post_type' => 'product',
'fields' => 'ids'
));
if ($children_by_price) :
$children_by_price = $children_by_price[0];
$child = $children_by_price->ID;
update_post_meta( $post_parent, 'price', get_post_meta($child, 'price', true) );
foreach ($children_by_price as $child) :
$child_price = get_post_meta($child, 'price', true);
update_post_meta( $post_parent, 'price', $child_price );
endforeach;
endif;
endif;
// Stock Data
if (get_option('woocommerce_manage_stock')=='yes') :
// Manage Stock Checkbox
if ($product_type!=='grouped' && isset($_POST['manage_stock']) && $_POST['manage_stock']) :

View File

@ -44,7 +44,6 @@ dl.totals dd input.last{width:49%;float:right;}
.woocommerce-order-panel textarea,.woocommerce-order-panel input,.woocommerce-order-panel select{margin:0;}
.woocommerce-order-panel textarea{width:65% !important;float:left;}
.woocommerce-order-panel input{width:65%;float:left;}
.widefat th.column-id{width:60px !important;}
.widefat .column-order_title time{display:block;color:#999;margin:3px 0;}
.widefat small.meta{display:block;color:#999;font-size:inherit;margin:3px 0;}
.widefat .column-total_cost,.widefat .column-order_date{width:150px !important;}
@ -62,7 +61,7 @@ ul.subsubsub li.onhold a{color:red;}
ul.subsubsub li.cancelled a{color:#dfdfdf;}
ul.subsubsub li.refunded a{color:#ccc;}
table.wp-list-table .column-thumb{width:66px;text-align:center;white-space:nowrap;}
table.wp-list-table .column-title{width:25%;}
table.wp-list-table .column-sku,table.wp-list-table .column-product_type,table.wp-list-table .column-product_cat,table.wp-list-table .column-product_tags,table.wp-list-table .column-is_in_stock,table.wp-list-table .column-price,table.wp-list-table .column-product_date,table.wp-list-table .column-featured{width:9%;}
table.wp-list-table img{margin:1px 2px;}
table.wp-list-table .column-thumb img{padding:2px;margin:0;border:1px solid #dfdfdf;vertical-align:middle;width:42px;height:42px;}
table.wp-list-table span.na{color:#999;}

View File

@ -235,10 +235,7 @@ dl.totals {
}
}
.widefat {
th.column-id {
width:60px !important;
}
.widefat {
.column-order_title {
time {
display: block;
@ -343,10 +340,8 @@ table.wp-list-table {
text-align: center;
white-space: nowrap
}
.column-title {
width: 25%;
}
.column-sku {
.column-sku, .column-product_type, .column-product_cat, .column-product_tags, .column-is_in_stock, .column-price, .column-product_date, .column-featured {
width: 9%;
}
img {
margin: 1px 2px;

View File

@ -87,9 +87,9 @@ class woocommerce_product {
$this->get_children();
// total_stock
// total_stock (stock of parent and children combined)
$this->total_stock = $this->stock;
if (sizeof($this->children)>0) foreach ($this->children as $child) :
if (sizeof($this->get_children())>0) foreach ($this->get_children() as $child) :
if (isset($child->product->variation_has_stock)) :
if ($child->product->variation_has_stock) :
$this->total_stock += $child->product->stock;
@ -99,6 +99,9 @@ class woocommerce_product {
endif;
endforeach;
// Check sale
$this->check_sale_price();
if ($product_custom_fields) :
$this->exists = true;
else :
@ -123,20 +126,24 @@ class woocommerce_product {
$this->children = array();
if ($this->is_type('variable')) $child_post_type = 'product_variation'; else $child_post_type = 'product';
if ( $children_products =& get_children( 'post_parent='.$this->id.'&post_type='.$child_post_type.'&orderby=menu_order&order=ASC' ) ) :
if ($children_products) foreach ($children_products as $child) :
if ($this->is_type('variable')) :
$child->product = &new woocommerce_product_variation( $child->ID );
else :
$child->product = &new woocommerce_product( $child->ID );
endif;
endforeach;
$this->children = (array) $children_products;
if ($this->is_type('variable') || $this->is_type('grouped')) :
if ($this->is_type('variable')) $child_post_type = 'product_variation'; else $child_post_type = 'product';
if ( $children_products =& get_children( 'post_parent='.$this->id.'&post_type='.$child_post_type.'&orderby=menu_order&order=ASC' ) ) :
if ($children_products) foreach ($children_products as $child) :
if ($this->is_type('variable')) :
$child->product = &new woocommerce_product_variation( $child->ID );
else :
$child->product = &new woocommerce_product( $child->ID );
endif;
endforeach;
$this->children = (array) $children_products;
endif;
endif;
endif;
@ -193,7 +200,7 @@ class woocommerce_product {
/** Returns whether or not the product has any child product */
function has_child() {
return sizeof($this->children) ? true : false;
return sizeof($this->get_children()) ? true : false;
}
/** Returns whether or not the product post exists */
@ -392,25 +399,17 @@ class woocommerce_product {
/** Returns whether or not the product is on sale */
function is_on_sale() {
if ( $this->has_child() ) :
$onsale = false;
foreach ($this->children as $child) :
if ( $child->product->sale_price==$child->product->price ) :
return true;
endif;
foreach ($this->get_children() as $child) :
if ( $child->product->sale_price==$child->product->price ) return true;
endforeach;
else :
if ( $this->sale_price && $this->sale_price==$this->price ) :
return true;
endif;
if ( $this->sale_price && $this->sale_price==$this->price ) return true;
endif;
return false;
}
@ -421,9 +420,7 @@ class woocommerce_product {
/** Returns the product's price */
function get_price() {
return $this->price;
}
/** Returns the price (excluding tax) */
@ -475,12 +472,12 @@ class woocommerce_product {
/** Returns the price in html format */
function get_price_html() {
$price = '';
if ( $this->has_child() ) :
if ($this->is_type('grouped')) :
$min_price = '';
$max_price = '';
foreach ($this->children as $child) :
foreach ($this->get_children() as $child) :
$child_price = $child->product->get_price();
if ($child_price<$min_price || $min_price == '') $min_price = $child_price;
if ($child_price>$max_price || $max_price == '') $max_price = $child_price;
@ -765,8 +762,8 @@ class woocommerce_product {
$this->price = $this->sale_price;
update_post_meta($this->id, 'price', $this->price);
// Grouped products are affected by children
$this->grouped_product_price_sync();
// Grouped product prices and sale status are affected by children
$this->grouped_product_sync();
endif;
@ -784,8 +781,8 @@ class woocommerce_product {
update_post_meta($this->id, 'sale_price_dates_from', '');
update_post_meta($this->id, 'sale_price_dates_to', '');
// Grouped products are affected by children
$this->grouped_product_price_sync();
// Grouped product prices and sale status are affected by children
$this->grouped_product_sync();
endif;
@ -795,7 +792,7 @@ class woocommerce_product {
/**
* Sync grouped products with the childs lowest price (so they can be sorted by price accurately)
**/
function grouped_product_price_sync() {
function grouped_product_sync() {
global $wpdb;
$post_parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID = $this->id;");
@ -808,12 +805,14 @@ class woocommerce_product {
'order' => 'asc',
'meta_key' => 'price',
'posts_per_page' => 1,
'post_type' => 'product'
'post_type' => 'product',
'fields' => 'ids'
));
if ($children_by_price) :
$children_by_price = $children_by_price[0];
$child = $children_by_price->ID;
update_post_meta( $post_parent, 'price', get_post_meta($child, 'price', true) );
foreach ($children_by_price as $child) :
$child_price = get_post_meta($child, 'price', true);
update_post_meta( $post_parent, 'price', $child_price );
endforeach;
endif;
}

View File

@ -312,7 +312,7 @@ if (!function_exists('woocommerce_grouped_add_to_cart')) {
<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post">
<table cellspacing="0" class="group_table">
<tbody>
<?php foreach ($_product->children as $child) : $child_product = &new woocommerce_product( $child->ID ); $cavailability = $child_product->get_availability(); ?>
<?php foreach ($_product->get_children() as $child) : $child_product = &new woocommerce_product( $child->ID ); $cavailability = $child_product->get_availability(); ?>
<tr>
<td><div class="quantity"><input name="quantity[<?php echo $child->ID; ?>]" value="0" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td>
<td><label for="product-<?php echo $child_product->id; ?>"><?php
@ -340,9 +340,8 @@ if (!function_exists('woocommerce_variable_add_to_cart')) {
// Put available variations into an array and put in a Javascript variable (JSON encoded)
$available_variations = array();
$children = $_product->get_children();
foreach($children as $child) {
foreach($_product->get_children() as $child) {
$variation = $child->product;
if($variation instanceof woocommerce_product_variation) {