Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhungate committed Feb 8, 2018
2 parents 6df73db + 48b90dd commit 0c080f5
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 117 deletions.
11 changes: 8 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: ryanhungate, MailChimp
Tags: ecommerce,email,workflows,mailchimp
Donate link: https://mailchimp.com
Requires at least: 4.3
Tested up to: 4.8
Stable tag: 4.6.1
Tested up to: 4.9
Stable tag: 2.1.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -29,7 +29,7 @@ This plugin supports our most powerful API 3.0 features, and is intended for use

You can run this new integration at the same time as your current WooCommerce integration for MailChimp. However, data from the older integration will display separately in subscriber profiles, and can’t be used with e-commerce features that require API 3.0.

This plugin is not compatible for WordPress.com users at this time.
WordPress.com compatibility is limited to Business tier users only.

== Installation ==
###Before You Start
Expand All @@ -52,6 +52,11 @@ You’ll need to do a few things to connect your WooCommerce store to MailChimp.
For 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)

== Changelog ==
= 2.1.4 =
* updated wordpress compatibility
* updated sync details tab to show more informative stats
* queue job processing performance enhancement
* added an integrity check for queued jobs that were not getting processed

= 2.1.3 =
* Fix subscriber status for repeat transactional customers to stay transactional.
Expand Down
12 changes: 6 additions & 6 deletions admin/partials/mailchimp-woocommerce-admin-tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@

<?php if ($active_tab == 'sync'): ?>
<h2 style="padding-top: 1em;">More Information</h2>
<p>
Need help to connect your store? Visit the MailChimp
<a href="http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce/" target="_blank">Knowledge Base</a>.<br/>
Want to tell us how we're doing?
<a href="https://wordpress.org/support/plugin/mailchimp-for-woocommerce/reviews/" target="_blank">Leave a review on Wordpress.org</a>.
</p>
<ul>
<li>Have a larger store or having issues syncing? Consider using <a href="https://github.com/mailchimp/mc-woocommerce/issues/158" target="_blank">WP-CLI</a>.</li>
<li>Order and customer information will not sync if they contain an Amazon or generic email address.</li>
<li>Need help to connect your store? Visit the MailChimp <a href="http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce/" target="_blank">Knowledge Base</a>.</li>
<li>Want to tell us how we're doing? <a href="https://wordpress.org/support/plugin/mailchimp-for-woocommerce/reviews/" target="_blank">Leave a review on Wordpress.org</a>.</li>
</ul>
<?php endif; ?>

</div><!-- /.wrap -->
53 changes: 25 additions & 28 deletions admin/partials/tabs/store_sync.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,69 @@
<?php

$mailchimp_total_products = $mailchimp_total_orders = 0;
$store_id = mailchimp_get_store_id();
$product_count = mailchimp_get_product_count();
$order_count = mailchimp_get_order_count();
$store_syncing = false;
$last_updated_time = get_option('mailchimp-woocommerce-resource-last-updated');
$sync_started_at = get_option('mailchimp-woocommerce-sync.started_at');
if (!empty($sync_started_at)) {
$sync_started_at = mailchimp_date_local($sync_started_at);
} else {
$sync_started_at = new \DateTime();
}

$sync_completed_at = get_option('mailchimp-woocommerce-sync.completed_at');
if (!empty($sync_completed_at)) {
$sync_completed_at = mailchimp_date_local($sync_completed_at);
} else {
$sync_completed_at = false;
}

$account_name = 'n/a';
$mailchimp_list_name = 'n/a';

if (!empty($last_updated_time)) {
$last_updated_time = mailchimp_date_local($last_updated_time);
}

if (($mailchimp_api = mailchimp_get_api()) && ($store = $mailchimp_api->getStore($store_id))) {

$store_syncing = $store->isSyncing();

if (($account_details = $handler->getAccountDetails())) {
$account_name = $account_details['account_name'];
}

try {
$products = $mailchimp_api->products($store_id, 1, 1);
$mailchimp_total_products = $products['total_items'];
if ($mailchimp_total_products > $product_count) $mailchimp_total_products = $product_count;
} catch (\Exception $e) { $mailchimp_total_products = 0; }

try {
$orders = $mailchimp_api->orders($store_id, 1, 1);
$mailchimp_total_orders = $orders['total_items'];
if ($mailchimp_total_orders > $order_count) $mailchimp_total_orders = $order_count;
} catch (\Exception $e) { $mailchimp_total_orders = 0; }

$mailchimp_list_name = $handler->getListName();
}
?>

<input type="hidden" name="mailchimp_active_settings_tab" value="store_sync"/>

<?php if($store_syncing): ?>
<h2 style="padding-top: 1em;">Sync Progress</h2>
<?php endif; ?>
<h2 style="padding-top: 1em;">Sync Information</h2>

<?php if(!$store_syncing): ?>
<h2 style="padding-top: 1em;">Sync Status</h2>
<?php if ($sync_started_at): ?>
<p><strong>Started:</strong> <i><?php echo $sync_started_at->format('D, M j, Y g:i A'); ?></i></p>
<?php endif; ?>

<p>
<strong>Account Connected:</strong> <?php echo $account_name; ?>
</p>

<p>
<strong>List Connected:</strong> <?php echo $mailchimp_list_name; ?>
</p>

<p>
<strong>Products:</strong> <?php echo $mailchimp_total_products; ?>/<?php echo $product_count; ?>
</p>

<p>
<strong>Orders:</strong> <?php echo $mailchimp_total_orders; ?>/<?php echo $order_count; ?>
</p>
<?php if ($sync_completed_at): ?>
<p><strong>Finished:</strong> <i><?php echo $sync_completed_at->format('D, M j, Y g:i A'); ?></i></p>
<?php endif; ?>

<?php if ($last_updated_time): ?>
<p><strong>Last Updated:</strong> <i><?php echo $last_updated_time->format('D, M j, Y g:i A'); ?></i></p>
<?php endif; ?>

<p><strong>Account Connected:</strong> <?php echo $account_name; ?></p>
<p><strong>List Connected:</strong> <?php echo $mailchimp_list_name; ?></p>
<p><strong>Products Synced:</strong> <?php echo $mailchimp_total_products; ?></p>
<p><strong>Orders Synced:</strong> <?php echo $mailchimp_total_orders; ?></p>

<?php if($mailchimp_api && (!$store_syncing || isset($_GET['resync']) && $_GET['resync'] === '1')): ?>
<h2 style="padding-top: 1em;">Advanced</h2>
<p>
Expand Down
19 changes: 19 additions & 0 deletions includes/api/assets/class-mailchimp-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ class MailChimp_WooCommerce_Order
protected $lines = array();
protected $confirm_and_paid = false;
protected $promos = [];
protected $is_amazon_order = false;

/**
* @param $bool
* @return $this
*/
public function flagAsAmazonOrder($bool)
{
$this->is_amazon_order = (bool) $bool;
return $this;
}

/**
* @return bool
*/
public function isFlaggedAsAmazonOrder()
{
return (bool) $this->is_amazon_order;
}

/**
* @return array
Expand Down
2 changes: 1 addition & 1 deletion includes/api/class-mailchimp-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ protected function applyCurlOptions($method, $url, $params = array(), $headers =
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => array_merge(array(
'content-type: application/json',
"user-agent: MailChimp for WooCommerce/{$env->version}; WordPress/{$env->wp_version}",
"user-agent: MailChimp for WooCommerce/{$env->version}; PHP/{$env->php_version}; WordPress/{$env->wp_version}; Woo/{$env->wc_version};",
), $headers)
);
}
Expand Down
38 changes: 18 additions & 20 deletions includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ public function compile($page = 1, $limit = 5)
if ((($orders = $this->getOrderPosts($page, $limit)) && !empty($orders))) {
foreach ($orders as $post) {
$response->count++;

if ($post->post_status === 'auto-draft') {
$response->drafts++;
continue;
}

$response->valid++;
$response->items[] = $this->transform($post);
$order = $this->transform($post);
if (!$order->isFlaggedAsAmazonOrder()) {
$response->valid++;
$response->items[] = $order;
}
}
}

Expand All @@ -58,6 +62,11 @@ public function transform(WP_Post $post)

$order = new MailChimp_WooCommerce_Order();

// just skip these altogether because we can't submit any amazon orders anyway.
if (mailchimp_string_contains($woo->get_billing_email(), '@marketplace.amazon.com')) {
return $order->flagAsAmazonOrder(true);
}

$order->setId($woo->get_order_number());

// if we have a campaign id let's set it now.
Expand Down Expand Up @@ -284,33 +293,22 @@ public function transformShippingAddress(WC_Order $order)
*/
public function getOrderPosts($page = 1, $posts = 5)
{
$orders = get_posts(array(
'post_type' => wc_get_order_types(),
$params = array(
'post_type' => wc_get_order_types(),
'post_status' => array_keys(wc_get_order_statuses()),
'posts_per_page' => $posts,
'paged' => $page,
'orderby' => 'id',
'order' => 'ASC'
));
'order' => 'ASC',
);

$orders = get_posts($params);
if (empty($orders)) {
sleep(2);

$orders = get_posts(array(
'post_type' => wc_get_order_types(),
'post_status' => array_keys(wc_get_order_statuses()),
'posts_per_page' => $posts,
'paged' => $page,
'orderby' => 'id',
'order' => 'ASC'
));

if (empty($orders)) {
return false;
}
$orders = get_posts($params);
}

return $orders;
return empty($orders) ? false : $orders;
}

/**
Expand Down
38 changes: 17 additions & 21 deletions includes/api/class-mailchimp-woocommerce-transform-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public function compile($page = 1, $limit = 5)
continue;
}

$response->valid++;
$response->items[] = $this->transform($post);
$order = $this->transform($post);
if (!$order->isFlaggedAsAmazonOrder()) {
$response->valid++;
$response->items[] = $order;
}
}
}

Expand Down Expand Up @@ -80,6 +83,11 @@ public function transform(WP_Post $post)

$order->setId($woo->get_order_number());

// just skip these altogether because we can't submit any amazon orders anyway.
if (mailchimp_string_contains($woo->billing_email, '@marketplace.amazon.com')) {
return $order->flagAsAmazonOrder(true);
}

// if we have a campaign id let's set it now.
if (!empty($this->campaign_id)) {
$order->setCampaignId($this->campaign_id);
Expand Down Expand Up @@ -358,34 +366,22 @@ protected function buildLineItem($key, $order_detail)
*/
public function getOrderPosts($page = 1, $posts = 5)
{
$orders = get_posts(array(
$params = array(
'post_type' => 'shop_order',
//'post_status' => 'publish',
'posts_per_page' => $posts,
'paged' => $page,
'orderby' => 'id',
'order' => 'ASC'
));
'order' => 'ASC',
);

if (empty($orders)) {
$orders = get_posts($params);

if (empty($orders)) {
sleep(2);

$orders = get_posts(array(
'post_type' => 'shop_order',
//'post_status' => 'publish',
'posts_per_page' => $posts,
'paged' => $page,
'orderby' => 'id',
'order' => 'ASC'
));

if (empty($orders)) {
return false;
}
$orders = get_posts($params);
}

return $orders;
return empty($orders) ? false : $orders;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions includes/processes/class-mailchimp-woocommerce-single-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public function process()
return false;
}

// skip amazon orders
if ($this->isAmazonOrder()) {
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
return false;
}

$job = new MailChimp_WooCommerce_Transform_Orders();
$api = new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);

Expand Down Expand Up @@ -86,6 +92,12 @@ public function process()
// transform the order
$order = $job->transform($order_post);

// skip amazon orders
if ($order->isFlaggedAsAmazonOrder()) {
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
return false;
}

// if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
if ($call === 'addStoreOrder' && in_array($order->getFinancialStatus(), array('failed', 'cancelled'))) {
return false;
Expand Down Expand Up @@ -205,5 +217,22 @@ public function getRealOrderNumber()
return false;
}
}

/**
* @return bool
*/
public function isAmazonOrder()
{
try {
if (empty($this->order_id) || !($order_post = get_post($this->order_id))) {
return false;
}
$woo = new WC_Order($order_post);
// just skip these altogether because we can't submit any amazon orders anyway.
return mailchimp_string_contains($woo->get_billing_email(), '@marketplace.amazon.com');
} catch (\Exception $e) {
return false;
}
}
}

Loading

0 comments on commit 0c080f5

Please sign in to comment.