WC_Product_Variable::sort_variation_prices()

To keep variation sorting logic inside the variable product, and separate
from the database storage logic in WC_Product_Variable_Data_Store_CPT
This commit is contained in:
Brent Shepherd 2017-01-26 10:45:16 -08:00
parent 3632660d2c
commit e7e434da4b
2 changed files with 19 additions and 5 deletions

View File

@ -68,7 +68,14 @@ class WC_Product_Variable extends WC_Product {
*/
public function get_variation_prices( $include_taxes = false ) {
$data_store = $this->get_data_store();
return $data_store->read_price_data( $this, $include_taxes );
$prices = $data_store->read_price_data( $this, $include_taxes );
foreach ( $prices as $price_key => $variation_prices ) {
$prices[ $price_key ] = $this->sort_variation_prices( $variation_prices );
}
return $prices;
}
/**
@ -485,4 +492,15 @@ class WC_Product_Variable extends WC_Product {
}
return $product;
}
/**
* Sort an associativate array of $variation_id => $price pairs in order of min and max prices.
*
* @param array $prices Associativate array of $variation_id => $price pairs
* @return array
*/
protected function sort_variation_prices( $prices ) {
asort( $prices );
return $prices;
}
}

View File

@ -205,10 +205,6 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
}
}
asort( $prices );
asort( $regular_prices );
asort( $sale_prices );
$transient_cached_prices_array[ $price_hash ] = array(
'price' => $prices,
'regular_price' => $regular_prices,