diff --git a/src/include/class-wc-retailcrm-plugin.php b/src/include/class-wc-retailcrm-plugin.php index f5e2dc4..ca05507 100644 --- a/src/include/class-wc-retailcrm-plugin.php +++ b/src/include/class-wc-retailcrm-plugin.php @@ -53,6 +53,12 @@ class WC_Retailcrm_Plugin { } public function activate() { + if (!class_exists( 'WC_Integration' ) ) { + add_action('admin_notices', array(new WC_Integration_Retailcrm(), 'woocommerce_missing_notice')); + + return; + } + if (!class_exists('WC_Retailcrm_Icml')) { require_once (dirname(__FILE__) . '/class-wc-retailcrm-icml.php'); } diff --git a/src/retailcrm.php b/src/retailcrm.php index 49cb19a..b7e7e54 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -21,6 +21,8 @@ if (!class_exists( 'WC_Integration_Retailcrm')) : * Class WC_Integration_Retailcrm */ class WC_Integration_Retailcrm { + const WOOCOMMERCE_SLUG = 'woocommerce'; + const WOOCOMMERCE_PLUGIN_PATH = 'woocommerce/woocommerce.php'; private static $instance; @@ -56,7 +58,30 @@ if (!class_exists( 'WC_Integration_Retailcrm')) : } public function woocommerce_missing_notice() { - echo '

Woocommerce is not installed

'; + if (static::isWooCommerceInstalled()) { + if (!is_plugin_active(static::WOOCOMMERCE_PLUGIN_PATH)) { + echo ' +
+

+ Activate WooCommerce in order to enable retailCRM integration! + + Click here to open plugins manager + +

+
+ '; + } + } else { + echo ' +
+

+ Install WooCommerce in order to enable retailCRM integration! +

+
+ '; + } } public function load_plugin_textdomain() { @@ -74,6 +99,51 @@ if (!class_exists( 'WC_Integration_Retailcrm')) : $integrations[] = 'WC_Retailcrm_Base'; return $integrations; } + + /** + * Returns true if WooCommerce was found in plugin cache + * + * @return bool + */ + private function isWooCommerceInstalled() + { + $plugins = wp_cache_get( 'plugins', 'plugins' ); + + if (!$plugins) { + $plugins = get_plugins(); + } elseif (isset($plugins[''])) { + $plugins = $plugins['']; + } + + if (!isset($plugins[static::WOOCOMMERCE_PLUGIN_PATH])) { + return false; + } + + return true; + } + + /** + * Generate plugin installation url + * + * @param $pluginSlug + * + * @return string + */ + private function generatePluginInstallationUrl($pluginSlug) + { + $action = 'install-plugin'; + + return wp_nonce_url( + add_query_arg( + array( + 'action' => $action, + 'plugin' => $pluginSlug + ), + admin_url( 'update.php' ) + ), + $action.'_'.$pluginSlug + ); + } } if (!class_exists('WC_Retailcrm_Plugin')) {