Merge pull request #12292 from woocommerce/product-crud-todos
Remove _wc_save_product_price
This commit is contained in:
commit
5264e2511e
|
@ -29,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<select name="attribute_<?php echo sanitize_title( $attribute->get_name() ) . "[{$loop}]"; ?>">
|
||||
<option value=""><?php
|
||||
/* translators: %s: attribute label */
|
||||
echo sprintf( __( 'Any %s…', 'woocommerce' ), esc_html( wc_attribute_label( $attribute->get_name() ) ) ) )
|
||||
echo sprintf( __( 'Any %s…', 'woocommerce' ), esc_html( wc_attribute_label( $attribute->get_name() ) ) );
|
||||
?>…</option>
|
||||
<?php if ( $attribute->is_taxonomy() ) : ?>
|
||||
<?php foreach ( $attribute->get_terms() as $option ) : ?>
|
||||
|
|
|
@ -2029,17 +2029,9 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
foreach ( $variations as $variation_id ) {
|
||||
// Price fields
|
||||
$regular_price = wc_clean( $data['value'] );
|
||||
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
||||
|
||||
// Date fields
|
||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
|
||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
||||
$variation = wc_get_product( $variation_id );
|
||||
$variation->save_regular_price( wc_clean( $data['value'] ) );
|
||||
$variation->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2056,17 +2048,9 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
foreach ( $variations as $variation_id ) {
|
||||
// Price fields
|
||||
$regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
||||
$sale_price = wc_clean( $data['value'] );
|
||||
|
||||
// Date fields
|
||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
|
||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
||||
$variation = wc_get_product( $variation_id );
|
||||
$variation->save_sale_price( wc_clean( $data['value'] ) );
|
||||
$variation->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2187,27 +2171,17 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
foreach ( $variations as $variation_id ) {
|
||||
// Price fields
|
||||
$regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
||||
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
||||
$variation = wc_get_product( $variation_id );
|
||||
|
||||
// Date fields
|
||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
||||
|
||||
if ( 'false' === $data['date_from'] ) {
|
||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
} else {
|
||||
$date_from = $data['date_from'];
|
||||
if ( 'false' !== $data['date_from'] ) {
|
||||
$variation->set_date_on_sale_from( wc_clean( $data['date_from']) );
|
||||
}
|
||||
|
||||
if ( 'false' === $data['date_to'] ) {
|
||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
} else {
|
||||
$date_to = $data['date_to'];
|
||||
if ( 'false' !== $data['date_to'] ) {
|
||||
$variation->set_date_on_sale_from( wc_clean( $data['date_to']) );
|
||||
}
|
||||
|
||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
||||
$variation->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2259,28 +2233,25 @@ class WC_AJAX {
|
|||
* Bulk action - Set Price.
|
||||
* @access private
|
||||
* @used-by bulk_edit_variations
|
||||
* @param array $variations
|
||||
* @param array $variations
|
||||
* @param string $operator + or -
|
||||
* @param string $field price being adjusted
|
||||
* @param string $field price being adjusted _regular_price or _sale_price
|
||||
* @param string $value Price or Percent
|
||||
*/
|
||||
private static function variation_bulk_adjust_price( $variations, $field, $operator, $value ) {
|
||||
foreach ( $variations as $variation_id ) {
|
||||
// Get existing data
|
||||
$_regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
||||
$_sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
$variation = wc_get_product( $variation_id );
|
||||
$field_value = $variation->{"get$field"}( 'edit' );
|
||||
|
||||
if ( '%' === substr( $value, -1 ) ) {
|
||||
$percent = wc_format_decimal( substr( $value, 0, -1 ) );
|
||||
$$field += ( ( $$field / 100 ) * $percent ) * "{$operator}1";
|
||||
$field_value += ( ( $field_value / 100 ) * $percent ) * "{$operator}1";
|
||||
} else {
|
||||
$$field += $value * "{$operator}1";
|
||||
$field_value += $value * "{$operator}1";
|
||||
}
|
||||
_wc_save_product_price( $variation_id, $_regular_price, $_sale_price, $date_from, $date_to );
|
||||
|
||||
$variation->{"set$field"}( $field_value );
|
||||
$variation->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -732,3 +732,54 @@ function woocommerce_get_product_schema() {
|
|||
|
||||
return 'http://schema.org/' . $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save product price.
|
||||
*
|
||||
* This is a private function (internal use ONLY) used until a data manipulation api is built.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @param int $product_id
|
||||
* @param float $regular_price
|
||||
* @param float $sale_price
|
||||
* @param string $date_from
|
||||
* @param string $date_to
|
||||
*/
|
||||
function _wc_save_product_price( $product_id, $regular_price, $sale_price = '', $date_from = '', $date_to = '' ) {
|
||||
_doing_it_wrong( '_wc_save_product_price()', 'This function is not for developer use and is deprecated.', '2.7' );
|
||||
|
||||
$product_id = absint( $product_id );
|
||||
$regular_price = wc_format_decimal( $regular_price );
|
||||
$sale_price = '' === $sale_price ? '' : wc_format_decimal( $sale_price );
|
||||
$date_from = wc_clean( $date_from );
|
||||
$date_to = wc_clean( $date_to );
|
||||
|
||||
update_post_meta( $product_id, '_regular_price', $regular_price );
|
||||
update_post_meta( $product_id, '_sale_price', $sale_price );
|
||||
|
||||
// Save Dates
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
|
||||
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
|
||||
}
|
||||
|
||||
// Update price if on sale
|
||||
if ( '' !== $sale_price && '' === $date_to && '' === $date_from ) {
|
||||
update_post_meta( $product_id, '_price', $sale_price );
|
||||
} else {
|
||||
update_post_meta( $product_id, '_price', $regular_price );
|
||||
}
|
||||
|
||||
if ( '' !== $sale_price && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
update_post_meta( $product_id, '_price', $sale_price );
|
||||
}
|
||||
|
||||
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
update_post_meta( $product_id, '_price', $regular_price );
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', '' );
|
||||
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -716,57 +716,6 @@ function wc_get_product_id_by_sku( $sku ) {
|
|||
return ( $product_id ) ? intval( $product_id ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save product price.
|
||||
*
|
||||
* This is a private function (internal use ONLY) used until a data manipulation api is built.
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @todo needed?
|
||||
*
|
||||
* @param int $product_id
|
||||
* @param float $regular_price
|
||||
* @param float $sale_price
|
||||
* @param string $date_from
|
||||
* @param string $date_to
|
||||
*/
|
||||
function _wc_save_product_price( $product_id, $regular_price, $sale_price = '', $date_from = '', $date_to = '' ) {
|
||||
$product_id = absint( $product_id );
|
||||
$regular_price = wc_format_decimal( $regular_price );
|
||||
$sale_price = '' === $sale_price ? '' : wc_format_decimal( $sale_price );
|
||||
$date_from = wc_clean( $date_from );
|
||||
$date_to = wc_clean( $date_to );
|
||||
|
||||
update_post_meta( $product_id, '_regular_price', $regular_price );
|
||||
update_post_meta( $product_id, '_sale_price', $sale_price );
|
||||
|
||||
// Save Dates
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
|
||||
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
|
||||
}
|
||||
|
||||
// Update price if on sale
|
||||
if ( '' !== $sale_price && '' === $date_to && '' === $date_from ) {
|
||||
update_post_meta( $product_id, '_price', $sale_price );
|
||||
} else {
|
||||
update_post_meta( $product_id, '_price', $regular_price );
|
||||
}
|
||||
|
||||
if ( '' !== $sale_price && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
update_post_meta( $product_id, '_price', $sale_price );
|
||||
}
|
||||
|
||||
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
update_post_meta( $product_id, '_price', $regular_price );
|
||||
update_post_meta( $product_id, '_sale_price_dates_from', '' );
|
||||
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attibutes/data for an individual variation from the database and maintain it's integrity.
|
||||
* @since 2.4.0
|
||||
|
|
Loading…
Reference in New Issue