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

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Manos Psychogyiopoulos committed Oct 28, 2016
1 parent 5484a59 commit 4e19478
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 85 deletions.
2 changes: 1 addition & 1 deletion assets/js/wcsatt-write-panels.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** WooCommerce Subscribe All the Things ***

2016.10.28 - version 1.1.1
* Fix - Resubscribing to products that have been subscription-enabled using SATT.
* Fix - Product Bundles v5.0.0 and Composite Products v3.7.0 support.
* Fix - Inconsistent visibility of the One-Time Shipping option and SATT-enabled products.

2016.06.07 - version 1.1.0
* Important - Template files modified and re-organized under '/cart' and '/single-product' directories. Please update any overridden SATT template files in your tree.
* Fix - Wrong/static prices in the single-product template of Bundles and Composites when Per-Item Pricing is enabled. Totals next to SATT options are now properly updated to a) reflect changes in the configuration of a Bundle/Composite and b) include price discounts/overrides associated with each option.
Expand Down
8 changes: 4 additions & 4 deletions includes/class-wcsatt-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public static function add_cart_item_convert_to_sub_data( $cart_item, $product_i

if ( ! empty( $_POST[ 'convert_to_sub_' . $product_id ] ) ) {
$posted_subscription_scheme_id = wc_clean( $_POST[ 'convert_to_sub_' . $product_id ] );
} elseif ( isset( $cart_item['subscription_resubscribe'] ) ) {
} elseif ( isset( $cart_item[ 'subscription_resubscribe' ] ) ) {
// let's see if we can grab the scheme id from the order item meta
$scheme_id = wc_get_order_item_meta( $cart_item['subscription_resubscribe']['subscription_line_item_id'], '_wcsatt_scheme_id', true );
$scheme_id = wc_get_order_item_meta( $cart_item[ 'subscription_resubscribe' ][ 'subscription_line_item_id' ], '_wcsatt_scheme_id', true );

if ( '' !== $scheme_id ) {
$posted_subscription_scheme_id = $scheme_id;
Expand Down Expand Up @@ -287,8 +287,8 @@ public static function is_supported_product_type( $cart_item ) {
* @param array $cart_item data about the order item
*/
public static function store_cart_item_wcsatt_id( $item_id, $cart_item ) {
if ( isset( $cart_item['wccsub_data']['active_subscription_scheme_id'] ) ) {
wc_add_order_item_meta( $item_id, '_wcsatt_scheme_id', $cart_item['wccsub_data']['active_subscription_scheme_id'] );
if ( isset( $cart_item[ 'wccsub_data' ][ 'active_subscription_scheme_id' ] ) ) {
wc_add_order_item_meta( $item_id, '_wcsatt_scheme_id', $cart_item[ 'wccsub_data' ][ 'active_subscription_scheme_id' ] );
}
}
}
Expand Down
98 changes: 64 additions & 34 deletions includes/class-wcsatt-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function add_force_sub_price_filters() {
/**
* Filter the prices of an entire bundle when it has a single subscription option and one-time purchases are disabled.
*
* @param WC_Product $product
* @param WC_Product $product
* @return boolean
*/
private static function maybe_add_force_sub_price_filters( $product ) {
Expand Down Expand Up @@ -139,9 +139,9 @@ private static function maybe_add_force_sub_price_filters( $product ) {
/**
* Filter the prices of composited products loaded via ajax when the composite has a single subscription option and one-time purchases are disabled.
*
* @param WC_Product $product
* @param int $composite_id
* @param object $composite
* @param WC_Product $product
* @param int $composite_id
* @param object $composite
* @return void
*/
public static function add_composited_force_sub_price_filters( $product, $composite_id, $composite ) {
Expand All @@ -155,14 +155,14 @@ public static function add_composited_force_sub_price_filters( $product, $compos
* Do not filter bundled item prices when the 'override' method is used and the bundle is priced per product.
* In this case, replace only the base prices with the override price values.
*
* @param boolean $allowed
* @param WC_Product $product
* @param array $subscription_scheme
* @param boolean $allowed
* @param WC_Product $product
* @param array $subscription_scheme
* @return boolean
*/
public static function price_filters_allowed( $allowed, $product, $subscription_scheme ) {

if ( $subscription_scheme[ 'subscription_pricing_method' ] === 'override' && self::is_bundle_type_product( $product ) && $product->is_priced_per_product() ) {
if ( $subscription_scheme[ 'subscription_pricing_method' ] === 'override' && self::is_bundle_type_product( $product ) && self::has_individually_priced_bundled_contents( $product ) ) {
$allowed = false;
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public static function filter_get_base_sale_price( $sale_price, $product ) {
/**
* Checks if the passed cart item is a supported bundle type child. Returns the container item key name if yes, or false if not.
*
* @param array $cart_item
* @param array $cart_item
* @return boolean|string
*/
public static function has_bundle_type_container( $cart_item ) {
Expand All @@ -310,7 +310,7 @@ public static function has_bundle_type_container( $cart_item ) {
/**
* Checks if the passed cart item is a supported bundle type container. Returns the child item key name if yes, or false if not.
*
* @param array $cart_item
* @param array $cart_item
* @return boolean|string
*/
public static function has_bundle_type_children( $cart_item ) {
Expand Down Expand Up @@ -340,9 +340,9 @@ public static function is_bundle_type_product( $product ) {
/**
* Add subscription details next to subtotal of per-item-priced bundle-type container cart items.
*
* @param string $subtotal
* @param array $cart_item
* @param string $cart_item_key
* @param string $subtotal
* @param array $cart_item
* @param string $cart_item_key
* @return string
*/
public static function show_ppp_bundle_subtotal_details( $subtotal, $cart_item, $cart_item_key ) {
Expand All @@ -361,9 +361,9 @@ public static function show_ppp_bundle_subtotal_details( $subtotal, $cart_item,
/**
* Bundled items inherit the active subscription scheme id of their parent.
*
* @param string $scheme_id
* @param array $cart_item
* @param array $cart_level_schemes
* @param string $scheme_id
* @param array $cart_item
* @param array $cart_level_schemes
* @return string
*/
public static function set_bundled_item_subscription_scheme_id( $scheme_id, $cart_item, $cart_level_schemes ) {
Expand All @@ -387,9 +387,9 @@ public static function set_bundled_item_subscription_scheme_id( $scheme_id, $car
* - parent is statically priced, or
* - parent has subscription schemes defined at product-level.
*
* @param array $schemes
* @param array $cart_item
* @param string $scope
* @param array $schemes
* @param array $cart_item
* @param string $scope
* @return array
*/
public static function get_bundled_item_schemes( $schemes, $cart_item, $scope ) {
Expand Down Expand Up @@ -417,14 +417,14 @@ public static function get_bundled_item_schemes( $schemes, $cart_item, $scope )
/**
* Sub schemes attached on a Product Bundle should not work if the bundle contains a non-convertible product, such as a "legacy" subscription.
*
* @param array $schemes
* @param WC_Product $product
* @param array $schemes
* @param WC_Product $product
* @return array
*/
public static function get_bundle_product_schemes( $schemes, $product ) {

if ( self::is_bundle_type_product( $product ) ) {
if ( $product->product_type === 'bundle' && $product->contains_sub() ) {
if ( $product->product_type === 'bundle' && self::bundle_contains_subscription( $product ) ) {
$schemes = array();
} elseif ( $product->product_type === 'mix-and-match' && $product->is_priced_per_product() ) {
$schemes = array();
Expand All @@ -437,9 +437,9 @@ public static function get_bundle_product_schemes( $schemes, $product ) {
/**
* Sub schemes attached on a Product Bundle should not work if the bundle contains a non-convertible product, such as a "legacy" subscription.
*
* @param array $schemes
* @param array $cart_item
* @param string $scope
* @param array $schemes
* @param array $cart_item
* @param string $scope
* @return array
*/
public static function get_bundle_schemes( $schemes, $cart_item, $scope ) {
Expand All @@ -448,7 +448,7 @@ public static function get_bundle_schemes( $schemes, $cart_item, $scope ) {

if ( false !== $child_key ) {
$container = $cart_item[ 'data' ];
if ( $container->product_type === 'bundle' && $container->contains_sub() ) {
if ( $container->product_type === 'bundle' && self::bundle_contains_subscription( $container ) ) {
$schemes = array();
} elseif ( $container->product_type === 'mix-and-match' && $container->is_priced_per_product() ) {
$schemes = array();
Expand All @@ -463,9 +463,9 @@ public static function get_bundle_schemes( $schemes, $cart_item, $scope ) {
* - bundle has a static price, or
* - bundle has subscription schemes defined at bundle-level.
*
* @param boolean $show
* @param array $cart_item
* @param string $cart_item_key
* @param boolean $show
* @param array $cart_item
* @param string $cart_item_key
* @return boolean
*/
public static function hide_bundled_item_options( $show, $cart_item, $cart_item_key ) {
Expand All @@ -487,9 +487,9 @@ public static function hide_bundled_item_options( $show, $cart_item, $cart_item_
/**
* Hide bundle container cart item subscription options if bundle is priced per-item.
*
* @param boolean $show
* @param array $cart_item
* @param string $cart_item_key
* @param boolean $show
* @param array $cart_item
* @param string $cart_item_key
* @return boolean
*/
public static function hide_bundle_options( $show, $cart_item, $cart_item_key ) {
Expand All @@ -498,7 +498,7 @@ public static function hide_bundle_options( $show, $cart_item, $cart_item_key )

if ( false !== $child_key ) {
$container = $cart_item[ 'data' ];
if ( $container->is_priced_per_product() ) {
if ( self::has_individually_priced_bundled_contents( $container ) ) {
$show = false;
}
}
Expand All @@ -509,7 +509,7 @@ public static function hide_bundle_options( $show, $cart_item, $cart_item_key )
/**
* True if there are sub schemes inherited from a container.
*
* @param array $cart_item
* @param array $cart_item
* @return boolean
*/
public static function overrides_child_schemes( $cart_item ) {
Expand All @@ -522,6 +522,36 @@ public static function overrides_child_schemes( $cart_item ) {

return $overrides;
}

/**
* WC_Product_Bundle 'contains_sub' back-compat wrapper.
*
* @param WC_Product_Bundle $bundle
* @return boolean
*/
private static function bundle_contains_subscription( $bundle ) {

if ( version_compare( WC_PB()->version, '5.0.0' ) < 0 ) {
return $bundle->contains_sub();
} else {
return $bundle->contains( 'subscription' );
}
}

/**
* WC_Product_Bundle and WC_Product_Composite 'is_priced_per_product' back-compat wrapper.
*
* @param WC_Product $bundle
* @return boolean
*/
private static function has_individually_priced_bundled_contents( $product ) {

if ( 'bundle' === $product->product_type ) {
return version_compare( WC_PB()->version, '5.0.0' ) < 0 ? $product->is_priced_per_product() : $product->contains( 'priced_individually' );
} elseif( 'composite' === $product->product_type ) {
return version_compare( WC_CP()->version, '3.7.0' ) < 0 ? $product->is_priced_per_product() : $product->contains( 'priced_individually' );
}
}
}

WCS_ATT_Integrations::init();
Loading

0 comments on commit 4e19478

Please sign in to comment.