Plugin Directory

Changeset 1709699


Ignore:
Timestamp:
08/07/2017 05:04:24 PM (9 years ago)
Author:
MailChimp
Message:

Update to 2.0.1. Add support for Connected Site JS, fixes.

Location:
mailchimp-for-woocommerce
Files:
99 added
19 edited

Legend:

Unmodified
Added
Removed
  • mailchimp-for-woocommerce/trunk/README.md

    r1522130 r1709699  
    38382) In the left navigation panel, click **Plugins**, and choose **Add New**.
    3939
    40 ![Add new] (https://cloud.githubusercontent.com/assets/6547700/18677991/a7622bcc-7f28-11e6-8e8c-9bbdfa9861c7.png)
     40![Add new](https://cloud.githubusercontent.com/assets/6547700/18677991/a7622bcc-7f28-11e6-8e8c-9bbdfa9861c7.png)
    4141
    42423) Click **Upload Plugin**.
    4343
    44 ![Upload] (https://cloud.githubusercontent.com/assets/6547700/18677997/a76dab82-7f28-11e6-98e4-4309739cd840.png)
     44![Upload](https://cloud.githubusercontent.com/assets/6547700/18677997/a76dab82-7f28-11e6-98e4-4309739cd840.png)
    4545
    46464) Click **Choose File** to select the ZIP file for the plugin, then click **Install Now**.
  • mailchimp-for-woocommerce/trunk/README.txt

    r1639952 r1709699  
    44Donate link: https://mailchimp.com
    55Requires at least: 4.3
    6 Tested up to: 4.6.1
     6Tested up to: 4.8
    77Stable tag: 4.6.1
    88License: GPLv2 or later
     
    5050
    5151== Changelog ==
     52= 2.0.1 =
     53* Added support for "Connected Site" scripts.
     54* Made physical address a required field for store setup.
     55* Fixed order, cart timestamps to begin using UTC.
     56
    5257= 2.0 =
    5358* Support WooComerce 3.0
  • mailchimp-for-woocommerce/trunk/admin/class-mailchimp-woocommerce-admin.php

    r1639952 r1709699  
    282282        $this->setData('validation.api.ping', $valid);
    283283
     284        $data['active_tab'] = $valid ? 'store_info' : 'api_key';
     285
    284286        if ($valid && isset($profile) && is_array($profile) && array_key_exists('account_id', $profile)) {
    285287            $data['mailchimp_account_info_id'] = $profile['account_id'];
     
    300302    protected function validatePostStoreInfo($input)
    301303    {
    302         $data = array(
    303 
    304             // store basics
    305             'store_name' => trim((isset($input['store_name']) ? $input['store_name'] : get_option('blogname'))),
    306             'store_street' => isset($input['store_street']) ? $input['store_street'] : false,
    307             'store_city' => isset($input['store_city']) ? $input['store_city'] : false,
    308             'store_state' => isset($input['store_state']) ? $input['store_state'] : false,
    309             'store_postal_code' => isset($input['store_postal_code']) ? $input['store_postal_code'] : false,
    310             'store_country' => isset($input['store_country']) ? $input['store_country'] : false,
    311             'store_phone' => isset($input['store_phone']) ? $input['store_phone'] : false,
    312 
    313             // locale info
    314             'store_locale' => isset($input['store_locale']) ? $input['store_locale'] : false,
    315             'store_timezone' => isset($input['store_timezone']) ? $input['store_timezone'] : false,
    316             'store_currency_code' => isset($input['store_currency_code']) ? $input['store_currency_code'] : false,
    317 
    318             'admin_email' => isset($input['admin_email']) && is_email($input['admin_email']) ? $input['admin_email'] : $this->getOption('admin_email', false),
    319         );
     304        $data = $this->compileStoreInfoData($input);
    320305
    321306        if (!$this->hasValidStoreInfo($data)) {
    322307
    323             if (empty($data['admin_email']) || empty($data['store_city']) || empty($data['store_state']) || empty($data['store_postal_code']) || empty($data['store_country']) || empty($data['store_street'])) {
    324                 add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a contact email and a physical mailing address.');
    325             }
    326 
    327             if (empty($data['store_phone']) || strlen($data['store_phone']) <= 6) {
    328                 add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a valid phone number for your store.');
    329             }
    330 
    331             if (empty($data['store_name'])) {
    332                 add_settings_error('mailchimp_store_settings', '', 'MailChimp for WooCommerce requires a Store Name to connect your store.');
    333             }
     308            if ($this->hasInvalidStoreAddress($data)) {
     309                $this->addInvalidAddressAlert();
     310            }
     311
     312            if ($this->hasInvalidStorePhone($data)) {
     313                $this->addInvalidPhoneAlert();
     314            }
     315
     316            if ($this->hasInvalidStoreName($data)) {
     317                $this->addInvalidStoreNameAlert();
     318            }
    334319
    335320            $this->setData('validation.store_info', false);
     321
     322            $data['active_tab'] = 'store_info';
     323
    336324            return array();
    337325        }
    338326
    339327        $this->setData('validation.store_info', true);
     328
     329        $data['active_tab'] = 'campaign_defaults';
    340330
    341331        if ($this->hasValidMailChimpList()) {
     
    345335        return $data;
    346336    }
     337
     338    /**
     339     * @param $input
     340     * @return array
     341     */
     342    protected function compileStoreInfoData($input)
     343    {
     344        return array(
     345            // store basics
     346            'store_name' => trim((isset($input['store_name']) ? $input['store_name'] : get_option('blogname'))),
     347            'store_street' => isset($input['store_street']) ? $input['store_street'] : false,
     348            'store_city' => isset($input['store_city']) ? $input['store_city'] : false,
     349            'store_state' => isset($input['store_state']) ? $input['store_state'] : false,
     350            'store_postal_code' => isset($input['store_postal_code']) ? $input['store_postal_code'] : false,
     351            'store_country' => isset($input['store_country']) ? $input['store_country'] : false,
     352            'store_phone' => isset($input['store_phone']) ? $input['store_phone'] : false,
     353            // locale info
     354            'store_locale' => isset($input['store_locale']) ? $input['store_locale'] : false,
     355            'store_timezone' => isset($input['store_timezone']) ? $input['store_timezone'] : false,
     356            'store_currency_code' => isset($input['store_currency_code']) ? $input['store_currency_code'] : false,
     357            'admin_email' => isset($input['admin_email']) && is_email($input['admin_email']) ? $input['admin_email'] : $this->getOption('admin_email', false),
     358        );
     359    }
     360
     361    /**
     362     * @param array $data
     363     * @return array|bool
     364     */
     365    protected function hasInvalidStoreAddress($data)
     366    {
     367        $address_keys = array(
     368            'admin_email',
     369            'store_city',
     370            'store_state',
     371            'store_postal_code',
     372            'store_country',
     373            'store_street'
     374        );
     375
     376        $invalid = array();
     377        foreach ($address_keys as $address_key) {
     378            if (empty($data[$address_key])) {
     379                $invalid[] = $address_key;
     380            }
     381        }
     382        return empty($invalid) ? false : $invalid;
     383    }
     384
     385    /**
     386     * @param $data
     387     * @return bool
     388     */
     389    protected function hasInvalidStorePhone($data)
     390    {
     391        if (empty($data['store_phone']) || strlen($data['store_phone']) <= 6) {
     392            return true;
     393        }
     394
     395        return false;
     396    }
     397
     398    /**
     399     * @param $data
     400     * @return bool
     401     */
     402    protected function hasInvalidStoreName($data)
     403    {
     404        if (empty($data['store_name'])) {
     405            return true;
     406        }
     407        return false;
     408    }
     409
     410    /**
     411     *
     412     */
     413    protected function addInvalidAddressAlert()
     414    {
     415        add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a contact email and a physical mailing address.');
     416    }
     417
     418    /**
     419     *
     420     */
     421    protected function addInvalidPhoneAlert()
     422    {
     423        add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a valid phone number for your store.');
     424    }
     425
     426    /**
     427     *
     428     */
     429    protected function addInvalidStoreNameAlert()
     430    {
     431        add_settings_error('mailchimp_store_settings', '', 'MailChimp for WooCommerce requires a Store Name to connect your store.');
     432    }
    347433
    348434    /**
     
    366452        if (!$this->hasValidCampaignDefaults($data)) {
    367453            $this->setData('validation.campaign_defaults', false);
    368             return array();
     454
     455            return array('active_tab' => 'campaign_defaults');
    369456        }
    370457
    371458        $this->setData('validation.campaign_defaults', true);
     459
     460        $data['active_tab'] = 'newsletter_settings';
    372461
    373462        return $data;
     
    395484            'mailchimp_list' => isset($input['mailchimp_list']) ? $input['mailchimp_list'] : $this->getOption('mailchimp_list', ''),
    396485            'newsletter_label' => isset($input['newsletter_label']) ? $input['newsletter_label'] : $this->getOption('newsletter_label', 'Subscribe to our newsletter'),
    397             'mailchimp_auto_subscribe' => isset($input['mailchimp_auto_subscribe']) ? $input['mailchimp_auto_subscribe'] : $this->getOption('mailchimp_auto_subscribe', '0'),
     486            'mailchimp_auto_subscribe' => isset($input['mailchimp_auto_subscribe']) ? (bool) $input['mailchimp_auto_subscribe'] : $this->getOption('mailchimp_auto_subscribe', '0'),
    398487            'mailchimp_checkbox_defaults' => $checkbox,
    399488            'mailchimp_checkbox_action' => isset($input['mailchimp_checkbox_action']) ? $input['mailchimp_checkbox_action'] : $this->getOption('mailchimp_checkbox_action', 'woocommerce_after_checkout_billing_form'),
     
    406495        // as long as we have a list set, and it's currently in MC as a valid list, let's sync the store.
    407496        if (!empty($data['mailchimp_list']) && $this->api()->hasList($data['mailchimp_list'])) {
     497
     498            $this->setData('validation.newsletter_settings', true);
    408499
    409500            // sync the store with MC
     
    415506                $this->showSyncStartedMessage();
    416507            }
    417         }
    418 
    419         return $data;
     508
     509            $data['active_tab'] = 'sync';
     510
     511            return $data;
     512        }
     513
     514        $this->setData('validation.newsletter_settings', false);
     515
     516        $data['active_tab'] = 'newsletter_settings';
     517
     518        return $data;
    420519    }
    421520
     
    692791            $this->setData($time_key, time());
    693792
     793            // on a new store push, we need to make sure we save the site script into a local variable.
     794            if ($new) {
     795                mailchimp_update_connected_site_script();
     796            }
     797
    694798            return true;
    695799
  • mailchimp-for-woocommerce/trunk/admin/partials/mailchimp-woocommerce-admin-tabs.php

    r1639952 r1709699  
    11<?php
    22$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'api_key';
     3$is_mailchimp_post = isset($_POST['mailchimp_woocommerce_settings_hidden']) && $_POST['mailchimp_woocommerce_settings_hidden'] === 'Y';
    34
    45$handler = MailChimp_Woocommerce_Admin::connect();
     
    78$options = get_option($this->plugin_name, array());
    89
     10if (!isset($_GET['tab']) && isset($options['active_tab'])) {
     11    $active_tab = $options['active_tab'];
     12}
     13
    914$show_sync_tab = isset($_GET['resync']) ? $_GET['resync'] === '1' : false;;
    1015$show_campaign_defaults = true;
     
    1217$allow_new_list = true;
    1318
    14 $clicked_sync_button = isset($_POST['mailchimp_woocommerce_settings_hidden']) && $active_tab == 'sync';
     19$clicked_sync_button = $is_mailchimp_post&& $active_tab == 'sync';
    1520
    1621if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
  • mailchimp-for-woocommerce/trunk/admin/partials/tabs/store_info.php

    r1557758 r1709699  
    1919    </legend>
    2020    <label for="<?php echo $this->plugin_name; ?>-store-name-label">
    21         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-name-label" name="<?php echo $this->plugin_name; ?>[store_name]" value="<?php echo isset($options['store_name']) ? $options['store_name'] : get_option('blogname') ?>" />
    22         <span><?php esc_attr_e('Name', $this->plugin_name); ?></span>
     21        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-name-label" name="<?php echo $this->plugin_name; ?>[store_name]" value="<?php echo isset($options['store_name']) ? $options['store_name'] : get_option('blogname') ?>" />
     22        <span>
     23            <?php
     24            if (!empty($options['store_name']) ) {
     25                esc_attr_e('Name', $this->plugin_name);
     26            } else {
     27                esc_attr_e('Name', $this->plugin_name); echo '<span style="color:red;">*</span>';
     28            }
     29            ?>
     30        </span>
    2331    </label>
    2432</fieldset>
     
    2937    </legend>
    3038    <label for="<?php echo $this->plugin_name; ?>-admin-email-label">
    31         <input style="width: 30%;" type="email" id="<?php echo $this->plugin_name; ?>-admin-email-label" name="<?php echo $this->plugin_name; ?>[admin_email]" value="<?php echo isset($options['admin_email']) ? $options['admin_email'] : get_option('admin_email') ?>" />
    32         <span><?php esc_attr_e('Email', $this->plugin_name); ?></span>
     39        <input required style="width: 30%;" type="email" id="<?php echo $this->plugin_name; ?>-admin-email-label" name="<?php echo $this->plugin_name; ?>[admin_email]" value="<?php echo isset($options['admin_email']) ? $options['admin_email'] : get_option('admin_email') ?>" />
     40        <span>
     41            <?php
     42            if (!empty($options['admin_email']) ) {
     43                esc_attr_e('Email', $this->plugin_name);
     44            } else {
     45                esc_attr_e('Email', $this->plugin_name); echo '<span style="color:red;">*</span>';
     46            }
     47            ?>
     48        </span>
    3349    </label>
    3450</fieldset>
     
    3955    </legend>
    4056    <label for="<?php echo $this->plugin_name; ?>-store-address-label">
    41         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-address-label" name="<?php echo $this->plugin_name; ?>[store_street]" value="<?php echo isset($options['store_street']) ? $options['store_street'] : '' ?>" />
    42         <span><?php esc_attr_e('Street address', $this->plugin_name); ?></span>
     57        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-address-label" name="<?php echo $this->plugin_name; ?>[store_street]" value="<?php echo isset($options['store_street']) ? $options['store_street'] : '' ?>" />
     58        <span>
     59            <?php
     60            if (!empty($options['store_street']) ) {
     61                esc_attr_e('Street address', $this->plugin_name);
     62            } else {
     63                esc_attr_e('Street address', $this->plugin_name); echo '<span style="color:red;">*</span>';
     64            }
     65            ?>
     66        </span>
    4367    </label>
    4468</fieldset>
     
    4973    </legend>
    5074    <label for="<?php echo $this->plugin_name; ?>-store-city-label">
    51         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-city-label" name="<?php echo $this->plugin_name; ?>[store_city]" value="<?php echo isset($options['store_city']) ? $options['store_city'] : '' ?>" />
    52         <span><?php esc_attr_e('City', $this->plugin_name); ?></span>
     75        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-city-label" name="<?php echo $this->plugin_name; ?>[store_city]" value="<?php echo isset($options['store_city']) ? $options['store_city'] : '' ?>" />
     76        <span>
     77            <?php
     78            if (!empty($options['store_city']) ) {
     79                esc_attr_e('City', $this->plugin_name);
     80            } else {
     81                esc_attr_e('City', $this->plugin_name); echo '<span style="color:red;">*</span>';
     82            }
     83            ?>
     84        </span>
    5385    </label>
    5486</fieldset>
     
    5991    </legend>
    6092    <label for="<?php echo $this->plugin_name; ?>-store-state-label">
    61         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-state-label" name="<?php echo $this->plugin_name; ?>[store_state]" value="<?php echo isset($options['store_state']) ? $options['store_state'] : '' ?>" />
    62         <span><?php esc_attr_e('State', $this->plugin_name); ?></span>
     93        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-state-label" name="<?php echo $this->plugin_name; ?>[store_state]" value="<?php echo isset($options['store_state']) ? $options['store_state'] : '' ?>" />
     94        <span>
     95            <?php
     96            if (!empty($options['store_state']) ) {
     97                esc_attr_e('State', $this->plugin_name);
     98            } else {
     99                esc_attr_e('State', $this->plugin_name); echo '<span style="color:red;">*</span>';
     100            }
     101            ?>
     102        </span>
    63103    </label>
    64104</fieldset>
     
    69109    </legend>
    70110    <label for="<?php echo $this->plugin_name; ?>-store-state-label">
    71         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-postal-code-label" name="<?php echo $this->plugin_name; ?>[store_postal_code]" value="<?php echo isset($options['store_postal_code']) ? $options['store_postal_code'] : '' ?>" />
    72         <span><?php esc_attr_e('Postal Code', $this->plugin_name); ?></span>
     111        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-postal-code-label" name="<?php echo $this->plugin_name; ?>[store_postal_code]" value="<?php echo isset($options['store_postal_code']) ? $options['store_postal_code'] : '' ?>" />
     112        <span>
     113            <?php
     114            if (!empty($options['store_postal_code']) ) {
     115                esc_attr_e('Postal Code', $this->plugin_name);
     116            } else {
     117                esc_attr_e('Postal Code', $this->plugin_name); echo '<span style="color:red;">*</span>';
     118            }
     119            ?>
     120        </span>
    73121    </label>
    74122</fieldset>
     
    79127    </legend>
    80128    <label for="<?php echo $this->plugin_name; ?>-store-country-label">
    81         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-country-label" name="<?php echo $this->plugin_name; ?>[store_country]" value="<?php echo isset($options['store_country']) ? $options['store_country'] : 'US' ?>" />
    82         <span><?php esc_attr_e('Country', $this->plugin_name); ?></span>
     129        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-country-label" name="<?php echo $this->plugin_name; ?>[store_country]" value="<?php echo isset($options['store_country']) ? $options['store_country'] : 'US' ?>" />
     130        <span>
     131            <?php
     132            if (!empty($options['store_country'])) {
     133                esc_attr_e('Country', $this->plugin_name);
     134            } else {
     135                esc_attr_e('Country', $this->plugin_name); echo '<span style="color:red;">*</span>';
     136            }
     137            ?>
     138        </span>
    83139    </label>
    84140</fieldset>
     
    89145    </legend>
    90146    <label for="<?php echo $this->plugin_name; ?>-store-phone-label">
    91         <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-phone-label" name="<?php echo $this->plugin_name; ?>[store_phone]" value="<?php echo isset($options['store_phone']) ? $options['store_phone'] : '' ?>" />
    92         <span><?php esc_attr_e('Phone Number', $this->plugin_name); ?></span>
     147        <input required style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-store-phone-label" name="<?php echo $this->plugin_name; ?>[store_phone]" value="<?php echo isset($options['store_phone']) ? $options['store_phone'] : '' ?>" />
     148        <span>
     149            <?php
     150            if (!empty($options['store_phone']) ) {
     151                esc_attr_e('Phone Number', $this->plugin_name);
     152            } else {
     153                esc_attr_e('Phone Number', $this->plugin_name); echo '<span style="color:red;">*</span>';
     154            }
     155            ?>
     156        </span>
    93157    </label>
    94158</fieldset>
  • mailchimp-for-woocommerce/trunk/changelog.md

    r1639952 r1709699  
     1** 2.0.1 **
     2
     3##### New Features: #####
     4* MC.js support added.
     5* Added pop-up forms to the site details page with a warning to upgrade to 2.0.1 before using them.
     6
     7##### Fixes: #####
     8* Adding physical address as a required field for store setup, since this is also a field required by MailChimp.
     9* Order/carts timestamps now pass over as UTC.
     10* Improved handling of Order Notification and sending Order Invoice and Order Confirmation simultaneously when order is moved to “Processing” in Woocommerce.
     11* Tabs paginating on store set up, moving the user through each step automatically.
     12
    113** 2.0 **
    214* Support WooComerce 3.0
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-order.php

    r1604825 r1709699  
    2929    protected $billing_address = null;
    3030    protected $lines = array();
     31    protected $confirm_and_paid = false;
    3132
    3233    /**
     
    361362
    362363    /**
     364     * @param $bool
     365     * @param $bool
     366     * @return $this
     367     */
     368    public function confirmAndPay($bool)
     369    {
     370        $this->confirm_and_paid = (bool) $bool;
     371
     372        return $this;
     373    }
     374
     375    /**
     376     * @return bool
     377     */
     378    public function shouldConfirmAndPay()
     379    {
     380        return $this->confirm_and_paid;
     381    }
     382
     383    /**
    363384     * @param MailChimp_WooCommerce_Address $address
    364385     * @return $this
     
    377398    {
    378399        if (empty($this->shipping_address)) {
    379             $this->shipping_address = new MailChimp_WooCommerce_Address('shipping');
     400            $this->shipping_address = new MailChimp_WooCommerce_Address();
    380401        }
    381402        return $this->shipping_address;
     
    399420    {
    400421        if (empty($this->billing_address)) {
    401             $this->billing_address = new MailChimp_WooCommerce_Address('billing');
     422            $this->billing_address = new MailChimp_WooCommerce_Address();
    402423        }
    403424        return $this->billing_address;
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-store.php

    r1582981 r1709699  
    2424    protected $address = null;
    2525    protected $platform = null;
     26    protected $connected_site = null;
    2627
    2728    /**
     
    291292
    292293        return $this;
     294    }
     295
     296    /**
     297     * @return null|string
     298     */
     299    public function getConnectedSiteForeignID()
     300    {
     301        return $this->getConnectedSiteParam('site_foreign_id');
     302    }
     303
     304    /**
     305     * @return null|string
     306     */
     307    public function getConnectedSiteScriptUrl()
     308    {
     309        if (($script = $this->getConnectedSiteParam('site_script'))) {
     310            return $script['url'];
     311        }
     312        return false;
     313    }
     314
     315    /**
     316     * @return null|string
     317     */
     318    public function getConnectedSiteScriptFragment()
     319    {
     320        if (($script = $this->getConnectedSiteParam('site_script'))) {
     321            return $script['fragment'];
     322        }
     323        return false;
     324    }
     325
     326    /**
     327     * @param $key
     328     * @param null $default
     329     * @return null
     330     */
     331    public function getConnectedSiteParam($key, $default = null)
     332    {
     333        if (empty($this->connected_site)) {
     334            return $default;
     335        }
     336        return array_key_exists($key, $this->connected_site) ? $this->connected_site[$key] : null;
    293337    }
    294338
     
    338382        }
    339383
     384        if (array_key_exists('connected_site', $data)) {
     385            $this->connected_site = $data['connected_site'];
     386        }
     387
    340388        return $this;
    341389    }
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-api.php

    r1582981 r1709699  
    398398
    399399    /**
     400     * @param $store_id
     401     * @return array|bool
     402     */
     403    public function checkConnectedSite($store_id)
     404    {
     405        try {
     406             return $this->get("connected-sites/{$store_id}");
     407        } catch (MailChimp_WooCommerce_Error $e) {
     408            return false;
     409        }
     410    }
     411
     412    /**
     413     * @param $store_id
     414     * @return array|bool
     415     */
     416    public function connectSite($store_id)
     417    {
     418        try {
     419            return $this->post("connected-sites/{$store_id}/actions/verify-script-installation", array());
     420        } catch (MailChimp_WooCommerce_Error $e) {
     421            return false;
     422        }
     423    }
     424
     425    /**
    400426     * @return array|bool
    401427     */
     
    664690                return false;
    665691            }
     692
     693            // submit the first one
    666694            $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
     695
     696            // if the order is in pending status, we need to submit the order again with a paid status.
     697            if ($order->shouldConfirmAndPay() && $order->getFinancialStatus() !== 'paid') {
     698                $order->setFinancialStatus('paid');
     699                $data = $this->patch("ecommerce/stores/{$store_id}/orders/{$order->getId()}", $order->toArray());
     700            }
     701
    667702            update_option('mailchimp-woocommerce-resource-last-updated', time());
    668703            $order = new MailChimp_WooCommerce_Order();
     
    689724            }
    690725            $id = $order->getId();
    691             $data = $this->patch("ecommerce/stores/$store_id/orders/$id", $order->toArray());
     726            $data = $this->patch("ecommerce/stores/{$store_id}/orders/{$id}", $order->toArray());
     727
     728            // if the order is in pending status, we need to submit the order again with a paid status.
     729            if ($order->shouldConfirmAndPay() && $order->getFinancialStatus() !== 'paid') {
     730                $order->setFinancialStatus('paid');
     731                $data = $this->patch("ecommerce/stores/{$store_id}/orders/{$id}", $order->toArray());
     732            }
     733
    692734            $order = new MailChimp_WooCommerce_Order();
    693735            return $order->fromArray($data);
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php

    r1639952 r1709699  
    5959        $order = new MailChimp_WooCommerce_Order();
    6060
    61         $order->setId($woo->get_id());
     61        $order->setId($woo->get_order_number());
    6262
    6363        // if we have a campaign id let's set it now.
     
    6666        }
    6767
    68         $order->setProcessedAt($woo->get_date_created());
     68        $order->setProcessedAt($woo->get_date_created()->setTimezone(new \DateTimeZone('UTC')));
    6969
    7070        $order->setCurrencyCode($woo->get_currency());
     
    8686        $order->setFinancialStatus($financial_status);
    8787
     88        // if the status is processing, we need to send this one first, then send a 'paid' status right after.
     89        if ($status === 'processing') {
     90            $order->confirmAndPay(true);
     91        }
     92
    8893        // only set this if the order is cancelled.
    89         if ($status === 'cancelled') $order->setCancelledAt($woo->get_date_modified());
     94        if ($status === 'cancelled') {
     95            $order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
     96        }
    9097
    9198        // set the total
     
    329336            // All product orders require processing, except those for digital downloads
    330337            'processing'    => (object) array(
    331                 'financial' => 'processing',
     338                'financial' => 'pending',
    332339                'fulfillment' => null
    333340            ),
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-transform-orders.php

    r1639952 r1709699  
    1212{
    1313    public $campaign_id = null;
     14    protected $use_user_address = false;
    1415
    1516    /**
     
    5960        $order = new MailChimp_WooCommerce_Order();
    6061
    61         $order->setId($woo->id);
     62        $order->setId($woo->get_order_number());
    6263
    6364        // if we have a campaign id let's set it now.
     
    6667        }
    6768
    68         $order->setProcessedAt(mailchimp_date_utc($woo->order_date));
    69 
    70         $order->setCurrencyCode($woo->get_order_currency());
     69        $order->setProcessedAt($woo->get_date_created()->setTimezone(new \DateTimeZone('UTC')));
     70
     71        $order->setCurrencyCode($woo->get_currency());
    7172
    7273        // grab the current statuses - this will end up being custom at some point.
     
    8687        $order->setFinancialStatus($financial_status);
    8788
     89        // if the status is processing, we need to send this one first, then send a 'paid' status right after.
     90        if ($status === 'processing') {
     91            $order->confirmAndPay(true);
     92        }
     93
    8894        // only set this if the order is cancelled.
    89         if ($status === 'cancelled') $order->setCancelledAt(mailchimp_date_utc($woo->modified_date));
     95        if ($status === 'cancelled') {
     96            $order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
     97        }
    9098
    9199        // set the total
     
    135143                }
    136144
    137                 mailchimp_log('order.items.error', "Order #{$woo->id} :: Product {$item->getProductId()} does not exist!");
     145                mailchimp_log('order.items.error', "Order #{$woo->get_order_number()} :: Product {$item->getProductId()} does not exist!");
    138146                continue;
    139147            }
     
    166174
    167175        // we are saving the post meta for subscribers on each order... so if they have subscribed on checkout
    168         $subscriber_meta = get_post_meta($order->id, 'mailchimp_woocommerce_is_subscribed', true);
     176        $subscriber_meta = get_post_meta($order->get_id(), 'mailchimp_woocommerce_is_subscribed', true);
    169177        $subscribed_on_order = $subscriber_meta === '' ? false : (bool) $subscriber_meta;
    170178
     
    189197
    190198        if (($user = get_userdata($order->customer_user))) {
    191 
    192             /** IF we wanted to use the user data instead we would do it here.
     199            /**
     200             * IF we wanted to use the user data instead we would do it here.
    193201             * but we discussed using the billing address instead.
    194202             */
    195 
    196             /*
    197             $customer->setId($user->ID);
    198             $customer->setEmailAddress($user->user_email);
    199             $customer->setFirstName($user->first_name);
    200             $customer->setLastName($user->last_name);
    201 
    202             if (($address = $this->getUserAddress($user->ID))) {
    203                 if (count($address->toArray()) > 3) {
    204                     $customer->setAddress($address);
    205                 }
    206             }
    207             */
     203            if ($this->use_user_address) {
     204                $customer->setId($user->ID);
     205                $customer->setEmailAddress($user->user_email);
     206                $customer->setFirstName($user->first_name);
     207                $customer->setLastName($user->last_name);
     208
     209                if (($address = $this->getUserAddress($user->ID))) {
     210                    if (count($address->toArray()) > 3) {
     211                        $customer->setAddress($address);
     212                    }
     213                }
     214            }
    208215
    209216            if (!($stats = $this->getCustomerOrderTotals($order->customer_user))) {
     
    461468            // All product orders require processing, except those for digital downloads
    462469            'processing'    => (object) array(
    463                 'financial' => 'processing',
     470                'financial' => 'pending',
    464471                'fulfillment' => null
    465472            ),
  • mailchimp-for-woocommerce/trunk/includes/api/errors/class-mailchimp-server-error.php

    r1514325 r1709699  
    99 * Time: 11:13 AM
    1010 */
    11 class MailChimp_WooCommerce_ServerError extends \Exception
     11class MailChimp_WooCommerce_ServerError extends MailChimp_WooCommerce_Error
    1212{
    1313
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce-activator.php

    r1615883 r1709699  
    3434        // add a store id flag which will be a random hash
    3535        update_option('mailchimp-woocommerce-store_id', md5(get_option('siteurl')), 'yes');
     36
     37        // try this now for existing stores on an update.
     38        mailchimp_update_connected_site_script();
    3639    }
    3740
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce-newsletter.php

    r1557758 r1709699  
    6565    public function processPayPalNewsletterField($order)
    6666    {
    67         $this->handleStatus($order->id);
     67        $this->handleStatus($order->get_id());
    6868    }
    6969
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-process-orders.php

    r1639952 r1709699  
    6363                return $response;
    6464
     65            } catch (MailChimp_WooCommerce_ServerError $e) {
     66                mailchimp_log('sync.orders.error', "$call :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
     67                return false;
    6568            } catch (MailChimp_WooCommerce_Error $e) {
    6669                mailchimp_log('sync.orders.error', "$call :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
    67                 return false;
    68             } catch (MailChimp_WooCommerce_ServerError $e) {
    69                 mailchimp_log('sync.orders.error', "$call :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
    7070                return false;
    7171            } catch (Exception $e) {
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-process-products.php

    r1639952 r1709699  
    5454                return $response;
    5555
     56            } catch (MailChimp_WooCommerce_ServerError $e) {
     57                mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
    5658            } catch (MailChimp_WooCommerce_Error $e) {
    5759                mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
    58             } catch (MailChimp_WooCommerce_ServerError $e) {
    59                 mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
    6060            } catch (Exception $e) {
    6161                mailchimp_log('sync.products.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-single-product.php

    r1639952 r1709699  
    6868            return $product;
    6969
     70        } catch (MailChimp_WooCommerce_ServerError $e) {
     71            mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
    7072        } catch (MailChimp_WooCommerce_Error $e) {
    7173            mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
    72         } catch (MailChimp_WooCommerce_ServerError $e) {
    73             mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
    7474        } catch (Exception $e) {
    7575            mailchimp_log('product_submit.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
  • mailchimp-for-woocommerce/trunk/mailchimp-woocommerce.php

    r1639952 r1709699  
    1717 * Plugin URI:        https://mailchimp.com/connect-your-store/
    1818 * Description:       MailChimp - WooCommerce plugin
    19  * Version:           2.0.0
     19 * Version:           2.0.1
    2020 * Author:            MailChimp
    2121 * Author URI:        https://mailchimp.com
     
    2525 * Domain Path:       /languages
    2626 * Requires at least: 4.4
    27  * Tested up to: 4.7
     27 * Tested up to: 4.8
    2828 */
    2929
     
    3737 */
    3838function mailchimp_environment_variables() {
    39     global $wp_version;
    40 
    41     return (object) array(
    42         'repo' => 'master',
    43         'environment' => 'production',
    44         'version' => '2.0.0',
    45         'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
    46         'wc_version' => function_exists('WC') ? WC()->version : null,
    47     );
     39    return require 'env.php';
    4840}
    4941
     
    244236}
    245237
    246 /**
    247  * See if we need to run any updates.
    248  */
    249 function run_mailchimp_plugin_updater() {
    250     if (!class_exists('PucFactory')) {
    251         require plugin_dir_path( __FILE__ ) . 'includes/plugin-update-checker/plugin-update-checker.php';
    252     }
    253 
    254     /** @var \PucGitHubChecker_3_1 $checker */
    255     $updater = PucFactory::getLatestClassVersion('PucGitHubChecker');
    256 
    257     if (class_exists($updater)) {
    258         $env = mailchimp_environment_variables();
    259         $checker = new $updater('https://github.com/mailchimp/mc-woocommerce/', __FILE__, $env->repo, 1);
    260         $checker->handleManualCheck();
    261     }
    262 }
    263 
    264238function mailchimp_debug($action, $message, $data = null)
    265239{
     
    349323}
    350324
     325/**
     326 * @return bool
     327 */
     328function mailchimp_update_connected_site_script() {
     329    // pull the store ID
     330    $store_id = mailchimp_get_store_id();
     331
     332    // if the api is configured
     333    if ($store_id && ($api = mailchimp_get_api())) {
     334
     335        // if we have a store
     336        if (($store = $api->getStore($store_id))) {
     337
     338            // see if we have a connected site script url/fragment
     339            $url = $store->getConnectedSiteScriptUrl();
     340            $fragment = $store->getConnectedSiteScriptFragment();
     341
     342            // if it's not empty we need to set the values
     343            if ($url && $fragment) {
     344
     345                // update the options for script_url and script_fragment
     346                update_option('mailchimp-woocommerce-script_url', $url);
     347                update_option('mailchimp-woocommerce-script_fragment', $fragment);
     348
     349                // check to see if the site is connected
     350                if (!$api->checkConnectedSite($store_id)) {
     351
     352                    // if it's not, connect it now.
     353                    $api->connectSite($store_id);
     354                }
     355
     356                return true;
     357            }
     358        }
     359    }
     360    return false;
     361}
     362
     363/**
     364 * @return string|false
     365 */
     366function mailchimp_get_connected_site_script_url() {
     367    return get_option('mailchimp-woocommerce-script_url', false);
     368}
     369
     370/**
     371 * @return string|false
     372 */
     373function mailchimp_get_connected_site_script_fragment() {
     374    return get_option('mailchimp-woocommerce-script_fragment', false);
     375}
     376
    351377register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
    352378register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
     
    385411add_action('wp_head', 'mailchimp_woocommerce_add_meta_tags');
    386412
    387 /** Add the plugin updater function ONLY when they are logged in as admin. */
    388 add_action('admin_init', 'run_mailchimp_plugin_updater');
    389 
    390413/** Add all the MailChimp hooks. */
    391414run_mailchimp_woocommerce();
    392 
  • mailchimp-for-woocommerce/trunk/public/class-mailchimp-woocommerce-public.php

    r1557758 r1709699  
    7474
    7575        //wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailchimp-woocommerce-public.css', array(), $this->version, 'all' );
    76 
    7776    }
    7877
     
    106105        wp_enqueue_script($this->plugin_name);
    107106
     107        // if we have the connected_site script url saved, we need to inject it
     108        if (($site = mailchimp_get_connected_site_script_url()) && !empty($site)) {
     109            wp_enqueue_script($this->plugin_name.'_connected_site', $site, array(), $this->version, true);
     110        }
    108111    }
    109112}
Note: See TracChangeset for help on using the changeset viewer.