Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to handle commerce plan and shared commerce priority customers #164

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion includes/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,28 @@ public static function current_plan() {
}

$current_flow = Flows::get_flow_from_params();
if ( false !== $current_flow ) {
return array(
'flow' => $current_flow,
'subtype' => Flows::is_commerce_priority() ? 'wc_priority' : null,
'type' => null,
);
}

$current_flow = Flows::get_flow_from_plugins();
if ( false !== $current_flow ) {
switch ( $current_flow ) {
case 'ecommerce':
return array(
'flow' => 'ecommerce',
'subtype' => 'wc_priority',
'type' => null,
);
}
}

return array(
'flow' => ( false !== $current_flow ) ? $current_flow : Flows::get_default_flow(),
'flow' => Flows::get_default_flow(),
'subtype' => null,
'type' => null,
);
Expand All @@ -87,6 +107,11 @@ public static function current_flow() {
return $current_flow;
}

$current_flow = Flows::get_flow_from_plugins();
if ( false !== $current_flow ) {
return $current_flow;
}

$customer_data = self::customer_data();
$current_flow = Flows::get_flow_from_customer_data( $customer_data );
if ( false !== $current_flow ) {
Expand Down
26 changes: 26 additions & 0 deletions includes/Data/Flows.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;

/**
* Contains Onboarding Flow information.
*/
Expand Down Expand Up @@ -184,6 +186,18 @@ public static function is_ecommerce_plan( $plan ) {
return false;
}

/**
* Checks if an install is of type commerce priority.
*
* @return boolean
*/
public static function is_commerce_priority() {
if ( self::get_flow_from_plugins() === 'ecommerce' ) {
return true;
}
return false;
}

/**
* Get the type of flow from the flow query param or the flow preset option.
*
Expand All @@ -208,6 +222,18 @@ public static function get_flow_from_params() {
return false;
}

/**
* Gets the flow based on the plugins installed/activated.
*
* @return string|boolean
*/
public static function get_flow_from_plugins() {
if ( PluginInstaller::exists( 'woocommerce', true ) ) {
return 'ecommerce';
}
return false;
}

/**
* Get the flow type given customer data in a particular shape.
*
Expand Down
117 changes: 80 additions & 37 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
* List of Plugin Slugs/URLs/Domains
*/
final class Plugins {

/*
A value of true indicates that the slug/url/domain has been approved.
A value of null indicates that the slug/url/domain has not been approved
(or) has been temporarily deactivated.
*/

/**
* A value of true indicates that the slug/url/domain has been approved.
* A value of null indicates that the slug/url/domain has not been approved
* (or) has been temporarily deactivated.
*
* @var array
*/
protected static $wp_slugs = array(
'jetpack' => array(
'jetpack' => array(
'approved' => true,
'path' => 'jetpack/jetpack.php',
),
'woocommerce' => array(
'woocommerce' => array(
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
),
'wordpress-seo' => array(
'wordpress-seo' => array(
'approved' => true,
'path' => 'wordpress-seo/wp-seo.php',
),
'wpforms-lite' => array(
'wpforms-lite' => array(
'approved' => true,
'path' => 'wpforms-lite/wpforms.php',
),
'google-analytics-for-wordpress' => array(
'google-analytics-for-wordpress' => array(
'approved' => true,
'path' => 'google-analytics-for-wordpress/googleanalytics.php',
),
'optinmonster' => array(
'optinmonster' => array(
'approved' => true,
'path' => 'optinmonster/optin-monster-wp-api.php',
),
'yith-woocommerce-ajax-search' => array(
'yith-woocommerce-ajax-search' => array(
'approved' => true,
'path' => 'yith-woocommerce-ajax-search/init.php',
),
'creative-mail-by-constant-contact' => array(
'creative-mail-by-constant-contact' => array(
'approved' => true,
'path' => 'creative-mail-by-constant-contact/creative-mail-plugin.php',
),
Expand Down Expand Up @@ -100,18 +100,19 @@ final class Plugins {
),
);

/**
* @var array Initial plugins to be installed classified based on the hosting plan.
*
* Key 'default' contains a list of default plugins to be installed irrespective of the plan.
* Key <flow> contains a Key 'default' and a list of Key <subtype>'s.
* Key <flow> => 'default' contains a list of default plugin installs for <flow>.
* Key <flow> => <subtype> contains a list of plugins to be installed for a particular <subtype>.
*
* The final queue of Plugins to be installed makes use of a max heap and hence the greater the number the earlier
* a Plugin will be placed for install in the queue. This will also allow us to
* prevent entering negative numbers when queueing a plugin for earlier installs.
*/
/**
* Initial plugins to be installed classified based on the hosting plan.
* Key 'default' contains a list of default plugins to be installed irrespective of the plan.
* Key <flow> contains a Key 'default' and a list of Key <subtype>'s.
* Key <flow> => 'default' contains a list of default plugin installs for <flow>.
* Key <flow> => <subtype> contains a list of plugins to be installed for a particular <subtype>.
*
* The final queue of Plugins to be installed makes use of a max heap and hence the greater the number the earlier
* a Plugin will be placed for install in the queue. This will also allow us to
* prevent entering negative numbers when queueing a plugin for earlier installs.
*
* @var array
*/
protected static $init_list = array(
'default' => array(
array(
Expand Down Expand Up @@ -146,12 +147,14 @@ final class Plugins {
),
),
'ecommerce' => array(
'default' => array(
'default' => array(
array(
'slug' => 'woocommerce',
'activate' => true,
'priority' => 260,
),
),
'wc_standard' => array(
array(
'slug' => 'nfd_slug_yith_woocommerce_customize_myaccount_page',
'activate' => true,
Expand All @@ -178,41 +181,82 @@ final class Plugins {
'priority' => 258,
),
),
'wc_premium' => array(
'wc_premium' => array(
array(
'slug' => 'nfd_slug_yith_woocommerce_customize_myaccount_page',
'activate' => true,
'priority' => 257,
),
array(
'slug' => 'nfd_slug_yith_woocommerce_gift_cards',
'activate' => true,
'priority' => 100,
),
array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'activate' => true,
'priority' => 80,
),
array(
'slug' => 'nfd_slug_yith_shippo_shippings_for_woocommerce',
'activate' => true,
'priority' => 259,
),
array(
'slug' => 'nfd_slug_yith_paypal_payments_for_woocommerce',
'activate' => true,
'priority' => 258,
),
array(
'slug' => 'nfd_slug_ecomdash_wordpress_plugin',
'activate' => true,
'priority' => 20,
),
),
'wc_priority' => array(),
),
);

// [TODO] Think about deprecating this approach and move to nfd_slugs for url based installs.
// [TODO] Think about deprecating this approach and move to nfd_slugs for url based installs.
/**
* Contains a whitelist of zip url's.
*
* @var array
*/
protected static $urls = array(
'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.8.5.3.zip' => true,
);

/**
* Contains a list of approved domains for zip based installs.
*
* @var array
*/
protected static $domains = array(
'downloads.wordpress.org' => true,
'nonapproveddomain.com' => null,
);

/**
* Returns a list of whitelisted WordPress Plugin slugs.
*
* @return array
*/
public static function get_wp_slugs() {
return self::$wp_slugs;
}

/**
* Returns a list of whitelisted Plugin URL's.
*
* @return array
*/
public static function get_urls() {
return self::$urls;
}

/**
* Returns a list of whitelisted Plugin URL domains.
*
* @return array
*/
public static function get_domains() {
Expand Down Expand Up @@ -240,7 +284,7 @@ public static function get() {
*/
public static function get_squashed() {
return array_merge(
array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ,
array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ),
array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) )
);
}
Expand All @@ -260,14 +304,13 @@ public static function get_approved() {
}

/**
* @param array $value
*
* Checks if $value has been approved.
* Checks if a Plugin slug has been approved.
*
* @param array $value The Plugin slug that will be checked.
* @return boolean
*/
private static function check_approved( $value ) {
return $value['approved'] === true;
return true === $value['approved'];
}

/**
Expand All @@ -284,7 +327,7 @@ public static function get_init() {
if ( isset( self::$init_list[ $plan_flow ]['default'] ) ) {
$init_list = array_merge( $init_list, self::$init_list[ $plan_flow ]['default'] );
}
if ( $plan_subtype !== 'default' && isset( self::$init_list[ $plan_flow ][ $plan_subtype ] ) ) {
if ( 'default' !== $plan_subtype && isset( self::$init_list[ $plan_flow ][ $plan_subtype ] ) ) {
$init_list = array_merge( $init_list, self::$init_list[ $plan_flow ][ $plan_subtype ] );
}
}
Expand Down
Loading