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