Skip to content

Commit

Permalink
Merge pull request #49 from mailerlite/2857-missing-woo-sync-method
Browse files Browse the repository at this point in the history
added missing woo sync customer method
  • Loading branch information
johnkelesidis committed Mar 19, 2021
2 parents 151bbc5 + 65d9289 commit 71df4c8
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/Api/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ class WooCommerce extends ApiAbstract
{
protected $endpoint = 'woocommerce';

public function setConsumerData( $consumerKey, $consumerSecret, $store, $currency, $group_id, $resubscribe )
public function setConsumerData( $consumerKey, $consumerSecret, $store, $currency, $group_id, $resubscribe, $ignoreList, $create_segments)
{
$endpoint = $this->endpoint . '/consumer_data';

$params = array_merge($this->prepareParams(),
['consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret,
'store' => $store,
'currency' => $currency,
'group_id' => $group_id,
'resubscribe' => $resubscribe]);
$params = array_merge($this->prepareParams(),
['consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret,
'store' => $store,
'currency' => $currency,
'group_id' => $group_id,
'resubscribe' => $resubscribe,
'ignore_list' => $ignoreList,
'create_segments' => $create_segments]);

$response = $this->restClient->post( $endpoint, $params );

return $response['body'];
Expand Down Expand Up @@ -51,7 +54,7 @@ public function toggleShopConnection($shop, $activeState)
return $this->restClient->post( $endpoint, $params );
}

public function sendCartData($shopUrl, $cartData)
public function sendCartData($shopUrl, $cartData)
{
$endpoint = 'woocommerce/save_cart';

Expand All @@ -62,23 +65,23 @@ public function sendCartData($shopUrl, $cartData)
} else {
return true;
}
}
}

public function sendSubscriberData($data)
public function sendSubscriberData($data)
{
$endpoint = 'woocommerce/save_subscriber';

$params = array_merge($this->prepareParams(), ['data'=>$data] );
$response = $this->restClient->post( $endpoint, $params );

if (isset($response['body'])){
return $response['body'];
} else {
return false;
}
}

public function sendOrderProcessingData($data)
public function sendOrderProcessingData($data)
{
$endpoint = 'woocommerce/order_processing';

Expand All @@ -92,11 +95,11 @@ public function sendOrderProcessingData($data)
}
}

public function getShopSettings($shopUrl)
public function getShopSettings($shopUrl)
{
$shopName = parse_url($shopUrl, PHP_URL_HOST);
$endpoint = 'woocommerce/settings/'.$shopName;

return $this->restClient->get( $endpoint);
}

Expand All @@ -105,4 +108,18 @@ public function validateAccount()
$endpoint = 'woocommerce/initial_account_settings';
return $this->restClient->get($endpoint);
}

public function syncCustomer($email, $fields, $shopUrl)
{
$endpoint = 'woocommerce/sync_customer';
$params = array_merge($this->prepareParams(), ['email' => $email, 'subscriber_fields' => $fields, 'shop' => $shopUrl] );

$response = $this->restClient->post( $endpoint, $params );

if (isset($response['body'])) {
return $response['body'];
} else {
return true;
}
}
}

0 comments on commit 71df4c8

Please sign in to comment.