Plugin Directory

Changeset 1582981


Ignore:
Timestamp:
01/26/2017 09:27:11 PM (9 years ago)
Author:
MailChimp
Message:

Update to 1.0.8. Add additional order attributes, PHP 5.3 fix

Location:
mailchimp-for-woocommerce
Files:
116 added
14 edited

Legend:

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

    r1514922 r1582981  
    4747
    4848For more information on settings and configuration, please visit our Knowledge Base: [http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce](http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce)
     49
     50== Changelog ==
     51= 1.0.8 =
     52* add landing_site, financial status and discount information for orders
     53* fix to support php 5.3
     54
     55= 1.0.7 =
     56* add options to move, hide and change defaults for opt-in checkbox
     57* add ability to re-sync and display connection details
     58* support for subscriptions without orders
     59* additional small fixes and some internal logging removal
     60
     61= 1.0.6 =
     62* fixed conflict with the plugin updater where the class could not be loaded correctly.
     63* fixed error validation for store name.
     64* fixed cross device abandoned cart url's
     65
     66= 1.0.4 =
     67* fix for Abandoned Carts without cookies
     68
     69= 1.0.3 =
     70* fixed cart posts on dollar amounts greater than 1000
     71
     72= 1.0.2 =
     73* title correction for Product Variants
     74* added installation checks for WooCommerce and phone contact info
     75* support for free orders
     76
     77= 1.0 =
     78* added is_synicng flag to prevent sends during backfill
     79* fix for conflicts with Gravity Forms Pro and installation issues
     80* skip all Amazon orders
     81* allow users to set opt-in for pre-existing customers during first sync
     82* add Plugin Updater
     83
     84= 0.1.22 =
     85* flag quantity as 1 if the product does not manage inventory
     86
     87= 0.1.21 =
     88* php version check to display warnings < 5.5
     89
     90= 0.1.19 =
     91* fix campaign tracking on new orders
     92
     93= 0.1.18 =
     94* check woocommerce dependency before activating the plugin
     95
     96= 0.1.17 =
     97* fix php version syntax errors for array's
     98
     99= 0.1.16 =
     100* fix namespace conflicts
     101* fix free order 0.00 issue
     102* fix product variant naming issue
     103
     104= 0.1.15 =
     105* adding special MailChimp header to requests
     106
     107= 0.1.14 =
     108* removing jquery dependencies
     109
     110= 0.1.13 =
     111* fixing a number format issue on total_spent
     112
     113= 0.1.12 =
     114* skipping orders placed through amazon due to seller agreements
     115
     116= 0.1.11 =
     117* removed an extra debug log that was not needed
     118
     119= 0.1.10 =
     120* altered debug logging and fixed store settings validation requirements
     121
     122= 0.1.9 =
     123* using fallback to stream context during failed patch requests
     124
     125= 0.1.8 =
     126* fixing http request header for larger patch requests
     127
     128= 0.1.7 =
     129* fixing various bugs with the sync and product issues.
     130
     131= 0.1.2 =
     132* fixed admin order update hook.
  • mailchimp-for-woocommerce/trunk/admin/partials/tabs/newsletter_settings.php

    r1557758 r1582981  
    5151            <?php
    5252            if (is_array($mailchimp_lists)) {
     53                $selected_list = isset($options['mailchimp_list']) ? $options['mailchimp_list'] : null;
    5354                foreach ($mailchimp_lists as $key => $value ) {
    54                     echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key === $options['mailchimp_list'], true, false ) . '>' . esc_html( $value ) . '</option>';
     55                    echo '<option value="' . esc_attr( $key ) . '" ' . selected(((string) $key === (string) $selected_list), true, false) . '>' . esc_html( $value ) . '</option>';
    5556                }
    5657            }
  • mailchimp-for-woocommerce/trunk/changelog.md

    r1522130 r1582981  
     1** 1.0.8 **
     2* add landing_site, financial status and discount information for orders
     3* fix to support php 5.3
     4
     5** 1.0.7 **
     6* add options to move, hide and change defaults for opt-in checkbox
     7* add ability to re-sync and display connection details
     8* support for subscriptions without orders
     9* additional small fixes and some internal logging removal
     10
    111** 1.0.6 **
    212* fixed conflict with the plugin updater where the class could not be loaded correctly.
     
    414* fixed cross device abandoned cart url's
    515
     16** 1.0.4 **
     17* fix for Abandoned Carts without cookies
     18
    619** 1.0.3 **
    720* fixed cart posts on dollar amounts greater than 1000
     21
     22** 1.0.2**
     23* title correction for Product Variants
     24* added installation checks for WooCommerce and phone contact info
     25support for free orders
     26
     27** 1.0 **
     28* added is_synicng flag to prevent sends during backfill
     29* fix for conflicts with Gravity Forms Pro and installation issues
     30* skip all Amazon orders
     31* allow users to set opt-in for pre-existing customers during first sync
     32* add Plugin Updater
    833
    934** 0.1.22 **
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-cart.php

    r1557758 r1582981  
    262262
    263263        if (array_key_exists('customer', $data) && is_array($data['customer'])) {
    264             $this->customer = (new MailChimp_WooCommerce_Customer())->fromArray($data['customer']);
     264            $customer = new MailChimp_WooCommerce_Customer();
     265            $this->customer = $customer->fromArray($data['customer']);
    265266        }
    266267
    267268        if (array_key_exists('lines', $data) && is_array($data['lines'])) {
    268269            foreach ($data['lines'] as $line_item) {
    269                 $this->lines[] = (new MailChimp_WooCommerce_LineItem)->fromArray($line_item);
     270                $item = new MailChimp_WooCommerce_LineItem();
     271                $this->lines[] = $item->fromArray($line_item);
    270272            }
    271273        }
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-customer.php

    r1557758 r1582981  
    250250
    251251        if (array_key_exists('address', $data) && is_array($data['address'])) {
    252             $this->address = (new MailChimp_WooCommerce_Address())->fromArray($data['address']);
     252            $address = new MailChimp_WooCommerce_Address();
     253            $this->address = $address->fromArray($data['address']);
    253254        }
    254255
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-order.php

    r1514325 r1582981  
    1212{
    1313    protected $id = null;
     14    protected $landing_site = null;
    1415    protected $customer = null;
    1516    protected $campaign_id = null;
     
    1920    protected $order_total = null;
    2021    protected $tax_total = null;
     22    protected $discount_total = null;
    2123    protected $shipping_total = null;
    2224    protected $updated_at_foreign = null;
     
    3436        return array(
    3537            'id' => 'required|string',
     38            'landing_site' => 'required|string',
    3639            'customer' => 'required',
    3740            'campaign_id' => 'string',
     
    4144            'order_total' => 'required|numeric',
    4245            'tax_total' => 'numeric',
     46            'discount_total' => 'numeric',
    4347            'processed_at_foreign' => 'date',
    4448            'updated_at_foreign' => 'date',
     
    6872
    6973    /**
     74     * @param $landing_site
     75     * @return $this
     76     */
     77    public function setLandingSite($landing_site)
     78    {
     79        $this->landing_site = $landing_site;
     80
     81        return $this;
     82    }
     83
     84    /**
     85     * @return null|string
     86     */
     87    public function getLandingSite()
     88    {
     89        return $this->landing_site;
     90    }
     91
     92    /**
    7093     * @param MailChimp_WooCommerce_Customer $customer
    7194     * @return MailChimp_WooCommerce_Order
     
    241264
    242265    /**
     266     * @return mixed
     267     */
     268    public function getDiscountTotal()
     269    {
     270        return $this->discount_total;
     271    }
     272
     273    /**
     274     * @param mixed $discount_total
     275     * @return MailChimp_WooCommerce_Order
     276     */
     277    public function setDiscountTotal($discount_total)
     278    {
     279        $this->discount_total = $discount_total;
     280
     281        return $this;
     282    }
     283
     284    /**
    243285     * @param \DateTime $time
    244286     * @return $this
     
    348390        return mailchimp_array_remove_empty(array(
    349391            'id' => (string) $this->getId(),
     392            'landing_site' => (string) $this->getLandingSite(),
    350393            'customer' => $this->getCustomer()->toArray(),
    351394            'campaign_id' => (string) $this->getCampaignId(),
     
    355398            'order_total' => floatval($this->getOrderTotal()),
    356399            'tax_total' => floatval($this->getTaxTotal()),
     400            'discount_total' => floatval($this->getDiscountTotal()),
    357401            'shipping_total' => floatval($this->getShippingTotal()),
    358402            'processed_at_foreign' => (string) $this->getProcessedAt(),
     
    375419    {
    376420        $singles = array(
    377             'id', 'campaign_id', 'financial_status', 'fulfillment_status',
    378             'currency_code', 'order_total', 'tax_total', 'processed_at_foreign',
     421            'id', 'landing_site', 'campaign_id', 'financial_status', 'fulfillment_status',
     422            'currency_code', 'order_total', 'tax_total', 'discount_total', 'processed_at_foreign',
    379423            'cancelled_at_foreign', 'updated_at_foreign'
    380424        );
     
    387431
    388432        if (array_key_exists('shipping_address', $data) && is_array($data['shipping_address'])) {
    389             $this->shipping_address = (new MailChimp_WooCommerce_Address())->fromArray($data['shipping_address']);
     433            $shipping = new MailChimp_WooCommerce_Address();
     434            $this->shipping_address = $shipping->fromArray($data['shipping_address']);
    390435        }
    391436
    392437        if (array_key_exists('billing_address', $data) && is_array($data['billing_address'])) {
    393             $this->billing_address = (new MailChimp_WooCommerce_Address())->fromArray($data['billing_address']);
     438            $billing = new MailChimp_WooCommerce_Address();
     439            $this->billing_address = $billing->fromArray($data['billing_address']);
    394440        }
    395441
     
    397443            $this->lines = array();
    398444            foreach ($data['lines'] as $line_item) {
    399                 $this->lines[] = (new MailChimp_WooCommerce_LineItem())->fromArray($line_item);
     445                $item = new MailChimp_WooCommerce_LineItem();
     446                $this->lines[] = $item->fromArray($line_item);
    400447            }
    401448        }
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-product.php

    r1514325 r1582981  
    273273            $this->variants = array();
    274274            foreach ($data['variants'] as $variant) {
    275                 $this->variants[] = (new MailChimp_WooCommerce_ProductVariation())->fromArray($variant);
     275                $variation = new MailChimp_WooCommerce_ProductVariation();
     276                $this->variants[] = $variation->fromArray($variant);
    276277            }
    277278        }
  • mailchimp-for-woocommerce/trunk/includes/api/assets/class-mailchimp-store.php

    r1514325 r1582981  
    334334
    335335        if (array_key_exists('address', $data)) {
    336             $this->address = (new MailChimp_WooCommerce_Address())->fromArray($data['address']);
     336            $address = new MailChimp_WooCommerce_Address();
     337            $this->address = $address->fromArray($data['address']);
    337338        }
    338339
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-api.php

    r1557758 r1582981  
    390390                return false;
    391391            }
    392             return (new MailChimp_WooCommerce_Store)->fromArray($data);
     392            $store = new MailChimp_WooCommerce_Store();
     393            return $store->fromArray($data);
    393394        } catch (MailChimp_WooCommerce_Error $e) {
    394395            return false;
     
    411412
    412413            foreach ($data['stores'] as $store_data) {
    413                 $response[] = (new MailChimp_WooCommerce_Store)->fromArray($store_data);
     414                $store = new MailChimp_WooCommerce_Store();
     415                $response[] = $store->fromArray($store_data);
    414416            }
    415417
     
    456458            $this->validateStoreSubmission($store);
    457459            $data = $this->post("ecommerce/stores", $store->toArray());
    458             return (new MailChimp_WooCommerce_Store)->fromArray($data);
     460            $store = new MailChimp_WooCommerce_Store();
     461            return $store->fromArray($data);
    459462        } catch (\Exception $e) {
    460463            if (!$silent) throw $e;
     
    474477            $this->validateStoreSubmission($store);
    475478            $data = $this->patch("ecommerce/stores/{$store->getId()}", $store->toArray());
    476             return (new MailChimp_WooCommerce_Store)->fromArray($data);
     479            $store = new MailChimp_WooCommerce_Store();
     480            return $store->fromArray($data);
    477481        } catch (\Exception $e) {
    478482            if (!$silent) throw $e;
     
    504508        try {
    505509            $data = $this->get("ecommerce/stores/$store_id/customers/$customer_id");
    506             return (new MailChimp_WooCommerce_Customer)->fromArray($data);
     510            $customer = new MailChimp_WooCommerce_Customer();
     511            return $customer->fromArray($data);
    507512        } catch (MailChimp_WooCommerce_Error $e) {
    508513            return false;
     
    519524        $this->validateStoreSubmission($store);
    520525        $data = $this->post("ecommerce/stores", $store->toArray());
    521         return (new MailChimp_WooCommerce_Customer)->fromArray($data);
     526        $customer = new MailChimp_WooCommerce_Customer();
     527        return $customer->fromArray($data);
    522528    }
    523529
     
    550556        try {
    551557            $data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
    552             return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
     558            $cart = new MailChimp_WooCommerce_Cart();
     559            return $cart->setStoreID($store_id)->fromArray($data);
    553560        } catch (MailChimp_WooCommerce_Error $e) {
    554561            if (!$silent) throw $e;
     
    569576        try {
    570577            $data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
    571             return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
     578            $cart = new MailChimp_WooCommerce_Cart();
     579            return $cart->setStoreID($store_id)->fromArray($data);
    572580        } catch (MailChimp_WooCommerce_Error $e) {
    573581            if (!$silent) throw $e;
     
    586594        try {
    587595            $data = $this->get("ecommerce/stores/$store_id/carts/$id");
    588             return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
     596            $cart = new MailChimp_WooCommerce_Cart();
     597            return $cart->setStoreID($store_id)->fromArray($data);
    589598        } catch (MailChimp_WooCommerce_Error $e) {
    590599            return false;
     
    619628            $this->validateStoreSubmission($customer);
    620629            $data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
    621             return (new MailChimp_WooCommerce_Customer)->fromArray($data);
     630            $customer = new MailChimp_WooCommerce_Customer();
     631            return $customer->fromArray($data);
    622632        } catch (MailChimp_WooCommerce_Error $e) {
    623633            if (!$silent) throw $e;
     
    656666            $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
    657667            update_option('mailchimp-woocommerce-resource-last-updated', time());
    658             return (new MailChimp_WooCommerce_Order)->fromArray($data);
     668            $order = new MailChimp_WooCommerce_Order();
     669            return $order->fromArray($data);
    659670        } catch (\Exception $e) {
    660671            if (!$silent) throw $e;
     
    679690            $id = $order->getId();
    680691            $data = $this->patch("ecommerce/stores/$store_id/orders/$id", $order->toArray());
    681             return (new MailChimp_WooCommerce_Order)->fromArray($data);
     692            $order = new MailChimp_WooCommerce_Order();
     693            return $order->fromArray($data);
    682694        } catch (\Exception $e) {
    683695            if (!$silent) throw $e;
     
    696708        try {
    697709            $data = $this->get("ecommerce/stores/$store_id/orders/$order_id");
    698             return (new MailChimp_WooCommerce_Order)->fromArray($data);
     710            $order = new MailChimp_WooCommerce_Order();
     711            return $order->fromArray($data);
    699712        } catch (MailChimp_WooCommerce_Error $e) {
    700713            return false;
     
    726739        try {
    727740            $data = $this->get("ecommerce/stores/$store_id/products/$product_id");
    728             return (new MailChimp_WooCommerce_Product)->fromArray($data);
     741            $product = new MailChimp_WooCommerce_Product();
     742            return $product->fromArray($data);
    729743        } catch (MailChimp_WooCommerce_Error $e) {
    730744            return false;
     
    762776            $data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
    763777            update_option('mailchimp-woocommerce-resource-last-updated', time());
    764             return (new MailChimp_WooCommerce_Product)->fromArray($data);
     778            $product = new MailChimp_WooCommerce_Product();
     779            return $product->fromArray($data);
    765780        } catch (\Exception $e) {
    766781            if (!$silent) throw $e;
  • mailchimp-for-woocommerce/trunk/includes/api/class-mailchimp-woocommerce-transform-orders.php

    r1514325 r1582981  
    6666        }
    6767
    68         $order->setFulfillmentStatus($woo->get_status());
    6968        $order->setProcessedAt(mailchimp_date_utc($woo->order_date));
    7069
    71         if ($woo->get_status() === 'cancelled') {
    72             $order->setCancelledAt(mailchimp_date_utc($woo->modified_date));
    73         }
    74 
    7570        $order->setCurrencyCode($woo->get_order_currency());
    76         $order->setFinancialStatus($woo->is_paid() ? 'paid' : 'pending');
    77 
     71
     72        // grab the current statuses - this will end up being custom at some point.
     73        $statuses = $this->getOrderStatuses();
     74
     75        // grab the order status
     76        $status = $woo->get_status();
     77
     78        // map the fulfillment and financial statuses based on the map above.
     79        $fulfillment_status = array_key_exists($status, $statuses) ? $statuses[$status]->fulfillment : null;
     80        $financial_status = array_key_exists($status, $statuses) ? $statuses[$status]->financial : $status;
     81
     82        // set the fulfillment_status
     83        $order->setFulfillmentStatus($fulfillment_status);
     84
     85        // set the financial status
     86        $order->setFinancialStatus($financial_status);
     87
     88        // only set this if the order is cancelled.
     89        if ($status === 'cancelled') $order->setCancelledAt(mailchimp_date_utc($woo->modified_date));
     90
     91        // set the total
    7892        $order->setOrderTotal($woo->get_total());
    7993
     
    8397        // if we have shipping.
    8498        $order->setShippingTotal($woo->get_total_shipping());
     99
     100        // set the order discount
     101        $order->setDiscountTotal($woo->get_total_discount());
    85102
    86103        // set the customer
     
    396413        return $address;
    397414    }
     415
     416    /**
     417     * @return array
     418     */
     419    public function getOrderStatuses()
     420    {
     421        return array(
     422            // Order received (unpaid)
     423            'pending'       => (object) array(
     424                'financial' => 'pending',
     425                'fulfillment' => null
     426            ),
     427            // Payment received and stock has been reduced – the order is awaiting fulfillment.
     428            // All product orders require processing, except those for digital downloads
     429            'processing'    => (object) array(
     430                'financial' => 'processing',
     431                'fulfillment' => null
     432            ),
     433            // Awaiting payment – stock is reduced, but you need to confirm payment
     434            'on-hold'       => (object) array(
     435                'financial' => 'on-hold',
     436                'fulfillment' => null
     437            ),
     438            // Order fulfilled and complete – requires no further action
     439            'completed'     => (object) array(
     440                'financial' => 'fulfilled',
     441                'fulfillment' => 'fulfilled'
     442            ),
     443            // Cancelled by an admin or the customer – no further action required
     444            'cancelled'     => (object) array(
     445                'financial' => 'cancelled',
     446                'fulfillment' => null
     447            ),
     448            // Refunded by an admin – no further action required
     449            'refunded'      => (object) array(
     450                'financial' => 'refunded',
     451                'fulfillment' => null
     452            ),
     453            // Payment failed or was declined (unpaid). Note that this status may not show immediately and
     454            // instead show as Pending until verified (i.e., PayPal)
     455            'failed'        => (object) array(
     456                'financial' => 'failed',
     457                'fulfillment' => null
     458            ),
     459        );
     460    }
    398461}
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce-service.php

    r1557758 r1582981  
    1111class MailChimp_Service extends MailChimp_Woocommerce_Options
    1212{
     13    protected static $pushed_orders = array();
     14
    1315    protected $user_email = null;
    1416    protected $previous_email = null;
    1517    protected $force_cart_post = false;
    16     protected $pushed_orders = array();
    1718    protected $cart_was_submitted = false;
    1819    protected $cart = array();
     
    5556
    5657    /**
     58     * This should only fire on a web based order so we can do real campaign tracking here.
     59     *
    5760     * @param $order_id
    5861     */
    59     public function handleOrderStatusChanged($order_id)
    60     {
    61         if ($this->hasOption('mailchimp_api_key') && !array_key_exists($order_id, $this->pushed_orders)) {
     62    public function onNewOrder($order_id)
     63    {
     64        if ($this->hasOption('mailchimp_api_key')) {
    6265
    6366            // register this order is already in process..
    64             $this->pushed_orders[$order_id] = true;
     67            static::$pushed_orders[$order_id] = true;
    6568
    6669            // see if we have a session id and a campaign id, also only do this when this user is not the admin.
    6770            $campaign_id = $this->getCampaignTrackingID();
    6871
     72            // grab the landing site cookie if we have one here.
     73            $landing_site = $this->getLandingSiteCookie();
     74
     75            // expire the landing site cookie so we can rinse and repeat tracking
     76            $this->expireLandingSiteCookie();
     77
     78            mailchimp_log('new_order', "New order #$order_id", array(
     79                'campaign_id' => $campaign_id,
     80                'landing_site' => $landing_site,
     81            ));
     82
    6983            // queue up the single order to be processed.
    70             $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, $campaign_id);
     84            $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, $campaign_id, $landing_site);
    7185            wp_queue($handler);
    7286        }
     
    7488
    7589    /**
    76      * @return bool|void
     90     * @param $order_id
     91     */
     92    public function handleOrderStatusChanged($order_id)
     93    {
     94        if ($this->hasOption('mailchimp_api_key')) {
     95
     96            // register this order is already in process..
     97            static::$pushed_orders[$order_id] = true;
     98
     99            // queue up the single order to be processed.
     100            $handler = new MailChimp_WooCommerce_Single_Order($order_id, null, null, null);
     101            $handler->is_update = true;
     102            wp_queue($handler);
     103        }
     104    }
     105
     106    /**
     107     * @return bool
    77108     */
    78109    public function handleCartUpdated()
     
    235266    public function handleCampaignTracking()
    236267    {
     268        // set the landing site cookie if we don't have one.
     269        $this->setLandingSiteCookie();
     270
    237271        $cookie_duration = $this->getCookieDuration();
    238272
     
    292326        @setcookie('mailchimp_campaign_id', $cid, $cookie_duration, '/' );
    293327        $this->setWooSession('mailchimp_campaign_id', $cid);
     328
     329        return $this;
     330    }
     331
     332    /**
     333     * @return mixed|null
     334     */
     335    public function getLandingSiteCookie()
     336    {
     337        $cookie = $this->cookie('mailchimp_landing_site', false);
     338
     339        if (empty($cookie)) {
     340            $cookie = $this->getWooSession('mailchimp_landing_site', false);
     341        }
     342
     343        return $cookie;
     344    }
     345
     346    /**
     347     * @return $this
     348     */
     349    public function setLandingSiteCookie()
     350    {
     351        if (isset($_GET['expire_landing_site'])) $this->expireLandingSiteCookie();
     352
     353        // if we already have a cookie here, we need to skip it.
     354        if ($this->getLandingSiteCookie() != false) return $this;
     355
     356        if (($http_referer = wp_get_raw_referer()) && !empty($http_referer)) {
     357
     358            // grab the current landing url since it's a referral.
     359            $landing_site = home_url() . wp_unslash($_SERVER['REQUEST_URI']);
     360
     361            $compare_refer = str_replace(array('http://', 'https://'), '', $http_referer);
     362            $compare_local = str_replace(array('http://', 'https://'), '', $landing_site);
     363
     364            if (strpos($compare_local, $compare_refer) === 0) return $this;
     365
     366            // set the cookie
     367            @setcookie('mailchimp_landing_site', $landing_site, $this->getCookieDuration(), '/' );
     368
     369            $this->setWooSession('mailchimp_landing_site', $landing_site);
     370        }
     371
     372        return $this;
     373    }
     374
     375    /**
     376     * @return $this
     377     */
     378    public function expireLandingSiteCookie()
     379    {
     380        @setcookie('mailchimp_landing_site', false, $this->getCookieDuration(), '/' );
     381        $this->setWooSession('mailchimp_landing_site', false);
    294382
    295383        return $this;
     
    535623        exit;
    536624    }
     625
    537626}
  • mailchimp-for-woocommerce/trunk/includes/class-mailchimp-woocommerce.php

    r1557758 r1582981  
    326326
    327327            // order hooks
    328             $this->loader->add_action('woocommerce_api_create_order', $service, 'handleOrderStatusChanged');
    329             $this->loader->add_action('woocommerce_thankyou', $service, 'handleOrderStatusChanged');
    330             $this->loader->add_action('woocommerce_order_status_changed', $service, 'handleOrderStatusChanged');
     328            $this->loader->add_action('woocommerce_thankyou', $service, 'onNewOrder', 1);
     329            $this->loader->add_action('woocommerce_api_create_order', $service, 'handleOrderStatusChanged', 10);
     330            $this->loader->add_action('woocommerce_order_status_changed', $service, 'handleOrderStatusChanged', 2);
    331331
    332332            // cart hooks
     
    390390        return $this->version;
    391391    }
    392 
    393392}
  • mailchimp-for-woocommerce/trunk/includes/processes/class-mailchimp-woocommerce-single-order.php

    r1514325 r1582981  
    1414    public $cart_session_id;
    1515    public $campaign_id;
     16    public $landing_site;
     17    public $is_update = false;
    1618
    1719    /**
     
    2022     * @param null $cart_session_id
    2123     * @param null $campaign_id
     24     * @param null $landing_site
    2225     */
    23     public function __construct($order_id = null, $cart_session_id = null, $campaign_id = null)
     26    public function __construct($order_id = null, $cart_session_id = null, $campaign_id = null, $landing_site = null)
    2427    {
    25         if (!empty($order_id)) {
    26             $this->order_id = $order_id;
    27         }
    28         if (!empty($cart_session_id)) {
    29             $this->cart_session_id = $cart_session_id;
    30         }
    31         if (!empty($campaign_id)) {
    32             $this->campaign_id = $campaign_id;
    33         }
     28        if (!empty($order_id)) $this->order_id = $order_id;
     29        if (!empty($cart_session_id)) $this->cart_session_id = $cart_session_id;
     30        if (!empty($campaign_id)) $this->campaign_id = $campaign_id;
     31        if (!empty($landing_site)) $this->landing_site = $landing_site;
    3432    }
    3533
     
    4038    {
    4139        $this->process();
    42 
    4340        return false;
    4441    }
     
    5855            $job->campaign_id = $this->campaign_id;
    5956
    60             $call = $api->getStoreOrder($store_id, $this->order_id) ? 'updateStoreOrder' : 'addStoreOrder';
     57            $call = ($api_response = $api->getStoreOrder($store_id, $this->order_id)) ? 'updateStoreOrder' : 'addStoreOrder';
     58
     59            if ($call === 'addStoreOrder' && $this->is_update === true) {
     60                return false;
     61            }
    6162
    6263            // if we already pushed this order into the system, we need to unset it now just in case there
     
    6465            if ($call === 'updateStoreOrder') {
    6566                $job->campaign_id = null;
     67                $this->campaign_id = null;
     68                $this->landing_site = null;
    6669            }
    6770
     
    7780                $log = "$call :: #{$order->getId()} :: email: {$order->getCustomer()->getEmailAddress()}";
    7881
    79                 if (!empty($this->campaign_id) && $call === 'addStoreOrder') {
    80                     $log .= ' :: campaign id '.$this->campaign_id;
    81                     $order->setCampaignId($this->campaign_id);
     82                // only do this stuff on new orders
     83                if ($call === 'addStoreOrder') {
     84
     85                    // apply a campaign id if we have one.
     86                    if (!empty($this->campaign_id)) {
     87                        $log .= ' :: campaign id ' . $this->campaign_id;
     88                        $order->setCampaignId($this->campaign_id);
     89                    }
     90
     91                    // apply the landing site if we have one.
     92                    if (!empty($this->landing_site)) {
     93                        $log .= ' :: landing site ' . $this->landing_site;
     94                        $order->setLandingSite($this->landing_site);
     95                    }
     96
    8297                }
    8398
     
    148163    }
    149164}
     165
  • mailchimp-for-woocommerce/trunk/mailchimp-woocommerce.php

    r1557758 r1582981  
    1717 * Plugin URI:        https://mailchimp.com/connect-your-store/
    1818 * Description:       MailChimp - WooCommerce plugin
    19  * Version:           1.0.70
     19 * Version:           1.0.8
    2020 * Author:            MailChimp
    2121 * Author URI:        https://mailchimp.com
     
    4040        'repo' => 'master',
    4141        'environment' => 'production',
    42         'version' => '1.0.70',
     42        'version' => '1.0.8',
    4343        'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
    4444    );
     
    350350}
    351351
     352function mailchimp_woocommerce_add_meta_tags() {
     353    echo '<meta name="referrer" content="always"/>';
     354}
     355
     356add_action('wp_head', 'mailchimp_woocommerce_add_meta_tags');
     357
    352358/** Add the plugin updater function ONLY when they are logged in as admin. */
    353359add_action('admin_init', 'run_mailchimp_plugin_updater');
     
    355361/** Add all the MailChimp hooks. */
    356362run_mailchimp_woocommerce();
     363
     364
Note: See TracChangeset for help on using the changeset viewer.