Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.62% |
41 / 42 |
|
100.00% |
12 / 12 |
CRAP | |
100.00% |
1 / 1 |
| Crm | |
100.00% |
40 / 40 |
|
100.00% |
12 / 12 |
18 | |
100.00% |
1 / 1 |
| get_name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_title | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_long_description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_features | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| get_pricing_for_ui | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| do_product_specific_activation | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| get_post_activation_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_manage_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| has_paid_plan_for_product | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
| get_paid_bundles_that_include_product | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| is_upgradable_by_bundle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Boost product |
| 4 | * |
| 5 | * @package my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack\Products; |
| 9 | |
| 10 | use Automattic\Jetpack\My_Jetpack\Product; |
| 11 | use Automattic\Jetpack\My_Jetpack\Wpcom_Products; |
| 12 | use WP_Error; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class responsible for handling the CRM product |
| 20 | */ |
| 21 | class Crm extends Product { |
| 22 | |
| 23 | /** |
| 24 | * The product slug |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | public static $slug = 'crm'; |
| 29 | |
| 30 | /** |
| 31 | * The filename (id) of the plugin associated with this product. If not defined, it will default to the Jetpack plugin |
| 32 | * |
| 33 | * @var string |
| 34 | */ |
| 35 | public static $plugin_filename = array( |
| 36 | 'zero-bs-crm/ZeroBSCRM.php', |
| 37 | 'crm/ZeroBSCRM.php', |
| 38 | ); |
| 39 | |
| 40 | /** |
| 41 | * The slug of the plugin associated with this product. If not defined, it will default to the Jetpack plugin |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | public static $plugin_slug = 'zero-bs-crm'; |
| 46 | |
| 47 | /** |
| 48 | * The category of the product |
| 49 | * |
| 50 | * @var string |
| 51 | */ |
| 52 | public static $category = 'management'; |
| 53 | |
| 54 | /** |
| 55 | * Whether this product requires a user connection |
| 56 | * |
| 57 | * @var string |
| 58 | */ |
| 59 | public static $requires_user_connection = false; |
| 60 | |
| 61 | /** |
| 62 | * Whether this product has a free offering |
| 63 | * |
| 64 | * @var bool |
| 65 | */ |
| 66 | public static $has_free_offering = true; |
| 67 | |
| 68 | /** |
| 69 | * CRM has a standalone plugin |
| 70 | * |
| 71 | * @var bool |
| 72 | */ |
| 73 | public static $has_standalone_plugin = true; |
| 74 | |
| 75 | /** |
| 76 | * Get the product name |
| 77 | * |
| 78 | * @return string |
| 79 | */ |
| 80 | public static function get_name() { |
| 81 | return 'CRM'; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get the product title |
| 86 | * |
| 87 | * @return string |
| 88 | */ |
| 89 | public static function get_title() { |
| 90 | return 'Jetpack CRM'; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the internationalized product description |
| 95 | * |
| 96 | * @return string |
| 97 | */ |
| 98 | public static function get_description() { |
| 99 | return __( 'All of the tools you need to grow your business.', 'jetpack-my-jetpack' ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get the internationalized product long description |
| 104 | * |
| 105 | * @return string |
| 106 | */ |
| 107 | public static function get_long_description() { |
| 108 | return __( 'Build better relationships with your customers and grow your business.', 'jetpack-my-jetpack' ); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the internationalized features list |
| 113 | * |
| 114 | * @return array CRM features list |
| 115 | */ |
| 116 | public static function get_features() { |
| 117 | return array( |
| 118 | __( 'Manage unlimited contacts', 'jetpack-my-jetpack' ), |
| 119 | __( 'Manage billing and create invoices', 'jetpack-my-jetpack' ), |
| 120 | __( 'Fully integrated with WordPress & WooCommerce', 'jetpack-my-jetpack' ), |
| 121 | __( 'Infinitely customizable with integrations and extensions', 'jetpack-my-jetpack' ), |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Get the product princing details |
| 127 | * |
| 128 | * @return array Pricing details |
| 129 | */ |
| 130 | public static function get_pricing_for_ui() { |
| 131 | // We are hard coding pricing info for CRM because it is not available to us through the CRM API. |
| 132 | return array( |
| 133 | 'available' => true, |
| 134 | 'is_free' => false, |
| 135 | 'full_price' => 132, |
| 136 | 'discount_price' => 132, |
| 137 | 'is_introductory_offer' => false, |
| 138 | 'product_term' => 'year', |
| 139 | 'introductory_offer' => null, |
| 140 | // CRM is only sold in USD |
| 141 | 'currency_code' => 'USD', |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Perform the CRM specific activation routines. |
| 147 | * |
| 148 | * @param bool|WP_Error $current_result Is the result of the top level activation actions. |
| 149 | * @return bool|WP_Error |
| 150 | */ |
| 151 | public static function do_product_specific_activation( $current_result ) { |
| 152 | if ( is_wp_error( $current_result ) ) { |
| 153 | return $current_result; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * CRM sets this on activation to send the next admin page load to its own full-screen |
| 158 | * setup wizard — which, activated from here, is the My Jetpack screen the owner is still on. |
| 159 | */ |
| 160 | delete_option( 'jpcrm_do_redirect' ); |
| 161 | |
| 162 | return $current_result; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Get the URL the user is taken after activating the product |
| 167 | * |
| 168 | * @return ?string |
| 169 | */ |
| 170 | public static function get_post_activation_url() { |
| 171 | return admin_url( 'admin.php?page=zerobscrm-plugin' ); // Welcome page. |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get the URL where the user manages the product |
| 176 | * |
| 177 | * @return ?string |
| 178 | */ |
| 179 | public static function get_manage_url() { |
| 180 | return admin_url( 'admin.php?page=zerobscrm-dash' ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Checks whether the current plan (or purchases) of the site already supports the product |
| 185 | * CRM is available as part of Jetpack Complete |
| 186 | * |
| 187 | * @return boolean |
| 188 | */ |
| 189 | public static function has_paid_plan_for_product() { |
| 190 | $purchases_data = Wpcom_Products::get_site_current_purchases(); |
| 191 | if ( is_wp_error( $purchases_data ) ) { |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | // TODO: check if CRM has a separate plan |
| 196 | |
| 197 | if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) { |
| 198 | foreach ( $purchases_data as $purchase ) { |
| 199 | if ( str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ) { |
| 200 | return true; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Get the product-slugs of the paid bundles/plans that this product/module is included in. |
| 210 | * |
| 211 | * @return array |
| 212 | */ |
| 213 | public static function get_paid_bundles_that_include_product() { |
| 214 | return array( |
| 215 | 'jetpack_complete', |
| 216 | 'jetpack_complete_monthly', |
| 217 | 'jetpack_complete_bi_yearly', |
| 218 | ); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Return product bundles list |
| 223 | * that supports the product. |
| 224 | * |
| 225 | * @return boolean|array Products bundle list. |
| 226 | */ |
| 227 | public static function is_upgradable_by_bundle() { |
| 228 | return array( 'complete' ); |
| 229 | } |
| 230 | } |