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

@@ -31,6 +31,7 @@ class MailChimp_WooCommerce_Order
protected $confirm_and_paid = false;
protected $promos = array();
protected $is_amazon_order = false;
protected $is_privacy_protected = false;
/**
* @param $bool
@@ -50,6 +51,24 @@ class MailChimp_WooCommerce_Order
return (bool) $this->is_amazon_order;
}
/**
* @param $bool
* @return $this
*/
public function flagAsPrivacyProtected($bool)
{
$this->is_privacy_protected = (bool) $bool;
return $this;
}
/**
* @return bool
*/
public function isFlaggedAsPrivacyProtected()
{
return (bool) $this->is_privacy_protected;
}
/**
* @return array
*/

View File

@@ -1,12 +1,7 @@
<?php
/**
* Created by PhpStorm.
*
* User: kingpin
* Email: ryan@vextras.com
* Date: 11/4/15
* Time: 3:35 PM
* Class MailChimp_WooCommerce_MailChimpApi
*/
class MailChimp_WooCommerce_MailChimpApi
{
@@ -67,7 +62,8 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param bool $return_profile
* @return array|bool
* @return array|bool|mixed|null|object
* @throws Exception
*/
public function ping($return_profile = false)
{
@@ -80,7 +76,10 @@ class MailChimp_WooCommerce_MailChimpApi
}
/**
* @return array
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getProfile()
{
@@ -88,7 +87,10 @@ class MailChimp_WooCommerce_MailChimpApi
}
/**
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getAuthorizedApps()
{
@@ -96,7 +98,11 @@ class MailChimp_WooCommerce_MailChimpApi
}
/**
* @return array|bool
* @param $id
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getAuthorizedAppDetails($id)
{
@@ -104,11 +110,12 @@ class MailChimp_WooCommerce_MailChimpApi
}
/**
* Returns an array of ['access_token' => '', 'viewer_token' => '']
*
* @param $client_id
* @param $client_secret
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function linkAuthorizedApp($client_id, $client_secret)
{
@@ -118,7 +125,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @param $email
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function member($list_id, $email)
{
@@ -128,7 +138,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function members($list_id)
{
@@ -138,7 +151,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @param $email
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function deleteMember($list_id, $email)
{
@@ -152,7 +168,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param bool $subscribed
* @param array $merge_fields
* @param array $list_interests
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function subscribe($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
{
@@ -181,7 +200,9 @@ class MailChimp_WooCommerce_MailChimpApi
* @param bool $subscribed
* @param array $merge_fields
* @param array $list_interests
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function update($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
{
@@ -212,7 +233,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param bool $subscribed
* @param array $merge_fields
* @param array $list_interests
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function updateOrCreate($list_id, $email, $subscribed = true, $merge_fields = array(), $list_interests = array())
{
@@ -239,7 +263,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param MailChimp_WooCommerce_CreateListSubmission $submission
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function createList(MailChimp_WooCommerce_CreateListSubmission $submission)
{
@@ -249,7 +276,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param bool $as_list
* @param int $count
* @return array|mixed
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getLists($as_list = false, $count = 100)
{
@@ -285,9 +315,13 @@ class MailChimp_WooCommerce_MailChimpApi
return false;
}
}
/**
* @param $id
* @return mixed
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getList($id)
{
@@ -296,7 +330,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $id
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function deleteList($id)
{
@@ -305,6 +342,9 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @return array|mixed
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getListsWithMergeFields()
{
@@ -319,7 +359,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @param int $count
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function mergeFields($list_id, $count = 10)
{
@@ -330,7 +373,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getInterestGroups($list_id)
{
@@ -345,7 +391,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $list_id
* @param $group_id
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getInterestGroupOptions($list_id, $group_id)
{
@@ -363,7 +412,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param int $count
* @param DateTime|null $since
* @param null $campaign_id
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function orders($store_id, $page = 1, $count = 10, \DateTime $since = null, $campaign_id = null)
{
@@ -393,6 +445,8 @@ class MailChimp_WooCommerce_MailChimpApi
return $store->fromArray($data);
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
@@ -406,12 +460,14 @@ class MailChimp_WooCommerce_MailChimpApi
return $this->get("connected-sites/{$store_id}");
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
/**
* @param $store_id
* @return array|bool
* @return array|bool|mixed|null|object
*/
public function connectSite($store_id)
{
@@ -419,6 +475,8 @@ class MailChimp_WooCommerce_MailChimpApi
return $this->post("connected-sites/{$store_id}/actions/verify-script-installation", array());
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
@@ -444,6 +502,8 @@ class MailChimp_WooCommerce_MailChimpApi
return $response;
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
@@ -521,13 +581,16 @@ class MailChimp_WooCommerce_MailChimpApi
return true;
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
/**
* @param $store_id
* @param string $customer_id
* @return MailChimp_WooCommerce_Customer|bool
* @param $customer_id
* @return bool|MailChimp_WooCommerce_Customer
* @throws Exception
*/
public function getCustomer($store_id, $customer_id)
{
@@ -541,14 +604,18 @@ class MailChimp_WooCommerce_MailChimpApi
}
/**
* @param MailChimp_WooCommerce_Customer $store
* @return MailChimp_WooCommerce_Customer
* @param MailChimp_WooCommerce_Customer $customer
* @return bool|MailChimp_WooCommerce_Customer
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function addCustomer(MailChimp_WooCommerce_Customer $store)
public function addCustomer(MailChimp_WooCommerce_Customer $customer)
{
$this->validateStoreSubmission($store);
$data = $this->post("ecommerce/stores", $store->toArray());
if (!($this->validateStoreSubmission($customer))) {
return false;
}
$data = $this->post("ecommerce/stores", $customer->toArray());
$customer = new MailChimp_WooCommerce_Customer();
return $customer->fromArray($data);
}
@@ -557,7 +624,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param int $page
* @param int $count
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function carts($store_id, $page = 1, $count = 10)
{
@@ -575,11 +645,16 @@ class MailChimp_WooCommerce_MailChimpApi
* @param MailChimp_WooCommerce_Cart $cart
* @param bool $silent
* @return bool|MailChimp_WooCommerce_Cart
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function addCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
{
try {
$email = $cart->getCustomer()->getEmailAddress();
if (mailchimp_email_is_privacy_protected($email) || mailchimp_email_is_amazon($email)) {
return false;
}
$data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
$cart = new MailChimp_WooCommerce_Cart();
return $cart->setStoreID($store_id)->fromArray($data);
@@ -587,6 +662,9 @@ class MailChimp_WooCommerce_MailChimpApi
if (!$silent) throw $e;
mailchimp_log('api.addCart', $e->getMessage());
return false;
} catch (\Exception $e) {
if (!$silent) throw $e;
return false;
}
}
@@ -595,11 +673,16 @@ class MailChimp_WooCommerce_MailChimpApi
* @param MailChimp_WooCommerce_Cart $cart
* @param bool $silent
* @return bool|MailChimp_WooCommerce_Cart
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function updateCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
{
try {
$email = $cart->getCustomer()->getEmailAddress();
if (mailchimp_email_is_privacy_protected($email) || mailchimp_email_is_amazon($email)) {
return false;
}
$data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
$cart = new MailChimp_WooCommerce_Cart();
return $cart->setStoreID($store_id)->fromArray($data);
@@ -607,6 +690,9 @@ class MailChimp_WooCommerce_MailChimpApi
if (!$silent) throw $e;
mailchimp_log('api.updateCart', $e->getMessage());
return false;
} catch (\Exception $e) {
if (!$silent) throw $e;
return false;
}
}
@@ -623,6 +709,8 @@ class MailChimp_WooCommerce_MailChimpApi
return $cart->setStoreID($store_id)->fromArray($data);
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
@@ -638,6 +726,8 @@ class MailChimp_WooCommerce_MailChimpApi
return true;
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
@@ -646,12 +736,15 @@ class MailChimp_WooCommerce_MailChimpApi
* @param MailChimp_WooCommerce_Customer $customer
* @param bool $silent
* @return bool|MailChimp_WooCommerce_Customer
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function updateCustomer($store_id, MailChimp_WooCommerce_Customer $customer, $silent = true)
{
try {
$this->validateStoreSubmission($customer);
if (!$this->validateStoreSubmission($customer)) {
return false;
}
$data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
$customer = new MailChimp_WooCommerce_Customer();
return $customer->fromArray($data);
@@ -665,6 +758,7 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param $customer_id
* @return bool
* @throws Exception
*/
public function deleteCustomer($store_id, $customer_id)
{
@@ -743,7 +837,8 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $store_id
* @param $order_id
* @return MailChimp_WooCommerce_Order|bool
* @return bool|MailChimp_WooCommerce_Order
* @throws Exception
*/
public function getStoreOrder($store_id, $order_id)
{
@@ -760,6 +855,7 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param $order_id
* @return bool
* @throws Exception
*/
public function deleteStoreOrder($store_id, $order_id)
{
@@ -774,7 +870,8 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $store_id
* @param $product_id
* @return MailChimp_WooCommerce_Product|bool
* @return bool|MailChimp_WooCommerce_Product
* @throws Exception
*/
public function getStoreProduct($store_id, $product_id)
{
@@ -791,7 +888,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param int $page
* @param int $count
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function products($store_id, $page = 1, $count = 10)
{
@@ -814,7 +914,9 @@ class MailChimp_WooCommerce_MailChimpApi
public function addStoreProduct($store_id, MailChimp_WooCommerce_Product $product, $silent = true)
{
try {
$this->validateStoreSubmission($product);
if (!$this->validateStoreSubmission($product)) {
return false;
}
$data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
update_option('mailchimp-woocommerce-resource-last-updated', time());
$product = new MailChimp_WooCommerce_Product();
@@ -830,6 +932,7 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param $product_id
* @return bool
* @throws Exception
*/
public function deleteStoreProduct($store_id, $product_id)
{
@@ -841,12 +944,12 @@ class MailChimp_WooCommerce_MailChimpApi
}
}
/**
* @param $store_id
* @param MailChimp_WooCommerce_PromoRule $rule
* @param bool $throw
* @return MailChimp_WooCommerce_PromoRule|bool
* @return bool|MailChimp_WooCommerce_PromoRule
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function addPromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
@@ -867,7 +970,8 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param MailChimp_WooCommerce_PromoRule $rule
* @param bool $throw
* @return MailChimp_WooCommerce_PromoRule|bool
* @return bool|MailChimp_WooCommerce_PromoRule
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function updatePromoRule($store_id, MailChimp_WooCommerce_PromoRule $rule, $throw = true)
@@ -883,8 +987,9 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $store_id
* @param MailChimp_WooCommerce_PromoRule|int $rule
* @param $rule
* @return bool
* @throws Exception
*/
public function deletePromoRule($store_id, $rule)
{
@@ -903,6 +1008,9 @@ class MailChimp_WooCommerce_MailChimpApi
* @param int $page
* @param int $count
* @return array
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getPromoRuleIds($store_id, $page = 1, $count = 10)
{
@@ -926,7 +1034,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param int $page
* @param int $count
* @param bool $return_original
* @return array
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getPromoRules($store_id, $page = 1, $count = 10, $return_original = false)
{
@@ -955,7 +1066,10 @@ class MailChimp_WooCommerce_MailChimpApi
* @param int $page
* @param int $count
* @param bool $return_original
* @return array
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
public function getPromoCodesForRule($store_id, $rule_id, $page = 1, $count = 10, $return_original = false)
{
@@ -982,8 +1096,8 @@ class MailChimp_WooCommerce_MailChimpApi
* @param $store_id
* @param $rule_id
* @param $code_id
*
* @return MailChimp_WooCommerce_PromoCode|bool
* @return bool|MailChimp_WooCommerce_PromoCode
* @throws Exception
*/
public function getPromoCodeForRule($store_id, $rule_id, $code_id)
{
@@ -1000,7 +1114,8 @@ class MailChimp_WooCommerce_MailChimpApi
* @param MailChimp_WooCommerce_PromoRule $rule
* @param MailChimp_WooCommerce_PromoCode $code
* @param bool $throw
* @return MailChimp_WooCommerce_PromoCode|bool
* @return bool|MailChimp_WooCommerce_PromoCode
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function addPromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
@@ -1022,7 +1137,8 @@ class MailChimp_WooCommerce_MailChimpApi
* @param MailChimp_WooCommerce_PromoRule $rule
* @param MailChimp_WooCommerce_PromoCode $code
* @param bool $throw
* @return MailChimp_WooCommerce_PromoCode|bool
* @return bool|MailChimp_WooCommerce_PromoCode
* @throws Exception
* @throws MailChimp_WooCommerce_Error
*/
public function updatePromoCodeForRule($store_id, MailChimp_WooCommerce_PromoRule $rule, MailChimp_WooCommerce_PromoCode $code, $throw = true)
@@ -1048,18 +1164,21 @@ class MailChimp_WooCommerce_MailChimpApi
return (bool) $this->delete("ecommerce/stores/{$store_id}/promo-rules/{$rule_id}/promo-codes/{$code_id}");
} catch (MailChimp_WooCommerce_Error $e) {
return false;
} catch (\Exception $e) {
return false;
}
}
/**
* @param MailChimp_WooCommerce_Store|MailChimp_WooCommerce_Order|MailChimp_WooCommerce_Product|MailChimp_WooCommerce_Customer $target
* @param $target
* @return bool
* @throws MailChimp_WooCommerce_Error
*/
protected function validateStoreSubmission($target)
{
if ($target instanceof MailChimp_WooCommerce_Order) {
return $this->validateStoreOrder($target);
} else if ($target instanceof MailChimp_WooCommerce_Customer) {
return $this->validateStoreCustomer($target);
}
return true;
}
@@ -1070,18 +1189,34 @@ class MailChimp_WooCommerce_MailChimpApi
*/
protected function validateStoreOrder(MailChimp_WooCommerce_Order $order)
{
if (mailchimp_string_contains($order->getCustomer()->getEmailAddress(), array('marketplace.amazon.com'))) {
mailchimp_log('validation.amazon', "Order #{$order->getId()} was placed through Amazon. Skipping!");
if (!$this->validateStoreCustomer($order->getCustomer())) {
return false;
}
return true;
}
/**
* @param MailChimp_WooCommerce_Customer $customer
* @return bool
*/
protected function validateStoreCustomer(MailChimp_WooCommerce_Customer $customer)
{
$email = $customer->getEmailAddress();
if (!is_email($email) || mailchimp_email_is_amazon($email) || mailchimp_email_is_privacy_protected($email)) {
return false;
}
return true;
}
/**
* @param $url
* @param null $params
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
protected function delete($url, $params = null)
{
@@ -1097,8 +1232,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $url
* @param null $params
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
protected function get($url, $params = null)
{
@@ -1140,8 +1277,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $url
* @param $body
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
protected function post($url, $body)
{
@@ -1164,8 +1303,10 @@ class MailChimp_WooCommerce_MailChimpApi
/**
* @param $url
* @param $body
* @return array|bool
* @return array|mixed|null|object
* @throws Exception
* @throws MailChimp_WooCommerce_Error
* @throws MailChimp_WooCommerce_ServerError
*/
protected function put($url, $body)
{

View File

@@ -62,9 +62,13 @@ class MailChimp_WooCommerce_Transform_Orders
$order = new MailChimp_WooCommerce_Order();
$email = $woo->get_billing_email();
// just skip these altogether because we can't submit any amazon orders anyway.
if (mailchimp_string_contains($woo->get_billing_email(), '@marketplace.amazon.com')) {
if (mailchimp_email_is_amazon($email)) {
return $order->flagAsAmazonOrder(true);
} elseif (mailchimp_email_is_privacy_protected($email)) {
return $order->flagAsPrivacyProtected(true);
}
$order->setId($woo->get_order_number());
@@ -101,7 +105,9 @@ class MailChimp_WooCommerce_Transform_Orders
// only set this if the order is cancelled.
if ($status === 'cancelled') {
$order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
if (method_exists($woo, 'get_date_modified')) {
$order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
}
}
// set the total
@@ -113,8 +119,10 @@ class MailChimp_WooCommerce_Transform_Orders
// if we have any tax
$order->setTaxTotal($woo->get_total_tax());
// if we have shipping.
$order->setShippingTotal($woo->get_shipping_total());
// if we have shipping
if (method_exists($woo, 'get_shipping_total')) {
$order->setShippingTotal($woo->get_shipping_total());
}
// set the order discount
$order->setDiscountTotal($woo->get_total_discount());
@@ -138,8 +146,15 @@ class MailChimp_WooCommerce_Transform_Orders
$pid = $order_detail->get_product_id();
try {
$deleted_product = MailChimp_WooCommerce_Transform_Products::deleted($pid);
} catch (\Exception $e) {
mailchimp_log('order.items.error', "Order #{$woo->get_id()} :: Product {$pid} does not exist!");
continue;
}
// check if it exists, otherwise create a new one.
if (($deleted_product = MailChimp_WooCommerce_Transform_Products::deleted($pid))) {
if ($deleted_product) {
// swap out the old item id and product variant id with the deleted version.
$item->setProductId("deleted_{$pid}");
$item->setProductVariantId("deleted_{$pid}");
@@ -171,7 +186,7 @@ class MailChimp_WooCommerce_Transform_Orders
{
$customer = new MailChimp_WooCommerce_Customer();
$customer->setId(md5(trim(strtolower($order->get_billing_email()))));
$customer->setId(mailchimp_hash_trim_lower($order->get_billing_email()));
$customer->setCompany($order->get_billing_company());
$customer->setEmailAddress(trim($order->get_billing_email()));
$customer->setFirstName($order->get_billing_first_name());
@@ -320,6 +335,7 @@ class MailChimp_WooCommerce_Transform_Orders
public function getCustomerOrderTotals($user_id)
{
$customer = new WC_Customer($user_id);
$customer->get_order_count();
$customer->get_total_spent();

View File

@@ -1,12 +1,7 @@
<?php
/**
* Created by PhpStorm.
*
* User: kingpin
* Email: ryan@vextras.com
* Date: 6/18/15
* Time: 11:13 AM
* Class MailChimp_WooCommerce_Error
*/
class MailChimp_WooCommerce_Error extends \Exception
{

View File

@@ -1,12 +1,7 @@
<?php
/**
* Created by PhpStorm.
*
* User: kingpin
* Email: ryan@vextras.com
* Date: 6/18/15
* Time: 11:13 AM
* Class MailChimp_WooCommerce_ServerError
*/
class MailChimp_WooCommerce_ServerError extends MailChimp_WooCommerce_Error
{

View File

@@ -43,12 +43,9 @@ class MailChimp_Newsletter extends MailChimp_WooCommerce_Options
}
// echo out the checkbox.
$checkbox = '<p class="form-row form-row-wide create-account">';
$checkbox .= '<label for="mailchimp_woocommerce_newsletter" class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">';
$checkbox .= '<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="mailchimp_woocommerce_newsletter" type="checkbox" ';
$checkbox .= 'name="mailchimp_woocommerce_newsletter" value="1"'.($status ? ' checked="checked"' : '').'> ';
$checkbox .= '<span>' . $label . '</span>';
$checkbox .= '</label>';
$checkbox = '<p class="form-row form-row-wide mailchimp-newsletter">';
$checkbox .= '<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="mailchimp_woocommerce_newsletter" type="checkbox" name="mailchimp_woocommerce_newsletter" value="1"'.($status ? ' checked="checked"' : '').'> ';
$checkbox .= '<label for="mailchimp_woocommerce_newsletter" class="woocommerce-form__label woocommerce-form__label-for-checkbox inline"><span>' . __($label, 'mailchimp-woocommerce') . '</span></label>';
$checkbox .= '</p>';
$checkbox .= '<div class="clear"></div>';

View File

@@ -0,0 +1,112 @@
<?php
class MailChimp_WooCommerce_Privacy
{
/**
* Privacy policy
*/
public function privacy_policy()
{
if (function_exists( 'wp_add_privacy_policy_content')) {
$content = sprintf(
__( 'When shopping, we keep a record of your email and the cart contents for up to 30 days on our server. This record is kept to repopulate the contents of your cart if you switch devices or needed to come back another day. Read our privacy policy <a href="%s">here</a>.', 'mailchimp-woocommerce' ),
'https://mailchimp.com/legal/privacy/'
);
wp_add_privacy_policy_content('MailChimp for WooCommerce', wp_kses_post(wpautop($content, false)));
}
}
/**
* @param array $exporters
* @return mixed
*/
public function register_exporter($exporters)
{
$exporters['mailchimp-woocommerce'] = array(
'exporter_friendly_name' => __('MailChimp for WooCommerce'),
'callback' => array($this, 'export'),
);
return $exporters;
}
/**
* @param array $erasers
* @return mixed
*/
public function register_eraser($erasers)
{
$erasers['mailchimp-woocommerce'] = array(
'eraser_friendly_name' => __('MailChimp for WooCommerce'),
'callback' => array($this, 'erase'),
);
return $erasers;
}
/**
* @param $email_address
* @param int $page
* @return array
*/
public function export($email_address, $page = 1)
{
global $wpdb;
$uid = mailchimp_hash_trim_lower($email_address);
$data = array();
if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
$table = "{$wpdb->prefix}mailchimp_carts";
$statement = "SELECT * FROM $table WHERE id = %s";
$sql = $wpdb->prepare($statement, $uid);
if (($saved_cart = $wpdb->get_row($sql)) && !empty($saved_cart)) {
$data = array('name' => __('Email Address'), 'value' => $email_address);
}
}
// If nothing found, return nothing
if (is_array($data) && (count($data) < 1)) {
return (array('data' => array(), 'done' => true));
}
return array(
'data' => array(
array(
'group_id' => 'mailchimp_cart',
'group_label' => __( 'MailChimp Shopping Cart Data', 'mailchimp-woocommerce' ),
'item_id' => 'mailing-shopping-cart-1',
'data' => array(
array(
'name' => __( 'User ID', 'mailchimp-woocommerce' ),
'value' => $uid,
),
$data, // this is already an associative array with name and value keys
)
)
),
'done' => true,
);
}
public function erase($email_address, $page = 1)
{
global $wpdb;
$uid = mailchimp_hash_trim_lower($email_address);
$count = 0;
if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
$table = "{$wpdb->prefix}mailchimp_carts";
$sql = $wpdb->prepare("DELETE FROM $table WHERE id = %s", $uid);
$count = $wpdb->query($sql);
}
return array(
'items_removed' => (int) $count,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
}
}

View File

@@ -146,14 +146,21 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
if (($user_email = $this->getCurrentUserEmail())) {
// let's skip this right here - no need to go any further.
if (mailchimp_email_is_privacy_protected($user_email)) {
return !is_null($updated) ? $updated : false;
}
$previous = $this->getPreviousEmailFromSession();
$uid = md5(trim(strtolower($user_email)));
$uid = mailchimp_hash_trim_lower($user_email);
$unique_sid = $this->getUniqueStoreID();
// delete the previous records.
if (!empty($previous) && $previous !== $user_email) {
if ($this->api()->deleteCartByID($this->getUniqueStoreID(), $previous_email = md5(trim(strtolower($previous))))) {
if ($this->api()->deleteCartByID($unique_sid, $previous_email = mailchimp_hash_trim_lower($previous))) {
mailchimp_log('ac.cart_swap', "Deleted cart [$previous] :: ID [$previous_email]");
}
@@ -161,6 +168,9 @@ class MailChimp_Service extends MailChimp_WooCommerce_Options
$this->deleteCart($previous_email);
}
// delete the current cart record if there is one
$this->api()->deleteCartByID($unique_sid, $uid);
if ($this->cart && !empty($this->cart)) {
// track the cart locally so we can repopulate things for cross device compatibility.

View File

@@ -27,131 +27,138 @@
* @subpackage MailChimp_WooCommerce/includes
* @author Ryan Hungate <ryan@vextras.com>
*/
class MailChimp_WooCommerce {
class MailChimp_WooCommerce
{
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var MailChimp_WooCommerce_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var MailChimp_WooCommerce_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* @var string
*/
protected $environment = 'production';
/**
* @var string
*/
protected $environment = 'production';
protected static $logging_config = null;
protected $is_configured;
/**
* @return object
*/
public static function getLoggingConfig()
{
if (is_object(static::$logging_config)) {
return static::$logging_config;
}
protected static $logging_config = null;
$plugin_options = get_option('mailchimp-woocommerce');
$is_options = is_array($plugin_options);
/**
* @return object
*/
public static function getLoggingConfig()
{
if (is_object(static::$logging_config)) {
return static::$logging_config;
}
$api_key = $is_options && array_key_exists('mailchimp_api_key', $plugin_options) ?
$plugin_options['mailchimp_api_key'] : false;
$plugin_options = get_option('mailchimp-woocommerce');
$is_options = is_array($plugin_options);
$enable_logging = $is_options &&
array_key_exists('mailchimp_debugging', $plugin_options) &&
$plugin_options['mailchimp_debugging'];
$api_key = $is_options && array_key_exists('mailchimp_api_key', $plugin_options) ?
$plugin_options['mailchimp_api_key'] : false;
$account_id = $is_options && array_key_exists('mailchimp_account_info_id', $plugin_options) ?
$plugin_options['mailchimp_account_info_id'] : false;
$enable_logging = $is_options &&
array_key_exists('mailchimp_debugging', $plugin_options) &&
$plugin_options['mailchimp_debugging'];
$username = $is_options && array_key_exists('mailchimp_account_info_username', $plugin_options) ?
$plugin_options['mailchimp_account_info_username'] : false;
$account_id = $is_options && array_key_exists('mailchimp_account_info_id', $plugin_options) ?
$plugin_options['mailchimp_account_info_id'] : false;
$api_key_parts = str_getcsv($api_key, '-');
$data_center = isset($api_key_parts[1]) ? $api_key_parts[1] : 'us1';
$username = $is_options && array_key_exists('mailchimp_account_info_username', $plugin_options) ?
$plugin_options['mailchimp_account_info_username'] : false;
return static::$logging_config = (object) array(
'enable_logging' => (bool) $enable_logging,
'account_id' => $account_id,
'username' => $username,
'endpoint' => 'https://ecommerce.'.$data_center.'.list-manage.com/ecommerce/log',
);
}
$api_key_parts = str_getcsv($api_key, '-');
$data_center = isset($api_key_parts[1]) ? $api_key_parts[1] : 'us1';
return static::$logging_config = (object)array(
'enable_logging' => (bool)$enable_logging,
'account_id' => $account_id,
'username' => $username,
'endpoint' => 'https://ecommerce.' . $data_center . '.list-manage.com/ecommerce/log',
);
}
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @param string $environment
* @param string $version
*
* @since 1.0.0
*/
public function __construct($environment = 'production', $version = '1.0.0') {
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @param string $environment
* @param string $version
*
* @since 1.0.0
*/
public function __construct($environment = 'production', $version = '1.0.0')
{
$this->plugin_name = 'mailchimp-woocommerce';
$this->version = $version;
$this->environment = $environment;
$this->plugin_name = 'mailchimp-woocommerce';
$this->version = $version;
$this->environment = $environment;
$this->is_configured = mailchimp_is_configured();
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
$this->define_gdpr_hooks();
$this->activateMailChimpNewsletter();
$this->activateMailChimpService();
}
$this->activateMailChimpNewsletter();
$this->activateMailChimpService();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - MailChimp_WooCommerce_Loader. Orchestrates the hooks of the plugin.
* - MailChimp_WooCommerce_i18n. Defines internationalization functionality.
* - MailChimp_WooCommerce_Admin. Defines all hooks for the admin area.
* - MailChimp_WooCommerce_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - MailChimp_WooCommerce_Loader. Orchestrates the hooks of the plugin.
* - MailChimp_WooCommerce_i18n. Defines internationalization functionality.
* - MailChimp_WooCommerce_Admin. Defines all hooks for the admin area.
* - MailChimp_WooCommerce_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies()
{
global $wp_queue;
if (empty($wp_queue)) {
$wp_queue = new WP_Queue();
}
// fire up the loader
$this->loader = new MailChimp_WooCommerce_Loader();
// fire up the loader
$this->loader = new MailChimp_WooCommerce_Loader();
if (!mailchimp_running_in_console() && mailchimp_is_configured()) {
// fire up the http worker container
@@ -165,7 +172,7 @@ class MailChimp_WooCommerce {
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);
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();
@@ -173,21 +180,34 @@ class MailChimp_WooCommerce {
}
} catch (\Exception $e) {}
}
}
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the MailChimp_WooCommerce_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new MailChimp_WooCommerce_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the MailChimp_WooCommerce_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale()
{
$plugin_i18n = new MailChimp_WooCommerce_i18n();
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
}
/**
* Define the GDPR additions from Automattic.
*/
private function define_gdpr_hooks()
{
$gdpr = new MailChimp_WooCommerce_Privacy();
$this->loader->add_action('admin_init', $gdpr, 'privacy_policy');
$this->loader->add_filter('wp_privacy_personal_data_exporters', $gdpr, 'register_exporter', 10);
$this->loader->add_filter('wp_privacy_personal_data_erasers', $gdpr, 'register_eraser', 10);
}
/**
* Register all of the hooks related to the admin area functionality
@@ -241,7 +261,7 @@ class MailChimp_WooCommerce {
{
$service = new MailChimp_Newsletter();
if ($service->isConfigured()) {
if ($this->is_configured && $service->isConfigured()) {
$service->setEnvironment($this->environment);
$service->setVersion($this->version);
@@ -316,11 +336,13 @@ class MailChimp_WooCommerce {
// handle the user updated profile hook
$this->loader->add_action('profile_update', $service, 'handleUserUpdated', 10, 2);
// when someone deletes a user??
//$this->loader->add_action('delete_user', $service, 'handleUserDeleting');
// get user by hash ( public and private )
$this->loader->add_action('wp_ajax_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
$this->loader->add_action('wp_ajax_nopriv_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
$this->loader->add_action('wp_ajax_nopriv_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
$this->loader->add_action('wp_ajax_nopriv_mailchimp_set_user_by_email', $service, 'set_user_by_email');
// set user by email hash ( public and private )
$this->loader->add_action('wp_ajax_mailchimp_set_user_by_email', $service, 'set_user_by_email');
$this->loader->add_action('wp_ajax_nopriv_mailchimp_set_user_by_email', $service, 'set_user_by_email');
}
}
@@ -363,81 +385,4 @@ class MailChimp_WooCommerce {
public function get_version() {
return $this->version;
}
/**
* This is just in case we ever needed to revert back to the old loading
*/
protected function manual_file_loader()
{
$path = plugin_dir_path(dirname( __FILE__ ));
/** The abstract options class.*/
require_once $path . 'includes/class-mailchimp-woocommerce-options.php';
/** The class responsible for orchestrating the actions and filters of the core plugin.*/
require_once $path . 'includes/class-mailchimp-woocommerce-loader.php';
/** The class responsible for defining internationalization functionality of the plugin. */
require_once $path . 'includes/class-mailchimp-woocommerce-i18n.php';
/** The service class.*/
require_once $path . 'includes/class-mailchimp-woocommerce-service.php';
/** The newsletter class. */
require_once $path . 'includes/class-mailchimp-woocommerce-newsletter.php';
/** The class responsible for defining all actions that occur in the admin area.*/
require_once $path . 'admin/class-mailchimp-woocommerce-admin.php';
/** The class responsible for defining all actions that occur in the public-facing side of the site. */
require_once $path . 'public/class-mailchimp-woocommerce-public.php';
/** Require all the MailChimp Assets for the API */
require_once $path . 'includes/api/class-mailchimp-api.php';
require_once $path . 'includes/api/class-mailchimp-woocommerce-api.php';
require_once $path . 'includes/api/class-mailchimp-woocommerce-create-list-submission.php';
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-orders-wc3.php';
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-products.php';
require_once $path . 'includes/api/class-mailchimp-woocommerce-transform-coupons.php';
/** Require all the mailchimp api asset classes */
require_once $path . 'includes/api/assets/class-mailchimp-address.php';
require_once $path . 'includes/api/assets/class-mailchimp-cart.php';
require_once $path . 'includes/api/assets/class-mailchimp-customer.php';
require_once $path . 'includes/api/assets/class-mailchimp-line-item.php';
require_once $path . 'includes/api/assets/class-mailchimp-order.php';
require_once $path . 'includes/api/assets/class-mailchimp-product.php';
require_once $path . 'includes/api/assets/class-mailchimp-product-variation.php';
require_once $path . 'includes/api/assets/class-mailchimp-store.php';
require_once $path . 'includes/api/assets/class-mailchimp-promo-code.php';
require_once $path . 'includes/api/assets/class-mailchimp-promo-rule.php';
/** Require all the api error helpers */
require_once $path . 'includes/api/errors/class-mailchimp-error.php';
require_once $path . 'includes/api/errors/class-mailchimp-server-error.php';
/** Require the various helper scripts */
require_once $path . 'includes/api/helpers/class-mailchimp-woocommerce-api-currency-codes.php';
require_once $path . 'includes/api/helpers/class-mailchimp-woocommerce-api-locales.php';
/** Background job sync tools */
// make sure the queue exists first since the other files depend on it.
require_once $path . 'includes/vendor/queue.php';
// the abstract bulk sync class
require_once $path.'includes/processes/class-mailchimp-woocommerce-abstract-sync.php';
// bulk data sync
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-orders.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-products.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-process-coupons.php';
// individual item sync
require_once $path.'includes/processes/class-mailchimp-woocommerce-cart-update.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-order.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-product.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-single-coupon.php';
require_once $path.'includes/processes/class-mailchimp-woocommerce-user-submit.php';
}
}

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