Enabled product bundles

This commit is contained in:
Nedim Uka
2018-06-29 14:40:28 +02:00
parent e0514f7f57
commit b5475ff2f1
12004 changed files with 1694047 additions and 1610 deletions

View File

@@ -17,6 +17,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
public $cart_data;
public $ip_address;
/**
* MailChimp_WooCommerce_Cart_Update constructor.
* @param null $uid
@@ -121,10 +122,9 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
try {
// if the post is successful we're all good.
$api->addCart($store_id, $cart, false);
mailchimp_log('abandoned_cart.success', "email: {$customer->getEmailAddress()} :: checkout_url: $checkout_url");
if ($api->addCart($store_id, $cart, false) !== false) {
mailchimp_log('abandoned_cart.success', "email: {$customer->getEmailAddress()} :: checkout_url: $checkout_url");
}
} catch (\Exception $e) {
mailchimp_error('abandoned_cart.error', "email: {$customer->getEmailAddress()} :: attempting product update :: {$e->getMessage()}");

View File

@@ -40,13 +40,13 @@ class MailChimp_WooCommerce_Process_Coupons extends MailChimp_WooCommerce_Abstra
mailchimp_log('coupon_sync.success', "update promo rule :: #{$item->getCode()}");
return $response;
} catch (MailChimp_WooCommerce_ServerError $e) {
mailchimp_error('order_submit.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
return false;
} catch (MailChimp_WooCommerce_Error $e) {
mailchimp_error('order_submit.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
return false;
} catch (Exception $e) {
mailchimp_error('order_submit.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
mailchimp_error('coupons.error', mailchimp_error_trace($e, "update promo rule :: {$item->getCode()}"));
return false;
}
}

View File

@@ -25,14 +25,22 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abstrac
}
/**
* @param MailChimp_WooCommerce_Order $item
*
* @return mixed
* @param $item
* @return bool|mixed
* @throws Exception
*/
protected function iterate($item)
{
if ($item instanceof MailChimp_WooCommerce_Order) {
// see if we need to prevent this order from being submitted.
$email = $item->getCustomer()->getEmailAddress();
// see if we have a bad email
if ($this->shouldSkipOrder($email, $item->getId())) {
return false;
}
// since we're syncing the customer for the first time, this is where we need to add the override
// for subscriber status. We don't get the checkbox until this plugin is actually installed and working!
if (!($status = $item->getCustomer()->getOptInStatus())) {
@@ -101,4 +109,30 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abstrac
// this is the last thing we're doing so it's complete as of now.
$this->flagStopSync();
}
/**
* @param $email
* @param $order_id
* @return bool
*/
protected function shouldSkipOrder($email, $order_id)
{
if (!is_email($email)) {
mailchimp_log('validation.bad_email', "Order #{$order_id} has an invalid email address. Skipping!");
return true;
}
// make sure we can submit this order to MailChimp or skip it.
if (mailchimp_email_is_amazon($email)) {
mailchimp_log('validation.amazon', "Order #{$order_id} was placed through Amazon. Skipping!");
return true;
}
if (mailchimp_email_is_privacy_protected($email)) {
mailchimp_log('validation.gdpr', "Order #{$order_id} is GDPR restricted. Skipping!");
return true;
}
return false;
}
}

View File

@@ -18,6 +18,8 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
public $is_admin_save = false;
public $partially_refunded = false;
protected $woo_order_number = false;
protected $is_amazon_order = false;
protected $is_privacy_restricted = false;
/**
* MailChimp_WooCommerce_Single_Order constructor.
@@ -57,9 +59,13 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
return false;
}
// skip amazon orders
if ($this->isAmazonOrder()) {
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
// see if we need to prevent this order from being submitted.
if ($this->shouldPreventSubmission()) {
if ($this->is_amazon_order) {
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
} elseif ($this->is_privacy_restricted) {
mailchimp_log('validation.gdpr', "Order #{$woo_order_number} is GDPR restricted. Skipping!");
}
return false;
}
@@ -98,10 +104,13 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
// delete the AC cart record.
$deleted_abandoned_cart = !empty($this->cart_session_id) && $api->deleteCartByID($store_id, $this->cart_session_id);
// skip amazon orders
// skip amazon orders and skip privacy protected orders.
if ($order->isFlaggedAsAmazonOrder()) {
mailchimp_log('validation.amazon', "Order #{$woo_order_number} was placed through Amazon. Skipping!");
return false;
} elseif ($order->isFlaggedAsPrivacyProtected()) {
mailchimp_log('validation.gdpr', "Order #{$woo_order_number} is GDPR restricted. Skipping!");
return false;
}
// if the order is in failed or cancelled status - and it's brand new, we shouldn't submit it.
@@ -221,15 +230,22 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
/**
* @return bool
*/
public function isAmazonOrder()
public function shouldPreventSubmission()
{
try {
if (empty($this->order_id) || !($order_post = get_post($this->order_id))) {
return false;
}
$woo = new WC_Order($order_post);
$email = $woo->get_billing_email();
// just skip these altogether because we can't submit any amazon orders anyway.
return mailchimp_string_contains($woo->get_billing_email(), '@marketplace.amazon.com');
$this->is_amazon_order = mailchimp_email_is_amazon($email);
// see if this is a privacy restricted email address.
$this->is_privacy_restricted = mailchimp_email_is_privacy_protected($email);
return $this->is_amazon_order || $this->is_privacy_restricted;
} catch (\Exception $e) {
return false;
}

View File

@@ -65,16 +65,23 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
$user = new WP_User($this->user_id);
if ($user->ID <= 0 || empty($store_id) || !is_array($options)) {
mailchimp_log('member.sync', "Invalid Data For Submission :: {$user->user_email}");
mailchimp_log('member.sync', "Invalid Data For Submission :: {$user->ID}");
return false;
}
}
$email = $user->user_email;
// make sure we don't need to skip this email
if (!is_email($email) || mailchimp_email_is_amazon($email) || mailchimp_email_is_privacy_protected($email)) {
return false;
}
// if we have a null value, we need to grab the correct user meta for is_subscribed
if (is_null($this->subscribed)) {
$user_subscribed = get_user_meta($this->user_id, 'mailchimp_woocommerce_is_subscribed', true);
if ($user_subscribed === '' || $user_subscribed === null) {
mailchimp_log('member.sync', "Skipping sync for {$user->user_email} because no subscriber status has been set");
mailchimp_log('member.sync', "Skipping sync for {$email} because no subscriber status has been set");
return false;
}
$this->subscribed = (bool) $user_subscribed;
@@ -85,7 +92,7 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
// we need a valid api key and list id to continue
if (empty($api_key) || empty($list_id)) {
mailchimp_log('member.sync', "Invalid Api Key or ListID :: {$user->user_email}");
mailchimp_log('member.sync', "Invalid Api Key or ListID :: {$email}");
return false;
}
@@ -108,29 +115,29 @@ class MailChimp_WooCommerce_User_Submit extends WP_Job
try {
// see if we have a member.
$api->member($list_id, $user->user_email);
$api->member($list_id, $email);
// if we're updating a member and the email is different, we need to delete the old person
if (is_array($this->updated_data) && isset($this->updated_data['user_email'])) {
if ($this->updated_data['user_email'] !== $user->user_email) {
if ($this->updated_data['user_email'] !== $email) {
// delete the old
$api->deleteMember($list_id, $this->updated_data['user_email']);
// subscribe the new
$api->subscribe($list_id, $user->user_email, $this->subscribed, $merge_vars);
$api->subscribe($list_id, $email, $this->subscribed, $merge_vars);
mailchimp_log('member.sync', 'Subscriber Swap '.$this->updated_data['user_email'].' to '.$user->user_email, $merge_vars);
mailchimp_log('member.sync', 'Subscriber Swap '.$this->updated_data['user_email'].' to '.$email, $merge_vars);
return false;
}
}
// ok let's update this member
$api->update($list_id, $user->user_email, $this->subscribed, $merge_vars);
$api->update($list_id, $email, $this->subscribed, $merge_vars);
mailchimp_log('member.sync', "Updated Member {$user->user_email}", $merge_vars);
mailchimp_log('member.sync', "Updated Member {$email}", $merge_vars);
} catch (\Exception $e) {
// if we have a 404 not found, we can create the member