Plugin Directory

Changeset 1762067


Ignore:
Timestamp:
11/09/2017 03:59:40 PM (8 years ago)
Author:
MailChimp
Message:

Update to 2.1.0. Adds Promo Code support.

Location:
mailchimp-for-woocommerce/trunk
Files:
5 added
22 edited

Legend:

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

    r1735785 r1762067  
    1111- This plugin requires you to have the [WooCommerce plugin](https://wordpress.org/plugins/woocommerce) already installed and activated in WordPress.
    1212
    13 - Your host environment must meet [WooCommerce's minimum requirements](https://docs.woocommerce.com/document/server-requirements), including PHP 5.6 or greater.
     13- Your host environment must meet [WooCommerce's minimum requirements](https://docs.woocommerce.com/document/server-requirements), including PHP 7.0 or greater.
    1414
    1515- We recommend you use this plugin in a staging environment before installing it on production servers.
     
    60601) On the **Connect** tab, paste your MailChimp API key into the field, choose whether or not you want to send debugging logs to MailChimp, and click **Save all changes**. To learn how to generate a MailChimp API Key, read [About API Keys](http://kb.mailchimp.com/integrations/api-integrations/about-api-keys).
    6161
    62  ![API key] (https://cloud.githubusercontent.com/assets/19805049/18877771/3fca90e8-849c-11e6-9e3a-161a7b3936dd.png)
     62![API key](https://cloud.githubusercontent.com/assets/19805049/18877771/3fca90e8-849c-11e6-9e3a-161a7b3936dd.png)
    6363
    64642) Navigate to the **Store Settings** tab.
     
    68683) Enter the contact and location details for your WooCommerce Store, and click **Save all changes**.
    6969
    70 ![Save all changes] (https://cloud.githubusercontent.com/assets/6547700/18677996/a76d126c-7f28-11e6-9150-4b289d20f057.png)
     70![Save all changes](https://cloud.githubusercontent.com/assets/6547700/18677996/a76d126c-7f28-11e6-9150-4b289d20f057.png)
    7171
    72724) Navigate to the **List Settings** tab.
    7373
    74 ![List Settings tab] (https://cloud.githubusercontent.com/assets/19805049/18878446/961221d0-849e-11e6-99bb-175c22bf921e.png)
     74![List Settings tab](https://cloud.githubusercontent.com/assets/19805049/18878446/961221d0-849e-11e6-99bb-175c22bf921e.png)
    7575
    76765) Choose the list you want to sync, decide whether or not you want to auto-subscribe existing customers, set the subscribe message you want customers to see at checkout, and click **Save all changes**.
  • mailchimp-for-woocommerce/trunk/README.txt

    r1741630 r1762067  
    2323- Grow your audience and sell more stuff with Facebook and Instagram Ad Campaigns in MailChimp.
    2424- Automatically embed a pop-up form that converts your website visitors to subscribers.
     25- Add discount codes created in WooCommerce to your emails and automations with a Promo Code content block
    2526
    2627###A note for current WooCommerce integration users
     
    3435
    3536- This plugin requires you to have the [WooCommerce plugin](https://woocommerce.com/) already installed and activated in WordPress.
    36 - Your hosting environment must meet [WooCommerce's minimum requirements](https://docs.woocommerce.com/document/server-requirements), including PHP 5.6 or greater.
     37- Your hosting environment must meet [WooCommerce's minimum requirements](https://docs.woocommerce.com/document/server-requirements), including PHP 7.0 or greater.
    3738- We recommend you use this plugin in a staging environment before installing it on production servers. To learn more about staging environments, [check out these related Wordpress plugins](https://wordpress.org/plugins/search.php?q=staging).
    3839- MailChimp for WooCommerce syncs the customer’s first name, last name, email address, and orders.
     
    5051
    5152== Changelog ==
     53
     54= 2.1.0 =
     55* Added Promo Code support.
    5256
    5357= 2.0.2 =
  • mailchimp-for-woocommerce/trunk/admin/class-mailchimp-woocommerce-admin.php

    r1735785 r1762067  
    885885    private function startSync()
    886886    {
     887        $coupon_sync = new MailChimp_WooCommerce_Process_Coupons();
     888        wp_queue($coupon_sync);
     889
    887890        $job = new MailChimp_WooCommerce_Process_Products();
    888891        $job->flagStartSync();
  • mailchimp-for-woocommerce/trunk/admin/partials/mailchimp-woocommerce-admin-tabs.php

    r1735785 r1762067  
    6161</style>
    6262
    63 <?php if (!defined('PHP_VERSION_ID') || (PHP_VERSION_ID < 50600)): ?>
     63<?php if (!defined('PHP_VERSION_ID') || (PHP_VERSION_ID < 70000)): ?>
    6464    <div data-dismissible="notice-php-version" class="error notice notice-error is-dismissible">
    65         <p><?php _e('MailChimp says: Please upgrade your PHP version to a minimum of 5.6', 'mailchimp-woocommerce'); ?></p>
     65        <p><?php _e('MailChimp says: Please upgrade your PHP version to a minimum of 7.0', 'mailchimp-woocommerce'); ?></p>
    6666    </div>
    6767<?php endif; ?>
  • mailchimp-for-woocommerce/trunk/admin/partials/tabs/logs.php

    r1735785 r1762067  
    44        $log_handler = new WC_Log_Handler_File();
    55        $log_handler->remove($_REQUEST['handle']);
     6        wp_redirect('options-general.php?page=mailchimp-woocommerce&tab=logs');
    67    }
    78}
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-order.php

    r1709699 r1762067  
    3030    protected $lines = array();
    3131    protected $confirm_and_paid = false;
     32    protected $promos = [];
    3233
    3334    /**
     
    126127
    127128    /**
     129     * @param $code
     130     * @param $amount
     131     * @param bool $is_percentage
     132     * @return $this
     133     */
     134    public function addDiscount($code, $amount, $is_percentage = false)
     135    {
     136        $this->promos[] = [
     137            'code' => $code,
     138            'amount_discounted' => $amount,
     139            'type' => $is_percentage ? 'percent' : 'fixed'
     140        ];
     141
     142        return $this;
     143    }
     144
     145    /**
    128146     * @return array
    129147     */
     148    public function discounts()
     149    {
     150        return $this->promos;
     151    }
     152
     153    /**
     154     * @return array
     155     */
    130156    public function items()
    131157    {
     
    162188    /**
    163189     * @param null $financial_status
    164      * @return Order
     190     * @return MailChimp_WooCommerce_Order
    165191     */
    166192    public function setFinancialStatus($financial_status)
     
    448474            'shipping_address' => $this->getShippingAddress()->toArray(),
    449475            'billing_address' => $this->getBillingAddress()->toArray(),
     476            'promos' => !empty($this->promos) ? $this->promos : null,
    450477            'lines' => array_map(function ($item) {
    451478                /** @var MailChimp_WooCommerce_LineItem $item */
     
    481508            $billing = new MailChimp_WooCommerce_Address();
    482509            $this->billing_address = $billing->fromArray($data['billing_address']);
     510        }
     511
     512        if (array_key_exists('promos', $data)) {
     513            $this->promos = $data['promos'];
    483514        }
    484515
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-api.php

    r1735785 r1762067  
    837837            $this->delete("ecommerce/stores/$store_id/products/$product_id");
    838838            return true;
     839        } catch (MailChimp_WooCommerce_Error $e) {
     840            return false;
     841        }
     842    }
     843
     844
     845    /**
     846     * @param $store_id
     847     * @param MailChimp_WooCommerce_PromoRule $rule
     848     * @param bool $throw
     849     * @return MailChimp_WooCommerce_PromoRule|bool
     850     * @throws MailChimp_WooCommerce_Error
     851     */
     852    public function addPromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
     853    {
     854        try {
     855            if (($response = $this->updatePromoRule($store_id, $rule, false))) {
     856                return $response;
     857            }
     858            $data = $this->post("ecommerce/stores/{$store_id}/promo-rules", $rule->toArray());
     859            return (new MailChimp_WooCommerce_PromoRule)->fromArray($data);
     860        } catch (MailChimp_WooCommerce_Error $e) {
     861            if ($throw) throw $e;
     862            return false;
     863        }
     864    }
     865
     866    /**
     867     * @param $store_id
     868     * @param MailChimp_WooCommerce_PromoRule $rule
     869     * @param bool $throw
     870     * @return MailChimp_WooCommerce_PromoRule|bool
     871     * @throws MailChimp_WooCommerce_Error
     872     */
     873    public function updatePromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
     874    {
     875        try {
     876            $data = $this->patch("ecommerce/stores/{$store_id}/promo-rules/{$rule->getId()}", $rule->toArray());
     877            return (new MailChimp_WooCommerce_PromoRule)->fromArray($data);
     878        } catch (MailChimp_WooCommerce_Error $e) {
     879            if ($throw) throw $e;
     880            return false;
     881        }
     882    }
     883
     884    /**
     885     * @param $store_id
     886     * @param MailChimp_WooCommerce_PromoRule|int $rule
     887     * @return bool
     888     */
     889    public function deletePromoRule($store_id, $rule)
     890    {
     891        try {
     892            $id = $rule instanceof MailChimp_WooCommerce_PromoRule ? $rule->getId() : $rule;
     893            //print_r(array('id' => $id, 'store' => $store_id));die();
     894            return (bool) $this->delete("ecommerce/stores/{$store_id}/promo-rules/{$id}");
     895        } catch (MailChimp_WooCommerce_Error $e) {
     896            //\Log::error("MC::deletePromoRule :: {$rule->getId()} :: {$e->getMessage()} on {$e->getLine()} in {$e->getFile()}");
     897            return false;
     898        }
     899    }
     900
     901    /**
     902     * @param $store_id
     903     * @param int $page
     904     * @param int $count
     905     * @return array
     906     */
     907    public function getPromoRuleIds($store_id, $page = 1, $count = 10)
     908    {
     909        $result = $this->get("ecommerce/stores/{$store_id}/promo-rules", [
     910            'start' => $page,
     911            'count' => $count,
     912            'offset' => $page > 1 ? (($page-1) * $count) : 0,
     913            'include' => 'id',
     914        ]);
     915
     916        $ids = array();
     917        foreach ($result['promo_rules'] as $rule) {
     918            $id = (string) $rule['id'];
     919            $ids[$id] = $id;
     920        }
     921        return $ids;
     922    }
     923
     924    /**
     925     * @param $store_id
     926     * @param int $page
     927     * @param int $count
     928     * @param bool $return_original
     929     * @return array
     930     */
     931    public function getPromoRules($store_id, $page = 1, $count = 10, $return_original = false)
     932    {
     933        $result = $this->get("ecommerce/stores/{$store_id}/promo-rules", [
     934            'start' => $page,
     935            'count' => $count,
     936            'offset' => $page > 1 ? (($page-1) * $count) : 0,
     937        ]);
     938
     939        if ($return_original) {
     940            return $result;
     941        }
     942
     943        $rules = array();
     944        foreach ($result['promo_rules'] as $rule_data) {
     945            $rule = new MailChimp_WooCommerce_PromoRule();
     946            $rule->fromArray($rule_data);
     947            $rules[] = $rule;
     948        }
     949        return $rules;
     950    }
     951
     952    /**
     953     * @param $store_id
     954     * @param $rule_id
     955     * @param int $page
     956     * @param int $count
     957     * @param bool $return_original
     958     * @return array
     959     */
     960    public function getPromoCodesForRule($store_id, $rule_id, $page = 1, $count = 10, $return_original = false)
     961    {
     962        $result = $this->get("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo_codes", [
     963            'start' => $page,
     964            'count' => $count,
     965            'offset' => $page > 1 ? (($page-1) * $count) : 0,
     966        ]);
     967
     968        if ($return_original) {
     969            return $result;
     970        }
     971
     972        $rules = array();
     973        foreach ($result as $rule_data) {
     974            $rule = new MailChimp_WooCommerce_PromoCode();
     975            $rule->fromArray($rule_data);
     976            $rules[] = $rule;
     977        }
     978        return $rules;
     979    }
     980
     981    /**
     982     * @param $store_id
     983     * @param $rule_id
     984     * @param $code_id
     985     *
     986     * @return MailChimp_WooCommerce_PromoCode|bool
     987     */
     988    public function getPromoCodeForRule($store_id, $rule_id, $code_id)
     989    {
     990        try {
     991            $data = $this->get("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo-codes/{$code_id}");
     992            return (new MailChimp_WooCommerce_PromoCode)->fromArray($data);
     993        } catch (MailChimp_WooCommerce_Error $e) {
     994            return false;
     995        }
     996    }
     997
     998    /**
     999     * @param $store_id
     1000     * @param MailChimp_WooCommerce_PromoRule $rule
     1001     * @param MailChimp_WooCommerce_PromoCode $code
     1002     * @param bool $throw
     1003     * @return MailChimp_WooCommerce_PromoCode|bool
     1004     * @throws MailChimp_WooCommerce_Error
     1005     */
     1006    public function addPromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
     1007    {
     1008        try {
     1009            if (($result = $this->updatePromoCodeForRule($store_id, $rule, $code, false))) {
     1010                return $result;
     1011            }
     1012            $data = $this->post("ecommerce/stores/{$store_id}/promo-rules/{$rule->getId()}/promo-codes", $code->toArray());
     1013            return (new MailChimp_WooCommerce_PromoCode)->fromArray($data);
     1014        } catch (MailChimp_WooCommerce_Error $e) {
     1015            if ($throw) throw $e;
     1016            return false;
     1017        }
     1018    }
     1019
     1020    /**
     1021     * @param $store_id
     1022     * @param MailChimp_WooCommerce_PromoRule $rule
     1023     * @param MailChimp_WooCommerce_PromoCode $code
     1024     * @param bool $throw
     1025     * @return MailChimp_WooCommerce_PromoCode|bool
     1026     * @throws MailChimp_WooCommerce_Error
     1027     */
     1028    public function updatePromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
     1029    {
     1030        try {
     1031            $data = $this->patch("ecommerce/stores/{$store_id}/promo-rules/{$rule->getId()}/promo-codes/{$code->getId()}", $code->toArray());
     1032            return (new MailChimp_WooCommerce_PromoCode)->fromArray($data);
     1033        } catch (MailChimp_WooCommerce_Error $e) {
     1034            if ($throw) throw $e;
     1035            return false;
     1036        }
     1037    }
     1038
     1039    /**
     1040     * @param $store_id
     1041     * @param $rule_id
     1042     * @param $code_id
     1043     * @return bool
     1044     */
     1045    public function deletePromoCodeForRule($store_id, $rule_id, $code_id)
     1046    {
     1047        try {
     1048            return (bool) $this->delete("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo-codes/{$code_id}");
    8391049        } catch (MailChimp_WooCommerce_Error $e) {
    8401050            return false;
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-api.php

    r1639952 r1762067  
    8282    /**
    8383     * @param $resource
    84      * @return bool|MailChimp_WooCommerce_Transform_Orders|MailChimp_WooCommerce_Transform_Products
     84     * @return bool|MailChimp_WooCommerce_Transform_Orders|MailChimp_WooCommerce_Transform_Products|MailChimp_WooCommerce_Transform_Coupons
    8585     */
    8686    public function engine($resource)
     
    9393                return new MailChimp_WooCommerce_Transform_Orders();
    9494                break;
    95 
     95            case 'coupons':
     96                return new MailChimp_WooCommerce_Transform_Coupons();
    9697            default:
    9798                return false;
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-transform-orders.php

    r1735785 r1762067  
    169169        }
    170170
     171        // apply the coupon discounts
     172        if (($used_coupons = $woo->get_used_coupons()) && is_array($used_coupons)) {
     173            foreach ($used_coupons as $coupon_code) {
     174                if (($coupon_id = wc_get_coupon_id_by_code($coupon_code))) {
     175                    $coupon = new WC_Coupon($coupon_id);
     176                    $is_percentage = $coupon->get_discount_type() === 'percent';
     177                    $order->addDiscount($coupon_code, $coupon->get_amount('edit'), $is_percentage);
     178                }
     179            }
     180        }
     181
    171182        //if (($refund = $woo->get_total_refunded()) && $refund > 0){
    172183        // this is where we would be altering the submission to tell us about the refund.
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-transform-products.php

    r1639952 r1762067  
    4545    public function transform(WP_Post $post)
    4646    {
    47         $woo = new WC_Product($post);
     47        $woo = wc_get_product($post);
    4848
    4949        $variant_posts = $this->getProductVariantPosts($post->ID);
     
    9999                $woo = new WC_Product_Variation($post->ID);
    100100            } else {
    101                 $woo = new WC_Product($post);
     101                $woo = wc_get_product($post);
    102102            }
    103103        }
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce-options.php

    r1639952 r1762067  
    2929        if (get_option('mailchimp_woocommerce_plugin_do_activation_redirect', false)) {
    3030            delete_option('mailchimp_woocommerce_plugin_do_activation_redirect');
     31
     32            // don't do the redirect while activating the plugin through the rest API. ( Bartosz from Woo asked for this )
     33            if ((defined( 'REST_REQUEST' ) && REST_REQUEST)) {
     34                return;
     35            }
     36
    3137            if (!isset($_GET['activate-multi'])) {
    3238                wp_redirect("options-general.php?page=mailchimp-woocommerce");
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce-service.php

    r1735785 r1762067  
    9696    {
    9797        if ($this->hasOption('mailchimp_api_key')) {
    98 
    9998            // register this order is already in process..
    10099            static::$pushed_orders[$order_id] = true;
    101 
    102100            // queue up the single order to be processed.
    103101            $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
     
    168166
    169167        return false;
     168    }
     169
     170    /**
     171     * @param $post_id
     172     */
     173    public function handleNewCoupon($post_id)
     174    {
     175        $this->handleCouponSaved($post_id, new WC_Coupon($post_id));
     176    }
     177
     178    /**
     179     * @param $post_id
     180     * @param null $coupon
     181     */
     182    public function handleCouponSaved($post_id, $coupon = null)
     183    {
     184        if ($coupon instanceof WC_Coupon) {
     185            wp_queue(new MailChimp_WooCommerce_SingleCoupon($post_id));
     186        }
     187    }
     188
     189    /**
     190     * @param $post_id
     191     */
     192    public function handleCouponRestored($post_id)
     193    {
     194        $this->handleCouponSaved($post_id, new WC_Coupon($post_id));
    170195    }
    171196
     
    185210                $this->handleOrderStatusChanged($post_id);
    186211            }
     212        }
     213    }
     214
     215    /**
     216     * @param $post_id
     217     * @return bool
     218     */
     219    public function handlePostTrashed($post_id)
     220    {
     221        if (!$this->hasOption('mailchimp_api_key')) {
     222            return false;
     223        }
     224
     225        switch (get_post_type($post_id)) {
     226            case 'shop_coupon':
     227                mailchimp_get_api()->deletePromoRule(mailchimp_get_store_id(), $post_id);
     228                mailchimp_log('promo_code.deleted', "deleted promo code {$post_id}");
     229                break;
     230        }
     231    }
     232
     233    /**
     234     * @param $post_id
     235     */
     236    public function handlePostRestored($post_id)
     237    {
     238        switch(get_post_type($post_id)) {
     239            case 'shop_coupon':
     240                return $this->handleCouponRestored($post_id);
     241                break;
    187242        }
    188243    }
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce.php

    r1639952 r1762067  
    175175        require_once $path . 'includes/api/class-mailchimp-woocommerce-create-list-submission.php';
    176176        require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-products.php';
     177        require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-coupons.php';
    177178
    178179        /** Require all the mailchimp api asset classes */
     
    185186        require_once $path . 'includes/api/assets/class-mailchimp-product-variation.php';
    186187        require_once $path . 'includes/api/assets/class-mailchimp-store.php';
     188        require_once $path . 'includes/api/assets/class-mailchimp-promo-code.php';
     189        require_once $path . 'includes/api/assets/class-mailchimp-promo-rule.php';
    187190
    188191        /** Require all the api error helpers */
     
    205208        require_once $path.'includes/processes/class-mailchimp-woocommerce-process-orders.php';
    206209        require_once $path.'includes/processes/class-mailchimp-woocommerce-process-products.php';
     210        require_once $path.'includes/processes/class-mailchimp-woocommerce-process-coupons.php';
    207211
    208212        // individual item sync
     
    210214        require_once $path.'includes/processes/class-mailchimp-woocommerce-single-order.php';
    211215        require_once $path.'includes/processes/class-mailchimp-woocommerce-single-product.php';
    212         require_once $path.'includes/processes/class-mailchimp-woocommerce-user-submit.php';
     216        require_once $path.'includes/processes/class-mailchimp-woocommerce-single-coupon.php';
     217        require_once $path.'includes/processes/class-mailchimp-woocommerce-user-submit.php';
    213218
    214219        // fire up the loader
     
    326331            // order hooks
    327332            $this->loader->add_action('woocommerce_thankyou', $service, 'onNewOrder', 1);
    328             $this->loader->add_action('woocommerce_api_create_order', $service, 'handleOrderStatusChanged', 10);
     333            $this->loader->add_action('woocommerce_api_create_order', $service, 'onNewOrder', 10);
    329334            $this->loader->add_action('woocommerce_order_status_changed', $service, 'handleOrderStatusChanged', 2);
    330335
     
    337342            $this->loader->add_action('woocommerce_cart_item_removed', $service, 'handleCartUpdated');
    338343
    339             // save post hook for products
     344            // save post hooks
    340345            $this->loader->add_action('save_post', $service, 'handlePostSaved', 10, 3);
     346            $this->loader->add_action('wp_trash_post', $service, 'handlePostTrashed', 10);
     347            $this->loader->add_action('untrashed_post', $service, 'handlePostRestored', 10);
     348
     349            //coupons
     350            $this->loader->add_action('woocommerce_new_coupon', $service, 'handleNewCoupon', 10);
     351            $this->loader->add_action('woocommerce_coupon_options_save', $service, 'handleCouponSaved', 10, 2);
     352            $this->loader->add_action('woocommerce_api_create_coupon', $service, 'handleCouponSaved', 9, 2);
     353
     354            $this->loader->add_action('woocommerce_delete_coupon', $service, 'handleCouponTrashed', 10);
     355            $this->loader->add_action('woocommerce_trash_coupon', $service, 'handleCouponTrashed', 10);
     356            $this->loader->add_action('woocommerce_api_delete_coupon', $service, 'handleCouponTrashed', 9);
    341357
    342358            // handle the user registration hook
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-abstract-sync.php

    r1735785 r1762067  
    103103        if ($page->count <= 0) {
    104104
    105             mailchimp_debug(get_called_class().'@handle', $this->getResourceType().' :: count is 0 : completing now!');
     105            mailchimp_debug(get_called_class().'@handle', $this->getResourceType().' :: completing now!');
    106106
    107107            // reset the resource page back to 1
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-cart-update.php

    r1735785 r1762067  
    126126                } catch (\Exception $e) {
    127127
    128                     mailchimp_log('abandoned_cart.error', "email: {$customer->getEmailAddress()}");
     128                    mailchimp_error('abandoned_cart.error', "email: {$customer->getEmailAddress()} :: attempting product update :: {$e->getMessage()}");
    129129
    130130                    // if we have an error it's most likely due to a product not being found.
     
    139139                    }
    140140
    141                     mailchimp_log('abandoned_cart.submitting', "email: {$customer->getEmailAddress()}");
    142 
    143141                    // if the post is successful we're all good.
    144142                    $api->addCart($store_id, $cart, false);
     
    150148        } catch (\Exception $e) {
    151149            update_option('mailchimp-woocommerce-cart-error', $e->getMessage());
    152             mailchimp_log('abandoned_cart.error', "{$e->getMessage()} on {$e->getLine()} in {$e->getFile()}");
     150            mailchimp_error('abandoned_cart.error', $e);
    153151        }
    154152
     
    163161    protected function transformLineItem($hash, $item)
    164162    {
    165         $product = new WC_Product($item['product_id']);
     163        $product = wc_get_product($item['product_id']);
     164        $price = $product ? $product->get_price() : 0;
    166165
    167166        $line = new MailChimp_WooCommerce_LineItem();
     
    176175
    177176        $line->setQuantity($item['quantity']);
    178         $line->setPrice($product->get_price());
     177        $line->setPrice($price);
    179178
    180179        return $line;
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-process-orders.php

    r1735785 r1762067  
    5757
    5858                if (empty($response)) {
    59                     mailchimp_log('order_submit.failure', "$call :: #{$item->getId()} :: email: {$item->getCustomer()->getEmailAddress()} produced a blank response from MailChimp");
     59                    mailchimp_error('order_submit.failure', "$call :: #{$item->getId()} :: email: {$item->getCustomer()->getEmailAddress()} produced a blank response from MailChimp");
    6060                    return $response;
    6161                }
     
    6868
    6969            } catch (MailChimp_WooCommerce_ServerError $e) {
    70                 mailchimp_log('order_submit.error', "$call :: {$item->getId()} :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
     70                mailchimp_error('order_submit.error', mailchimp_error_trace($e, "$call :: {$item->getId()}"));
    7171                return false;
    7272            } catch (MailChimp_WooCommerce_Error $e) {
    73                 mailchimp_log('order_submit.error', "$call :: {$item->getId()} :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
     73                mailchimp_error('order_submit.error', mailchimp_error_trace($e, "$call :: {$item->getId()}"));
    7474                return false;
    7575            } catch (Exception $e) {
    76                 mailchimp_log('order_submit.error', "$call :: {$item->getId()} :: Uncaught Exception :: {$e->getMessage()}");
     76                mailchimp_error('order_submit.error', mailchimp_error_trace($e, "$call :: {$item->getId()}"));
    7777                return false;
    7878            }
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-process-products.php

    r1735785 r1762067  
    5757
    5858            } catch (MailChimp_WooCommerce_ServerError $e) {
    59                 mailchimp_log('product_sync.error', "addStoreProduct :: {$item->getId()} :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
     59                mailchimp_error('product_sync.error', mailchimp_error_trace($e, "addStoreProduct :: {$item->getId()}"));
    6060            } catch (MailChimp_WooCommerce_Error $e) {
    61                 mailchimp_log('product_sync.error', "addStoreProduct :: {$item->getId()} :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
     61                mailchimp_error('product_sync.error', mailchimp_error_trace($e, "addStoreProduct :: {$item->getId()}"));
    6262            } catch (Exception $e) {
    63                 mailchimp_log('product_sync.error', "addStoreProduct :: {$item->getId()} :: Uncaught Exception :: {$e->getMessage()}");
     63                mailchimp_error('product_sync.error', mailchimp_error_trace($e, "addStoreProduct :: {$item->getId()}"));
    6464            }
    6565        }
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-single-order.php

    r1735785 r1762067  
    5252
    5353            if (!($woo_order_number = $this->getRealOrderNumber())) {
     54                mailchimp_log('order_submit.failure', "There is no real order number to use.");
    5455                return false;
    5556            }
     
    118119
    119120                if (empty($api_response)) {
    120                     mailchimp_log('order_submit.failure', "$call :: #{$order->getId()} :: email: {$order->getCustomer()->getEmailAddress()} produced a blank response from MailChimp");
     121                    mailchimp_error('order_submit.failure', "$call :: #{$order->getId()} :: email: {$order->getCustomer()->getEmailAddress()} produced a blank response from MailChimp");
    121122                    return $api_response;
    122123                }
     
    134135            } catch (\Exception $e) {
    135136
    136                 mailchimp_log('order_submit.tracing_error', $message = strtolower($e->getMessage()));
     137                $message = strtolower($e->getMessage());
     138
     139                mailchimp_error('order_submit.tracing_error', $e);
    137140
    138141                if (!isset($order)) {
     
    171174
    172175                    } catch (\Exception $e) {
    173                         mailchimp_log('order_submit.error', 'deleting-customer-re-add :: #'.$this->order_id.' :: '.$e->getMessage());
     176                        mailchimp_error('order_submit.error', mailchimp_error_trace($e, 'deleting-customer-re-add :: #'.$this->order_id));
    174177                    }
    175178                }
     
    193196        } catch (\Exception $e) {
    194197            $this->woo_order_number = false;
    195             mailchimp_log('order_sync.failure', "{$this->order_id} could not be loaded {$e->getMessage()}");
     198            mailchimp_error('order_sync.failure', mailchimp_error_trace($e, "{$this->order_id} could not be loaded"));
    196199            return false;
    197200        }
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-single-product.php

    r1735785 r1762067  
    6969
    7070        } catch (MailChimp_WooCommerce_ServerError $e) {
    71             mailchimp_log('product_submit.error', "addStoreProduct :: #{$this->product_id} :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
     71            mailchimp_error('product_submit.error', mailchimp_error_trace($e, "addStoreProduct :: #{$this->product_id}"));
    7272        } catch (MailChimp_WooCommerce_Error $e) {
    73             mailchimp_log('product_submit.error', "addStoreProduct :: #{$this->product_id} :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
     73            mailchimp_log('product_submit.error', mailchimp_error_trace($e, "addStoreProduct :: #{$this->product_id}"));
    7474        } catch (Exception $e) {
    75             mailchimp_log('product_submit.error', "addStoreProduct :: #{$this->product_id} :: Uncaught Exception :: {$e->getMessage()}");
     75            mailchimp_log('product_submit.error', mailchimp_error_trace($e, "addStoreProduct :: #{$this->product_id}"));
    7676        }
    7777
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-user-submit.php

    r1735785 r1762067  
    136136            }
    137137
    138             mailchimp_log('member.sync', $e->getMessage());
     138            mailchimp_error('member.sync', mailchimp_error_trace($e, $user->user_email));
    139139        }
    140140
  • mailchimp-for-woocommerce/trunk/includes/vendor/queue/classes/worker/wp-worker.php

    r1735785 r1762067  
    5555
    5656            try {
    57                 $this->payload->handle();
     57                $this->payload->handle();
    5858
    5959                if ( $this->payload->is_released() ) {
  • mailchimp-for-woocommerce/trunk/mailchimp-woocommerce.php

    r1735785 r1762067  
    1717 * Plugin URI:        https://mailchimp.com/connect-your-store/
    1818 * Description:       MailChimp - WooCommerce plugin
    19  * Version:           2.0.2
     19 * Version:           2.1.0
    2020 * Author:            MailChimp
    2121 * Author URI:        https://mailchimp.com
     
    4444        'repo' => 'master',
    4545        'environment' => 'production',
    46         'version' => '2.0.2',
     46        'version' => '2.1.0',
    4747        'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
    4848        'wc_version' => class_exists('WC') ? WC()->version : null,
     
    270270
    271271/**
     272 * @param $action
     273 * @param $message
     274 * @param array $data
     275 * @return array|WP_Error
     276 */
     277function mailchimp_error($action, $message, $data = array()) {
     278    if (mailchimp_environment_variables()->logging !== 'none') {
     279        if ($message instanceof \Exception) $message = mailchimp_error_trace($message);
     280        if (is_array($data) && !empty($data)) $message .= " :: ".wc_print_r($data, true);
     281        wc_get_logger()->error("{$action} :: {$message}", array('source' => 'mailchimp_woocommerce'));
     282    }
     283}
     284
     285/**
     286 * @param Exception $e
     287 * @param string $wrap
     288 * @return string
     289 */
     290function mailchimp_error_trace(\Exception $e, $wrap = "") {
     291    $error = "{$e->getMessage()} on {$e->getLine()} in {$e->getFile()}";
     292    if (empty($wrap)) return $error;
     293    return "{$wrap} :: {$error}";
     294}
     295
     296/**
    272297 * Determine if a given string contains a given substring.
    273298 *
     
    341366        if (($store = $api->getStore($store_id))) {
    342367
     368            // handle the coupon sync if we don't have a flag that says otherwise.
     369            $job = new MailChimp_WooCommerce_Process_Coupons();
     370            if ($job->getData('sync.coupons.completed_at', false) === false) {
     371                wp_queue($job);
     372            }
     373
    343374            // see if we have a connected site script url/fragment
    344375            $url = $store->getConnectedSiteScriptUrl();
Note: See TracChangeset for help on using the changeset viewer.