Plugin Directory

Changeset 1872868


Ignore:
Timestamp:
05/11/2018 07:24:47 PM (8 years ago)
Author:
leadbi
Message:

add woo commerce integration

Location:
leadbi/trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • leadbi/trunk/admin/Admin.php

    r1736960 r1872868  
    2323     * Implement the init hook
    2424     */
    25      public function init(){
     25    public function init(){
    2626        // Empty for now
    2727    }
     
    6262
    6363    /**
     64     * Check if wooCommerce is installed and active
     65     */
     66    private function isWooCommerceActive(){
     67        return Info::isWooCommerceActive();
     68    }
     69
     70    /**
    6471     * Render the view using MVC pattern.
    6572     */
     
    94101        }
    95102
    96         if(!isset($_REQUEST['connected']) || !isset($_REQUEST['websiteId'])  || !isset($_REQUEST['websiteDomain'])){
    97             echo "Unexpected input!";
    98             die();
     103        $newOptions = [];
     104
     105        if(isset($_REQUEST['connected'])){
     106            $newOptions['connected'] = $_REQUEST['connected'];
    99107        }
    100108
    101         $connected = isset($_REQUEST['connected']) ? $_REQUEST['connected'] : null;
    102         $websiteId = isset($_REQUEST['websiteId']) ? $_REQUEST['websiteId'] : null;
    103         $websiteDomain = isset($_REQUEST['websiteDomain']) ? $_REQUEST['websiteDomain']: null;
     109        if(isset($_REQUEST['websiteId'])){
     110            $newOptions['websiteId'] = $_REQUEST['websiteId'];
     111        }
     112
     113        if(isset($_REQUEST['websiteDomain'])){
     114            $newOptions['websiteDomain'] = $_REQUEST['websiteDomain'];
     115        }
     116
     117        if(isset($_REQUEST['wooCommerceEnabled'])){
     118            $newOptions['wooCommerceEnabled'] = $_REQUEST['wooCommerceEnabled'];
     119        }
    104120
    105121        $option_name = Info::OPTION_NAME;
    106        
    107         $newOptions = [
    108             'connected' => $connected,
    109             'websiteId' => $websiteId,
    110             'websiteDomain' => $websiteDomain,
    111         ];
    112122
    113123        $options = get_option($option_name);
  • leadbi/trunk/admin/js/leadbi-options.js

    r1736960 r1872868  
    4141                websiteId: data.websiteId,
    4242                websiteDomain: data.websiteDomain,
     43                wooCommerceEnabled: null,
    4344                nonce: nonce
    4445            },
     
    5657    // disconnect button
    5758    jQuery(document).on('click', '#leadbi-disconnect', function () {
    58         console.log(1);
    5959        return jQuery.ajax({
    6060            type: "post",
     
    6666                websiteId: null,
    6767                websiteDomain: null,
     68                wooCommerceEnabled: null,
    6869                nonce: nonce
    6970            },
     
    7879    });
    7980
     81    /**
     82     * Handle enable woocommerce integration
     83     */
     84    jQuery(document).on('click', '#leadbi-disable-woocommerce', function () {
     85        return jQuery.ajax({
     86            type: "post",
     87            dataType: "json",
     88            url: leadbiAjaxUpdate.ajaxurl,
     89            data: {
     90                action: "leadbi_update_options",
     91                wooCommerceEnabled: 0,
     92                nonce: nonce
     93            },
     94            success: function (response) {
     95                if (response.type == "success") {
     96                    window.location.reload();
     97                } else {
     98                    alert("Failed to disable woocommerce")
     99                }
     100            },
     101            error: function () {
     102                alert("Failed to disable woocommerce")
     103            }
     104        });
     105    });
     106
     107    /**
     108     * Handle disable woocommerce integration
     109     */
     110    jQuery(document).on('click', '#leadbi-enable-woocommerce', function () {
     111        return jQuery.ajax({
     112            type: "post",
     113            dataType: "json",
     114            url: leadbiAjaxUpdate.ajaxurl,
     115            data: {
     116                action: "leadbi_update_options",
     117                wooCommerceEnabled: 1,
     118                nonce: nonce
     119            },
     120            success: function (response) {
     121                if (response.type == "success") {
     122                    window.location.reload();
     123                } else {
     124                    alert("Failed to enable woocommerce")
     125                }
     126            },
     127            error: function () {
     128                alert("Failed to enable woocommerce")
     129            }
     130        });
     131    });
     132
    80133});
  • leadbi/trunk/admin/partials/view.php

    r1736960 r1872868  
    44    <div>
    55        <h1 class="wp-heading-inline">LeadBI for WordPress (<?php echo $settings['websiteDomain'] ?>)</h1>
    6         <button class="button button-primary" style="float: right;margin-top: 10px" id="leadbi-disconnect" type="button">Disconnect</button>
     6        <button class="button button-primary" style="float: right;margin-top: 10px; margin-left: 10px;" id="leadbi-disconnect" type="button">Disconnect</button>
     7
     8        <?php if($this->isWooCommerceActive()) : ?>
     9            <?php if(isset($settings['wooCommerceEnabled']) && $settings['wooCommerceEnabled']) : ?>
     10                <button class="button button-primary" style="float: right;margin-top: 10px" id="leadbi-disable-woocommerce" type="button">Disable WooCommerce</button>
     11            <?php else: ?>
     12                <button class="button button-primary" style="float: right;margin-top: 10px" id="leadbi-enable-woocommerce" type="button">Enable WooCommerce</button>
     13            <?php endif; ?>
     14        <?php endif; ?>
    715    </div>
    816   
  • leadbi/trunk/frontend/Frontend.php

    r1736960 r1872868  
    1515        $this->settings = get_option($this->option_name);
    1616        $this->settings_group = $this->option_name.'_group';
     17        $this->wooCommerce = null;
    1718    }
    1819
     
    2122    }
    2223
     24    /**
     25     * Load frontend integrations
     26     */
     27    public function pluginLoaded(){
     28        $settings = $this->settings;
     29        if(Info::isWooCommerceActive() && $settings['wooCommerceEnabled']){
     30            include_once 'WooCommerceIntegration.php';
     31            $this->wooCommerce = WooCommerceIntegration::getInstance();
     32            $this->wooCommerce->init();
     33        }
     34    }
    2335    /**
    2436     * Render the view using MVC pattern.
  • leadbi/trunk/includes/Info.php

    r1736960 r1872868  
    3232      */
    3333     const LEADBI_ENDPOINT = 'https://app.leadbi.com';
     34
     35
     36    /**
     37     * Check if wooCommerce is installed and active
     38     */
     39    public static function isWooCommerceActive(){
     40        if(class_exists('WC_Integration') && defined('WOOCOMMERCE_VERSION') && version_compare(WOOCOMMERCE_VERSION, '3.0.0', '>=') ) {
     41            return true;
     42        }
     43
     44        return false;
     45    }
    3446}
  • leadbi/trunk/includes/Plugin.php

    r1828900 r1872868  
    5050        $this->loader->add_action('wp_enqueue_scripts', $frontend, 'assets');
    5151        $this->loader->add_action('wp_footer', $frontend, 'render');
     52        $this->loader->add_action('plugins_loaded', $frontend, 'pluginLoaded');
    5253
    5354        add_shortcode('leadbi_form', array($this, 'leadbiForm'));
  • leadbi/trunk/leadbi.php

    r1828900 r1872868  
    88 * Plugin URI: https://www.leadbi.com/features/
    99 * Description: LeadBI's WordPress plugin allows existing LeadBI customers and trial users to install the LeadBI tracking code on their existing WordPress blogs and websites and view the dashboard.
    10  * Version: 1.1
     10 * Version: 1.2
    1111 * Author: LeadBI
    1212 * Author URI: https://www.leadbi.com/
Note: See TracChangeset for help on using the changeset viewer.