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

General Onboarding: Switch to Commerce flow if Top Priority is Selling #214

Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 11 additions & 18 deletions includes/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public static function current_plan() {
}
}

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

return array(
'flow' => Flows::get_default_flow(),
'subtype' => null,
Expand All @@ -93,24 +102,8 @@ public static function current_plan() {
* @return string
*/
public static function current_flow() {

$current_flow = Flows::get_flow_from_params();
if ( false !== $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 ) {
return $current_flow;
}

return Flows::get_default_flow();
$current_plan = self::current_plan();
return $current_plan['flow'];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions includes/Data/Flows.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data;

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

/**
Expand Down Expand Up @@ -261,4 +262,16 @@ public static function get_flow_from_plan_subtype( $plan_subtype ) {
}
return false;
}
/**
* Get the corresponding flow from the top priority in flow data.
*
* @return string|boolean
*/
public static function get_flow_from_top_priority() {
$flow_data = FlowService::read_data_from_wp_option();
if ( $flow_data && isset( $flow_data['data']['topPriority']['priority1'] ) && 'selling' === $flow_data['data']['topPriority']['priority1'] ) {
return true === self::get_flows()['ecommerce'] ? 'ecommerce' : false;
}
return false;
}
}
14 changes: 12 additions & 2 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ final class Plugins {
'path' => 'jetpack/jetpack.php',
),
'woocommerce' => array(
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
'post_install_callback' => array( __CLASS__, 'wc_prevent_redirect_on_activation' ),
),
'wordpress-seo' => array(
'approved' => true,
Expand Down Expand Up @@ -420,4 +421,13 @@ public static function get_init() {
return $init_list;
}

/**
* Prevent redirect to woo wizard after activation of woocommerce.
*
* @return void
*/
public static function wc_prevent_redirect_on_activation() {
\delete_transient( '_wc_activation_redirect' );
}

}
55 changes: 41 additions & 14 deletions includes/Data/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Onboarding\Services\ThemeInstaller;

/**
* Class Preview
*/
final class Preview {

/**
* Convert boolean to plugin/theme status.
*
* @param boolean $boolean The boolean value.
* @return string
*/
private static function boolean_to_status( $boolean ) {
return $boolean ? 'activated' : 'init';
return $boolean ? 'activated' : 'init';
}

/**
* Map of pre requisites to show the live preview successfully for a flow.
*
* @return array
*/
private static function pre_requisites() {
$theme_map = Themes::get();
return array(
Expand All @@ -30,21 +43,35 @@ private static function pre_requisites() {
);
}

public static function get_pre_requisites() {
$pre_requisites = self::pre_requisites();
return isset( $pre_requisites[ Data::current_flow() ] ) ? $pre_requisites[ Data::current_flow() ] : array();
/**
* Get the pre requisites for a given flow.
*
* @param string $flow A valid Onboarding flow.
* @return array
*/
public static function get_pre_requisites( $flow = null ) {
$pre_requisites = self::pre_requisites();
if ( ! isset( $flow ) ) {
$flow = Data::current_flow();
}
return isset( $pre_requisites[ $flow ] ) ? $pre_requisites[ $flow ] : array();
}

/**
* Get all the settings necessary to load the live preview
*
* @return array
*/
public static function get_settings() {
$block_editor_context = new \WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings = array(
'siteUrl' => \site_url(),
);
$block_editor_context = new \WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings = array(
'siteUrl' => \site_url(),
);

return array(
'settings' => \get_block_editor_settings( $custom_settings, $block_editor_context ),
'globalStyles' => \wp_get_global_styles(),
'preRequisites' => self::get_pre_requisites(),
);
return array(
'settings' => \get_block_editor_settings( $custom_settings, $block_editor_context ),
'globalStyles' => \wp_get_global_styles(),
'preRequisites' => self::get_pre_requisites(),
);
}
}
Loading