Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #313 from Prospress/issue-309
Browse files Browse the repository at this point in the history
Show variation prices if needed
  • Loading branch information
Manos Psychogyiopoulos authored May 31, 2018
2 parents a363bd9 + 6fd23a1 commit 6f7bbc6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 51 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fix - Wrong repository name in .pot file.
* Fix - Edge case issues with saving newly created schemes after changing the product type.
* Fix - When adding a new scheme to a Variable product, some Price fields appear mislabelled.
* Fix - When choosing a variation with susbcription schemes, its price string is always replaced by the subscription scheme options. Unless all variations have the same price, this behavior leaves the user wondering what the variation price might be.
* Tweak - Do not default global cart-level scheme options to non-empty set.

2018.05.03 - version 2.1.0
Expand Down
54 changes: 48 additions & 6 deletions includes/display/class-wcs-att-display-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Single-product template modifications.
*
* @class WCS_ATT_Display_Product
* @version 2.1.0
* @version 2.1.1
*/
class WCS_ATT_Display_Product {

Expand Down Expand Up @@ -72,7 +72,6 @@ public static function get_subscription_options_content( $product, $parent_produ
$product_id = WCS_ATT_Core_Compatibility::get_product_id( $product );
$subscription_schemes = WCS_ATT_Product_Schemes::get_subscription_schemes( $product );
$force_subscription = WCS_ATT_Product_Schemes::has_forced_subscription_scheme( $product );
$is_single_scheme_forced_subscription = $force_subscription && sizeof( $subscription_schemes ) === 1;
$default_subscription_scheme_key = apply_filters( 'wcsatt_get_default_subscription_scheme_id', WCS_ATT_Product_Schemes::get_default_subscription_scheme( $product, 'key' ), $subscription_schemes, false === $force_subscription, $product ); // Why 'false === $force_subscription'? The answer is back-compat.
$posted_subscription_scheme_key = WCS_ATT_Product_Schemes::get_posted_subscription_scheme( $product_id );
$options = array();
Expand All @@ -87,12 +86,11 @@ public static function get_subscription_options_content( $product, $parent_produ
// Non-recurring (one-time) option.
if ( false === $force_subscription ) {

$none_string = _x( 'none', 'product subscription selection - negative response', 'woocommerce-subscribe-all-the-things' );
$one_time_option_description = $product->is_type( 'variation' ) ? sprintf( __( '%1$s &ndash; %2$s', 'woocommerce-subscribe-all-the-things' ), $none_string, '<span class="price one-time-option-price">' . WCS_ATT_Product_Prices::get_price_html( $product, false ) . '</span>' ) : $none_string;
$none_string = _x( 'none', 'product subscription selection - negative response', 'woocommerce-subscribe-all-the-things' );

$options[] = array(
'class' => 'one-time-option',
'description' => apply_filters( 'wcsatt_single_product_one_time_option_description', $one_time_option_description, $product ),
'description' => apply_filters( 'wcsatt_single_product_one_time_option_description', $none_string, $product ),
'value' => '0',
'selected' => '0' === $default_subscription_scheme_option_value,
'data' => apply_filters( 'wcsatt_single_product_one_time_option_data', array(), $product )
Expand Down Expand Up @@ -187,7 +185,51 @@ public static function add_subscription_options_to_variation_data( $variation_da

if ( is_a( $product, 'WC_Product' ) && $variable_product->get_id() === $product->get_id() && ! did_action( 'wc_ajax_woocommerce_show_composited_product' ) ) {
if ( $subscription_options_content = self::get_subscription_options_content( $variation_product, $variable_product ) ) {
$variation_data[ 'price_html' ] = $subscription_options_content;

$subscription_schemes = WCS_ATT_Product_Schemes::get_subscription_schemes( $variable_product );
$force_subscription = WCS_ATT_Product_Schemes::has_forced_subscription_scheme( $variable_product );
$price_filter_exists = WCS_ATT_Product_Schemes::price_filter_exists( $subscription_schemes );
$is_single_scheme_forced_subscription = $force_subscription && sizeof( $subscription_schemes ) === 1;
$has_equal_variation_prices = '' === $variation_data[ 'price_html' ];

/*
* When should we keep the existing price string?
*
* - When dealing with a single-scheme, force-subscription case (non-empty price string with subscription details).
* - When no scheme overrides the original variation price and all variation prices are equal and hidden (empty price string).
*/
if ( $is_single_scheme_forced_subscription || ( false === $price_filter_exists && $has_equal_variation_prices ) ) {

$variation_data[ 'price_html' ] = $variation_data[ 'price_html' ] . $subscription_options_content;

} else {

/*
* At this point, the variation price string will include subscription details because it has been filtered by 'WCS_ATT_Product_Prices::get_price_html'.
* We need to somehow generate the original, subscription-less price string.
*/

if ( $force_subscription ) {
// To get the subscription-less price string, we need to enable the one-time option.
WCS_ATT_Product_Schemes::set_forced_subscription_scheme( $variation_product, false );
}

// Back up the currently applied scheme key.
$active_scheme_key = WCS_ATT_Product_Schemes::get_subscription_scheme( $variation_product );

// Set the one-time scheme on the object.
WCS_ATT_Product_Schemes::set_subscription_scheme( $variation_product, false );

// Get the price string :)
$variation_data[ 'price_html' ] = '<span class="price">' . $variation_product->get_price_html() . '</span>' . $subscription_options_content;

// Un-do.
WCS_ATT_Product_Schemes::set_subscription_scheme( $variation_product, $active_scheme_key );

if ( $force_subscription ) {
WCS_ATT_Product_Schemes::set_forced_subscription_scheme( $variation_product, true );
}
}
}
}

Expand Down
85 changes: 40 additions & 45 deletions languages/woocommerce-subscribe-all-the-things.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: WooCommerce Subscribe All the Things 2.1.1-dev\n"
"Report-Msgid-Bugs-To: "
"https://github.com/Prospress/woocommerce-subscribe-all-the-things/issues\n"
"POT-Creation-Date: 2018-05-30 07:22:53+00:00\n"
"POT-Creation-Date: 2018-05-30 14:15:52+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -56,6 +56,35 @@ msgstr ""
msgid "Disabled"
msgstr ""

#: includes/admin/class-wcs-att-admin.php:286
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:246
msgid "Inherit from product"
msgstr ""

#: includes/admin/class-wcs-att-admin.php:287
msgid "Inherit from chosen variation"
msgstr ""

#: includes/admin/class-wcs-att-admin.php:288
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:247
msgid "Override product"
msgstr ""

#: includes/admin/class-wcs-att-admin.php:289
msgid "Override all variations"
msgstr ""

#: includes/admin/class-wcs-att-admin.php:290
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:288
msgid "Discount applied on the <strong>Regular Price</strong> of the product."
msgstr ""

#: includes/admin/class-wcs-att-admin.php:291
msgid ""
"Discount applied on the <strong>Regular Price</strong> of the chosen "
"variation."
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:65
msgid "Subscriptions"
msgstr ""
Expand Down Expand Up @@ -124,53 +153,23 @@ msgstr ""
msgid "Choose the subscription billing length."
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:245
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:303
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:243
msgid "Price"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:248
msgid "Inherit from product"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:249
msgid "Override product"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:264
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:322
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:262
msgid "Regular Price"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:275
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:333
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:273
msgid "Sale Price"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:289
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:347
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:287
msgid "Discount %"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:290
msgid "Discount applied on the <strong>Regular Price</strong> of the product."
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:306
msgid "Inherit from chosen variation"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:307
msgid "Override all variations"
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:348
msgid ""
"Discount applied on the <strong>Regular Price</strong> of the chosen "
"variation."
msgstr ""

#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:416
#: includes/admin/meta-boxes/class-wcs-att-meta-box-product-data.php:340
msgid "Please enter positive subscription discount values, between 0-100."
msgstr ""

Expand Down Expand Up @@ -220,16 +219,12 @@ msgstr ""
msgid "only now"
msgstr ""

#: includes/display/class-wcs-att-display-product.php:91
msgid "%1$s &ndash; %2$s"
msgstr ""

#: includes/display/class-wcs-att-display-product.php:235
#: includes/display/class-wcs-att-display-product.php:265
#: includes/display/class-wcs-att-display-product.php:277
#: includes/display/class-wcs-att-display-product.php:307
msgid "Sign up"
msgstr ""

#: includes/display/class-wcs-att-display-product.php:257
#: includes/display/class-wcs-att-display-product.php:299
msgid "Select options"
msgstr ""

Expand Down Expand Up @@ -443,12 +438,12 @@ msgctxt "cart subscription selection - positive response"
msgid "Yes, %s."
msgstr ""

#: includes/display/class-wcs-att-display-product.php:90
#: includes/display/class-wcs-att-display-product.php:89
msgctxt "product subscription selection - negative response"
msgid "none"
msgstr ""

#: includes/display/class-wcs-att-display-product.php:133
#: includes/display/class-wcs-att-display-product.php:131
msgctxt "product subscription selection - positive response"
msgid "%s"
msgstr ""
Expand Down

0 comments on commit 6f7bbc6

Please sign in to comment.