Skip to content

Commit

Permalink
Merge pull request #192 from newfold-labs/add/PRESS2-682-support-craz…
Browse files Browse the repository at this point in the history
…ydomains

Support Crazy Domains
  • Loading branch information
arunshenoy99 authored Apr 17, 2023
2 parents bde619b + 4a3f6cc commit 0f3cd30
Show file tree
Hide file tree
Showing 64 changed files with 996 additions and 509 deletions.
88 changes: 88 additions & 0 deletions includes/Data/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function get_brands() {
'accountUrl' => 'https://my.bluehost.com',
'domainsUrl' => 'https://my.bluehost.com/hosting/app?lil=1#/domains',
'emailUrl' => 'https://my.bluehost.com/hosting/app?lil=1#/email-office',
'pluginDashboardPage' => \admin_url( 'admin.php?page=bluehost' ),
'phoneNumbers' => array(
'sales' => '844-303-1730',
'support' => '888-401-4678',
Expand Down Expand Up @@ -66,6 +67,9 @@ public static function get_brands() {
'utm_medium' => 'brand-plugin',
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
),
),
'bluehost-india' => array(
'brand' => 'bluehost-india',
Expand All @@ -82,6 +86,7 @@ public static function get_brands() {
'accountUrl' => 'https://my.bluehost.in',
'domainsUrl' => 'https://my.bluehost.in/hosting/app?lil=1#/domains',
'emailUrl' => 'https://my.bluehost.in/hosting/app?lil=1#/email-office',
'pluginDashboardPage' => \admin_url( 'admin.php?page=bluehost' ),
'phoneNumbers' => array(
'support' => '1800-419-4426',
),
Expand Down Expand Up @@ -115,6 +120,9 @@ public static function get_brands() {
'utm_medium' => 'brand-plugin',
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
),
),
'webcom' => array(
'brand' => 'webcom',
Expand Down Expand Up @@ -166,7 +174,87 @@ public static function get_brands() {
'utm_medium' => '',
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
),
),
'crazy-domains' => array(
'brand' => 'crazy-domains',
'name' => 'Crazy Domains',
'url' => 'https://www.crazydomains.com',
'knowledgeBaseUrl' => 'https://www.crazydomains.com/learn/online-academy/',
'helpUrl' => 'https://www.crazydomains.com/help',
'blogUrl' => 'https://www.crazydomains.com/learn/',
'facebookUrl' => 'https://www.facebook.com/crazydomains/',
'twitterName' => '@crazydomains',
'twitterUrl' => 'https://twitter.com/crazydomains',
'youtubeUrl' => 'https://www.youtube.com/user/CrazyDomains',
'linkedinUrl' => '',
'accountUrl' => 'https://www.crazydomains.com/my-account/home/',
'domainsUrl' => '',
'emailUrl' => 'https://www.crazydomains.com/contact/',
'pluginDashboardPage' => \admin_url( 'admin.php?page=crazy-domains' ),
'phoneNumbers' => array(
'support' => '2135592459',
),
'hireExpertsInfo' => array(
'defaultLink' => 'https://www.crazydomains.com/help/',
'fragment' => '',
'queryParameters' => array(
'utm_source' => 'wp-onboarding',
'utm_medium' => 'brand-plugin',
'utm_campaign' => 'wp-setup',
),
),
'expertsInfo' => array(
'defaultLink' => 'https://www.crazydomains.com/help/',
'queryParams' => array(
'utm_source' => 'wp-onboarding',
'utm_medium' => 'brand-plugin',
),
),
'fullServiceCreativeTeamInfo' => array(
'defaultLink' => 'https://www.crazydomains.com/help/',
'fragment' => '',
'queryParams' => array(
'utm_source' => 'wp-onboarding',
'utm_medium' => 'brand-plugin',
),
),
'techSupportInfo' => array(
'defaultLink' => 'https://www.crazydomains.com/contact/',
'queryParams' => array(
'utm_source' => 'wp-onboarding',
'utm_medium' => 'brand-plugin',
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
'views' => array(
'sidebar' => array(
'illustration' => array(
'shown' => false,
),
),
),
),
),
);
}

/**
* Sets the hosting brand for which Onboarding is active.
*
* @param array $container The brand plugin container.
* @return void
*/
public static function set_current_brand( $container ) {
if ( ! defined( 'NFD_ONBOARDING_PLUGIN_BRAND' ) ) {
$brand = $container->plugin()->brand;
if ( empty( $brand ) ) {
$brand = 'newfold';
}
define( 'NFD_ONBOARDING_PLUGIN_BRAND', sanitize_title_with_dashes( str_replace( '_', '-', $brand ) ) );
}
}
}
30 changes: 11 additions & 19 deletions includes/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,14 @@ public static function runtime() {
/**
* Establish brand to apply to Onboarding experience.
*
* [TODO]: Pull brand from container.
*
* @return array
*/
public static function current_brand() {

$brand = \get_option( Options::get_option_name( 'brand', false ), 'newfold' );
// This case arises when the option mm_brand exists but has an empty string as it's value.
if ( empty( $brand ) ) {
$brand = 'newfold';
}
$brand = \apply_filters( 'nfd_module_onboarding_brand', sanitize_title_with_dashes( str_replace( '_', '-', $brand ) ) );

$brands = Brands::get_brands();

return array_key_exists( $brand, $brands ) ? $brands[ $brand ] : array( 'brand' => $brand );
return array_key_exists( NFD_ONBOARDING_PLUGIN_BRAND, $brands ) ?
$brands[ NFD_ONBOARDING_PLUGIN_BRAND ] :
array( 'brand' => NFD_ONBOARDING_PLUGIN_BRAND );
}


Expand All @@ -60,11 +52,11 @@ public static function current_plan() {

$current_flow = Flows::get_flow_from_customer_data( $customer_data );
if ( false !== $current_flow ) {
return array(
'flow' => $current_flow,
'subtype' => $customer_data['plan_subtype'],
'type' => $customer_data['plan_type'],
);
return array(
'flow' => $current_flow,
'subtype' => $customer_data['plan_subtype'],
'type' => $customer_data['plan_type'],
);
}

$current_flow = Flows::get_flow_from_params();
Expand Down Expand Up @@ -128,9 +120,9 @@ public static function current_flow() {
*/
public static function customer_data() {
if ( class_exists( 'NewfoldLabs\WP\Module\CustomerBluehost\CustomerBluehost' ) ) {
return CustomerBluehost::collect();
return CustomerBluehost::collect();
}
return array();
return array();
}

} // END \NewfoldLabs\WP\Module\Onboarding\Data()
}
14 changes: 14 additions & 0 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ final class Plugins {
),
'wc_priority' => array(),
),
'crazy-domains' => array(
'wc_priority' => array(
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,
),
),
),
),
);

Expand Down
107 changes: 72 additions & 35 deletions includes/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

use NewfoldLabs\WP\Module\Onboarding\Data\Data;
use NewfoldLabs\WP\Module\Onboarding\Data\Flows;

use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\Data\Brands;
use NewfoldLabs\WP\ModuleLoader\ModuleRegistry;
use function NewfoldLabs\WP\ModuleLoader\activate;
use function NewfoldLabs\WP\ModuleLoader\deactivate;
use function NewfoldLabs\WP\ModuleLoader\container;


/**
Expand All @@ -18,24 +20,23 @@ class ModuleController {
* Initialize the Module Controller functionality.
*/
public static function init() {
// Check the conditions after the step_theme loads as only after that the moudle had been registered prior
add_action( 'after_setup_theme', array( __CLASS__, 'module_switcher' ), 10, 0 );
// Enable/Disable the module after_setup_theme.
\add_action( 'after_setup_theme', array( __CLASS__, 'module_switcher' ), 10, 0 );
}

/**
* Check if the user is a valid Ecommerce and subsequently enable/disable modules
* Enable/Disable Onboarding based on certain checks.
*/
public static function module_switcher() {

$module_name = 'onboarding';
$customer_data = Data::customer_data();
$module_name = 'onboarding';

// Sample data for Testing
// $customer_data['plan_subtype'] = 'wc_standard';
// $customer_data['signup_date'] = '2022-08-18T15:30:00.000Z';
// Set brand context for the module.
Brands::set_current_brand( container() );
$customer_data = Data::customer_data();

// Check if he is a Non-Ecom Cust and Disable Redirect and Module
if ( ! self::is_ecom_customer( $customer_data ) ) {
if ( ! self::is_new_commerce_signup( $customer_data ) ) {

// Check if the Module Does Exist
if ( ModuleRegistry::get( $module_name ) ) {
Expand All @@ -59,43 +60,79 @@ public static function module_switcher() {
}

/**
* Get the current customer data using the Bluehost customer data module.
* Get signup date of the install.
*
* @param array $customer_data The customer data to be parsed.
* @return boolean
* @param array $customer_data The customer data to be checked for signup date.
* @return string|boolean
*/
public static function is_ecom_customer( $customer_data ) {
public static function get_signup_date( $customer_data ) {
// Get the signup_date from customer data.
if ( isset( $customer_data['signup_date'] ) ) {
return gmdate( 'Y-m-d H:i:s', strtotime( $customer_data['signup_date'] ) );
}

// Get the signup_date from the container's install_date.
if ( ! empty( container()->plugin()->install_date ) ) {
return gmdate( 'Y-m-d H:i:s', container()->plugin()->install_date );
}

// Get the signup_date from the mm_install_date option.
$install_date = \get_option( Options::get_option_name( 'install_date', false ), false );
if ( false !== $install_date ) {
return gmdate( 'Y-m-d H:i:s', strtotime( $install_date ) );
}

return false;
}

/**
* Determine if the install is a new commerce signup
*
* @param array $customer_data The site's customer data.
* @return boolean
*/
public static function is_new_commerce_signup( $customer_data ) {
// Determine if the flow=ecommerce param is set.
if ( isset( $_GET['flow'] ) && 'ecommerce' === \sanitize_text_field( $_GET['flow'] ) ) {
return true;
}

// August 18
$new_cust_date = gmdate( 'Y-m-d H:i:s', strtotime( '2022-08-18T15:30:00.000Z' ) );

if ( isset( $customer_data['signup_date'] ) ) {
// Determine if the install is on a commerce plan (or) has Woocommerce active (commerce priority).
$is_commerce = false;
if ( isset( $customer_data['plan_subtype'] ) ) {
$is_commerce = Flows::is_ecommerce_plan( $customer_data['plan_subtype'] );
}
if ( ! $is_commerce ) {
$is_commerce = Flows::is_commerce_priority();
}
if ( ! $is_commerce ) {
return false;
}

// Convert the Customer Signup Date to a Php known format
$cust_signup_date = gmdate( 'Y-m-d H:i:s', strtotime( $customer_data['signup_date'] ) );
/*
Get the net new signup date threshold from the brand configuration.
As a safety measure, return false if a threshold is not set for a particular brand.
*/
$current_brand = Data::current_brand();
if ( ! isset( $current_brand['config']['net_new_signup_date_threshold'] ) ) {
return false;
}
$net_new_signup_date_threshold = gmdate( 'Y-m-d H:i:s', strtotime( $current_brand['config']['net_new_signup_date_threshold'] ) );

// Check if the Customer is a new Customer
$is_new_cust = $cust_signup_date >= $new_cust_date;
// Get the actual signup date of the install.
$signup_date = self::get_signup_date( $customer_data );

// Check if the Customer has an Ecom Plan
$has_ecom_plan = false;
if ( isset( $customer_data['plan_subtype'] ) ) {
$has_ecom_plan = Flows::is_ecommerce_plan( $customer_data['plan_subtype'] );
}
if ( ! $has_ecom_plan ) {
$has_ecom_plan = Flows::is_commerce_priority();
}
// As a safety measure, return false if a signup date cannot be determined.
if ( false === $signup_date ) {
return false;
}

if ( $has_ecom_plan && $is_new_cust ) {
return true;
}
// Determine whether the commerce install is a net new signup.
$is_net_new_signup = $signup_date >= $net_new_signup_date_threshold;
if ( ! $is_net_new_signup ) {
return false;
}

// If the Customer is not a Ecommerce Customer or is an Old Customer
return false;
return true;
}
}
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added src/Brands/crazy-domains/full-service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Brands/crazy-domains/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0f3cd30

Please sign in to comment.