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 Mar 13, 2018
2 parents a3548ba + 9ecf84b commit cc7233e
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 96 deletions.
30 changes: 26 additions & 4 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
Connect your store to your MailChimp list to track sales, create targeted emails, send abandoned cart emails, and more.

== Description ==
Join the 16 million customers who use MailChimp, the world's largest marketing automation platform, to develop their e-commerce marketing strategy. With the official MailChimp for WooCommerce integration, your customers and their purchase data are automatically synced with your MailChimp account, making it easy to send targeted campaigns, automatically follow up with customers post-purchase, recommend products, recover abandoned carts, and measure the ROI of your marketing efforts. And it's completely free.
Join the 17 million customers who use MailChimp, the world's largest marketing automation platform, to develop their e-commerce marketing strategy. With the official MailChimp for WooCommerce integration, your customers and their purchase data are automatically synced with your MailChimp account, making it easy to send targeted campaigns, automatically follow up with customers post-purchase, recommend products, recover abandoned carts, and measure the ROI of your marketing efforts. And it's completely free.

With MailChimp for WooCommerce, you’ll have the power to:

Expand All @@ -20,9 +20,10 @@ With MailChimp for WooCommerce, you’ll have the power to:
- Showcase product recommendations.
- Track and segment customers based on purchase history and purchase frequency.
- View detailed data on your marketing performance in your MailChimp Dashboard.
- Grow your audience and sell more stuff with Facebook and Instagram Ad Campaigns in MailChimp.
- Find new customers, connect with current ones, and drive them all to your website with [Facebook](https://mailchimp.com/features/facebook-ads/) and [Instagram](https://mailchimp.com/features/instagram-ads/) ads. Then, set up [Google remarketing](https://mailchimp.com/features/google-remarketing-ads/) ads to turn your site visitors into shoppers.
- Automatically embed a pop-up form that converts your website visitors to subscribers.
- Add discount codes created in WooCommerce to your emails and automations with a Promo Code content block
- Create beautiful landing pages that make it easy to highlight your products, promote a sale or giveaway, and grow your list.

###Important Notes
This plugin supports our most powerful API 3.0 features, and is intended for users who have not yet integrated their WooCommerce stores with MailChimp.
Expand All @@ -31,7 +32,7 @@ You can run this new integration at the same time as your current WooCommerce in

WordPress.com compatibility is limited to Business tier users only.

== Installation ==
=== Installation ===
###Before You Start
Here are some things to know before you begin this process.

Expand All @@ -49,9 +50,30 @@ You’ll need to do a few things to connect your WooCommerce store to MailChimp.
- Connect the plugin with your MailChimp API Key.
- Configure your list settings to complete the data sync process.

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)
###Advanced Queue Setup In CLI mode
To optimize the performance of your MailChimp integration - it is recommended that you run the queue in CLI mode.

First define a constant in your config file

`define('DISABLE_WP_HTTP_WORKER', true);`

You have 2 options to run this process:

1. On a cron schedule every minute:

`* * * * * /usr/bin/wp --url=http://yourdomain.com --path=/full/path/to/install/ queue listen`

2. Using a process manager like Monit or Supervisord:

`/usr/bin/wp --url=http://yourdomain.com --path=/full/path/to/install/ queue listen`


== Changelog ==
= 2.1.5 =
* added support for Polish (zloty - zł) and Moldovan Leu currencies
* update currency code for Belarusian Rouble
* queue performance enhancement

= 2.1.4 =
* updated wordpress compatibility
* updated sync details tab to show more informative stats
Expand Down
34 changes: 31 additions & 3 deletions includes/api/class-mailchimp-woocommerce-transform-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function transform(WP_Post $post)

$product->setId($woo->get_id());
$product->setHandle($post->post_name);
$product->setImageUrl(get_the_post_thumbnail_url($post));
$product->setImageUrl($this->getProductImage($post));
$product->setDescription($post->post_content);
$product->setPublishedAtForeign(mailchimp_date_utc($post->post_date));
$product->setTitle($woo->get_title());
Expand Down Expand Up @@ -106,7 +106,7 @@ public function variant($is_variant, $post, $fallback_title = null)

$variant->setId($woo->get_id());
$variant->setUrl($woo->get_permalink());
$variant->setImageUrl(get_the_post_thumbnail_url($post));
$variant->setImageUrl($this->getProductImage($post));
$variant->setPrice($woo->get_price());
$variant->setSku($woo->get_sku());
$variant->setBackorders($woo->backorders_allowed());
Expand Down Expand Up @@ -202,9 +202,37 @@ public function getProductVariantPosts($id)
return $variants;
}

/**
* @param $post_id
* @return false|string
*/
public function getProductImage($post_id)
{
$meta = get_post_meta($post_id);
$key = '_thumbnail_id';
$image_key = $this->getProductImageKey();

if ($meta && is_array($meta) && array_key_exists($key, $meta) && isset($meta[$key][0])) {
$img = wp_get_attachment_image($meta[$key][0], $image_key);
if (!empty($img)) return $img;
}

return get_the_post_thumbnail_url($post_id, $image_key);
}

/**
* @return null|string
*/
public function getProductImageKey()
{
// going to add a setting for this.
return 'post-thumbnail';
}

/**
* @param $id
* @return MailChimp_WooCommerce_Product
* @return bool|MailChimp_WooCommerce_Product
* @throws Exception
*/
public static function deleted($id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function all()
'BSD' => array('Bahamian Dollar', '044'),
'BDT' => array('Bangladeshi Taka', '050'),
'BBD' => array('Barbados Dollar', '052'),
'BYR' => array('Belarussian Rouble', '974'),
'BYN' => array('Belarussian Rouble', '974'),
'BOB' => array('Bolivian Boliviano', '068'),
'BRL' => array('Brazilian Real', '986'),
'GBP' => array('British Pounds Sterling', '826'),
Expand Down Expand Up @@ -65,6 +65,7 @@ public static function all()
'LVL' => array('Latvia Lat', '428'),
'LBP' => array('Lebanese Pound', '422'),
'LTL' => array('Lithuania Litas', '440'),
'MDL' => array('Moldovan Leu', '498'),
'MOP' => array('Macau Pataca', '446'),
'MKD' => array('Macedonian Denar', '807'),
'MGA' => array('Malagascy Ariary', '969'),
Expand All @@ -87,6 +88,7 @@ public static function all()
'PYG' => array('Paraguay Guarani', '600'),
'PEN' => array('Peru New Sol', '604'),
'PHP' => array('Philippine Pesos', '608'),
'PLN' => array('Polish Zloty', '985'),
'QAR' => array('Qatari Riyal', '634'),
'RON' => array('Romanian New Leu', '946'),
'RUB' => array('Russian Federation Ruble', '643'),
Expand Down
6 changes: 4 additions & 2 deletions includes/class-mailchimp-woocommerce-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public static function activate() {
update_option('mailchimp-woocommerce-store_id', uniqid(), 'yes');
}

// try this now for existing stores on an update.
mailchimp_update_connected_site_script();
if (class_exists('MailChimp_WooCommerce_MailChimpApi')) {
// try this now for existing stores on an update.
mailchimp_update_connected_site_script();
}
}

/**
Expand Down
17 changes: 9 additions & 8 deletions includes/class-mailchimp-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ private function activateMailChimpNewsletter()

// adding the ability to render the checkbox on another screen of the checkout page.
$render_on = $service->getOption('mailchimp_checkbox_action', 'woocommerce_after_checkout_billing_form');
$this->loader->add_action($render_on, $service, 'applyNewsletterField', 5);

$this->loader->add_action('woocommerce_ppe_checkout_order_review', $service, 'applyNewsletterField', 5);
$this->loader->add_action('woocommerce_register_form', $service, 'applyNewsletterField', 5);
$this->loader->add_action($render_on, $service, 'applyNewsletterField', 10);

$this->loader->add_action('woocommerce_checkout_order_processed', $service, 'processNewsletterField', 5, 2);
$this->loader->add_action('woocommerce_ppe_do_payaction', $service, 'processPayPalNewsletterField', 5, 1);
$this->loader->add_action('woocommerce_register_post', $service, 'processRegistrationForm', 5, 3);
$this->loader->add_action('woocommerce_ppe_checkout_order_review', $service, 'applyNewsletterField', 10);
$this->loader->add_action('woocommerce_register_form', $service, 'applyNewsletterField', 10);

$this->loader->add_action('woocommerce_checkout_order_processed', $service, 'processNewsletterField', 10, 2);
$this->loader->add_action('woocommerce_ppe_do_payaction', $service, 'processPayPalNewsletterField', 10, 1);
$this->loader->add_action('woocommerce_register_post', $service, 'processRegistrationForm', 10, 3);
}
}

Expand All @@ -329,9 +330,9 @@ private function activateMailChimpService()
$this->loader->add_action( 'init', $service, 'handleCampaignTracking' );

// order hooks
$this->loader->add_action('woocommerce_thankyou', $service, 'onNewOrder', 1);
$this->loader->add_action('woocommerce_thankyou', $service, 'onNewOrder', 10);
$this->loader->add_action('woocommerce_api_create_order', $service, 'onNewOrder', 10);
$this->loader->add_action('woocommerce_order_status_changed', $service, 'handleOrderStatusChanged', 2);
$this->loader->add_action('woocommerce_order_status_changed', $service, 'handleOrderStatusChanged', 10);

// partially refunded
$this->loader->add_action('woocommerce_order_partially_refunded', $service, 'onPartiallyRefunded', 10);
Expand Down
17 changes: 14 additions & 3 deletions includes/processes/class-mailchimp-woocommerce-abstract-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@ public function getStoreID()
*
* @return mixed
*/
public function handle() {
public function handle()
{
global $wpdb;

if (!($this->store_id = $this->getStoreID())) {
mailchimp_debug(get_called_class().'@handle', 'store id not loaded');
$this->delete();
return false;
}

// don't let recursion happen.
if ($this->getResourceType() === 'orders' && $this->getResourceCompleteTime()) {
mailchimp_log('sync.stop', "halting the sync for :: {$this->getResourceType()}");
$this->delete();
return false;
}

Expand All @@ -94,6 +98,8 @@ public function handle() {
// call the completed event to process further
$this->resourceComplete($this->getResourceType());
$this->complete();
$this->delete();

return false;
}

Expand All @@ -110,6 +116,8 @@ public function handle() {
// call the completed event to process further
$this->complete();

$this->delete();

return false;
}

Expand All @@ -118,11 +126,14 @@ public function handle() {
$this->iterate($resource);
}

mailchimp_debug(get_called_class().'@handle', 'queuing up the next job');
$this->delete();

$class_name = get_called_class();
$wpdb->query("DELETE FROM {$wpdb->prefix}queue WHERE job LIKE '%{$class_name}%'");

// this will paginate through all records for the resource type until they return no records.
wp_queue(new static());

mailchimp_debug(get_called_class().'@handle', 'queuing up the next job');
return false;
}

Expand Down
65 changes: 56 additions & 9 deletions includes/vendor/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,69 @@
// Add WP CLI commands
if (defined( 'WP_CLI' ) && WP_CLI) {
try {
/**
* Service push to MailChimp
*
* <type>
* : product_sync order_sync order product
*/
function mailchimp_cli_push_command( $args, $assoc_args ) {
if (is_array($args) && isset($args[0])) {
switch($args[0]) {

case 'product_sync':
wp_queue(new MailChimp_WooCommerce_Process_Products());
WP_CLI::success("queued up the product sync!");
break;

case 'order_sync':
wp_queue(new MailChimp_WooCommerce_Process_Orders());
WP_CLI::success("queued up the order sync!");
break;

case 'order':
if (!isset($args[1])) {
wp_die('You must specify an order id as the 2nd parameter.');
}
wp_queue(new MailChimp_WooCommerce_Single_Order($args[1]));
WP_CLI::success("queued up the order {$args[1]}!");
break;

case 'product':
if (!isset($args[1])) {
wp_die('You must specify a product id as the 2nd parameter.');
}
wp_queue(new MailChimp_WooCommerce_Single_Product($args[1]));
WP_CLI::success("queued up the product {$args[1]}!");
break;
}
}
};

WP_CLI::add_command( 'mailchimp_push', 'mailchimp_cli_push_command');

require_once $queue_folder_path . 'queue/classes/cli/queue-command.php';
WP_CLI::add_command( 'queue', 'Queue_Command' );
} catch (\Exception $e) {}
}

if (!mailchimp_running_in_console() && mailchimp_is_configured()) {
// fire up the http worker container
new WP_Http_Worker($wp_queue);
}

// if we're not running in the console, and the http_worker is not running
if (!mailchimp_running_in_console() && !mailchimp_http_worker_is_running()) {
if (mailchimp_should_init_queue()) {
try {
// fire up the http worker container
new WP_Http_Worker($wp_queue);
// if we do not have a site transient for the queue listener and we have available jobs
if (!get_site_transient('http_worker_queue_listen') && $wp_queue->available_jobs()) {
// set the site transient to expire in 60 seconds so this will not happen too many times.
set_site_transient( 'http_worker_queue_listen', microtime(), 60);
// call the http worker manually
mailchimp_call_http_worker_manually();
// if we do not have a site transient for the queue listener
if (!get_site_transient('http_worker_queue_listen')) {
// set the site transient to expire in 50 seconds so this will not happen too many times
// but still work for cron scripts on the minute mark.
set_site_transient( 'http_worker_queue_listen', microtime(), 50);
// if we have available jobs, call the http worker manually
if ($wp_queue->available_jobs()) {
mailchimp_call_http_worker_manually();
}
}
} catch (\Exception $e) {}
}
Expand Down
Loading

0 comments on commit cc7233e

Please sign in to comment.