Added login request
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:22 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Address
|
||||
{
|
||||
protected $type;
|
||||
protected $name;
|
||||
protected $address1;
|
||||
protected $address2;
|
||||
protected $city;
|
||||
protected $province;
|
||||
protected $province_code;
|
||||
protected $postal_code;
|
||||
protected $country;
|
||||
protected $country_code;
|
||||
protected $longitude;
|
||||
protected $latitude;
|
||||
protected $phone;
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'address1' => 'string',
|
||||
'address2' => 'string',
|
||||
'city' => 'string',
|
||||
'province' => 'string',
|
||||
'province_code' => 'string|digits:2',
|
||||
'postal_code' => 'string',
|
||||
'country' => 'string',
|
||||
'country_code' => 'string|digits:2',
|
||||
'latitude' => 'numeric',
|
||||
'longitude' => 'numeric',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $name
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAddress1()
|
||||
{
|
||||
return $this->address1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $address1
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setAddress1($address1)
|
||||
{
|
||||
$this->address1 = $address1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAddress2()
|
||||
{
|
||||
return $this->address2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $address2
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setAddress2($address2)
|
||||
{
|
||||
$this->address2 = $address2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $city
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setCity($city)
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProvince()
|
||||
{
|
||||
return $this->province;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $province
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setProvince($province)
|
||||
{
|
||||
$this->province = $province;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProvinceCode()
|
||||
{
|
||||
return $this->province_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $province_code
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setProvinceCode($province_code)
|
||||
{
|
||||
$this->province_code = $province_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPostalCode()
|
||||
{
|
||||
return $this->postal_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $postal_code
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setPostalCode($postal_code)
|
||||
{
|
||||
$this->postal_code = $postal_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCountry()
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $country
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setCountry($country)
|
||||
{
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCountryCode()
|
||||
{
|
||||
return $this->country_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $country_code
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setCountryCode($country_code)
|
||||
{
|
||||
$this->country_code = $country_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLongitude()
|
||||
{
|
||||
return $this->longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $longitude
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setLongitude($longitude)
|
||||
{
|
||||
$this->longitude = $longitude;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLatitude()
|
||||
{
|
||||
return $this->latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $latitude
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setLatitude($latitude)
|
||||
{
|
||||
$this->latitude = $latitude;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $phone
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setPhone($phone)
|
||||
{
|
||||
$this->phone = $phone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCompany()
|
||||
{
|
||||
return $this->company;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $company
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function setCompany($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'name' => (string) $this->name,
|
||||
'address1' => (string) $this->address1,
|
||||
'address2' => (string) $this->address2,
|
||||
'city' => (string) $this->city,
|
||||
'province' => (string) $this->province,
|
||||
'province_code' => (string) $this->province_code,
|
||||
'postal_code' => (string) $this->postal_code,
|
||||
'country' => (string) $this->country,
|
||||
'country_code' => (string) $this->country_code,
|
||||
'longitude' => ($this->longitude ? (int) $this->longitude : null),
|
||||
'latitude' => ($this->latitude ? (int) $this->latitude : null),
|
||||
'phone' => (string) $this->phone,
|
||||
'company' => (string) $this->company,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'name', 'address1', 'address2', 'city',
|
||||
'province', 'province_code', 'postal_code',
|
||||
'country', 'country_code', 'longitude',
|
||||
'phone', 'company',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/15/16
|
||||
* Time: 1:26 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Cart
|
||||
{
|
||||
protected $store_id;
|
||||
protected $id;
|
||||
protected $customer;
|
||||
protected $campaign_id;
|
||||
protected $checkout_url;
|
||||
protected $currency_code;
|
||||
protected $order_total;
|
||||
protected $tax_total;
|
||||
protected $lines = array();
|
||||
|
||||
/**
|
||||
* @param $unique_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($unique_id)
|
||||
{
|
||||
$this->id = $unique_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $store_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setStoreID($store_id)
|
||||
{
|
||||
$this->store_id = $store_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStoreID()
|
||||
{
|
||||
if (empty($this->store_id)) {
|
||||
$this->store_id = mailchimp_get_store_id();
|
||||
}
|
||||
|
||||
return $this->store_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Customer $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomer(MailChimp_WooCommerce_Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
if (empty($this->customer)) {
|
||||
$this->customer = new MailChimp_WooCommerce_Customer();
|
||||
}
|
||||
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setCampaignID($id)
|
||||
{
|
||||
$this->campaign_id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCampaignID()
|
||||
{
|
||||
return $this->campaign_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return $this
|
||||
*/
|
||||
public function setCheckoutUrl($url)
|
||||
{
|
||||
$this->checkout_url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCheckoutURL()
|
||||
{
|
||||
if (empty($this->checkout_url)) {
|
||||
$this->checkout_url = wc_get_checkout_url();
|
||||
}
|
||||
|
||||
return $this->checkout_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return $this
|
||||
*/
|
||||
public function setCurrencyCode($code)
|
||||
{
|
||||
$this->currency_code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode()
|
||||
{
|
||||
if (empty($this->currency_code)) {
|
||||
$options = get_option('mailchimp-woocommerce', array());
|
||||
$this->currency_code = isset($options['store_currency_code']) ? $options['store_currency_code'] : 'USD';
|
||||
}
|
||||
|
||||
return $this->currency_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $total
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderTotal($total)
|
||||
{
|
||||
$this->order_total = $total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getOrderTotal()
|
||||
{
|
||||
return $this->order_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $total
|
||||
* @return $this
|
||||
*/
|
||||
public function setTaxTotal($total)
|
||||
{
|
||||
$this->tax_total = $total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTaxTotal()
|
||||
{
|
||||
return $this->tax_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_LineItem $item
|
||||
* @return $this
|
||||
*/
|
||||
public function addItem(MailChimp_WooCommerce_LineItem $item)
|
||||
{
|
||||
$this->lines[] = $item;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->getId(),
|
||||
'customer' => $this->getCustomer()->toArray(),
|
||||
'campaign_id' => (string) $this->getCampaignID(),
|
||||
'checkout_url' => (string) $this->getCheckoutURL(),
|
||||
'currency_code' => (string) $this->getCurrencyCode(),
|
||||
'order_total' => floatval($this->getOrderTotal()),
|
||||
'tax_total' => $this->getTaxTotal() > 0 ? floatval($this->getTaxTotal()) : null,
|
||||
'lines' => array_map(function($item) {
|
||||
return $item->toArray();
|
||||
}, $this->items()),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArrayForUpdate()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'campaign_id' => (string) $this->getCampaignID(),
|
||||
'checkout_url' => (string) $this->getCheckoutURL(),
|
||||
'currency_code' => (string) $this->getCurrencyCode(),
|
||||
'order_total' => $this->getOrderTotal(),
|
||||
'tax_total' => ($this->getTaxTotal() > 0 ? $this->getTaxTotal() : null),
|
||||
'lines' => array_map(function($item) {
|
||||
return $item->toArray();
|
||||
}, $this->items()),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Cart
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'store_id', 'id', 'campaign_id', 'checkout_url',
|
||||
'currency_code', 'order_total', 'tax_total',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('customer', $data) && is_array($data['customer'])) {
|
||||
$customer = new MailChimp_WooCommerce_Customer();
|
||||
$this->customer = $customer->fromArray($data['customer']);
|
||||
}
|
||||
|
||||
if (array_key_exists('lines', $data) && is_array($data['lines'])) {
|
||||
foreach ($data['lines'] as $line_item) {
|
||||
$item = new MailChimp_WooCommerce_LineItem();
|
||||
$this->lines[] = $item->fromArray($line_item);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:16 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Customer
|
||||
{
|
||||
protected $id = null;
|
||||
protected $email_address = null;
|
||||
protected $opt_in_status = null;
|
||||
protected $company = null;
|
||||
protected $first_name = null;
|
||||
protected $last_name = null;
|
||||
protected $orders_count = null;
|
||||
protected $total_spent = null;
|
||||
protected $address;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required',
|
||||
'email_address' => 'required|email',
|
||||
'opt_in_status' => 'required|boolean',
|
||||
'company' => 'string',
|
||||
'first_name' => 'string',
|
||||
'last_name' => 'string',
|
||||
'orders_count' => 'integer',
|
||||
'total_spent' => 'integer',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getEmailAddress()
|
||||
{
|
||||
return $this->email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $email_address
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setEmailAddress($email_address)
|
||||
{
|
||||
$this->email_address = $email_address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getOptInStatus()
|
||||
{
|
||||
return $this->opt_in_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $opt_in_status
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setOptInStatus($opt_in_status)
|
||||
{
|
||||
$this->opt_in_status = $opt_in_status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCompany()
|
||||
{
|
||||
return $this->company;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $company
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setCompany($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->first_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $first_name
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setFirstName($first_name)
|
||||
{
|
||||
$this->first_name = $first_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $last_name
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setLastName($last_name)
|
||||
{
|
||||
$this->last_name = $last_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getOrdersCount()
|
||||
{
|
||||
return $this->orders_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $orders_count
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setOrdersCount($orders_count)
|
||||
{
|
||||
$this->orders_count = $orders_count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTotalSpent()
|
||||
{
|
||||
return $this->total_spent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $total_spent
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setTotalSpent($total_spent)
|
||||
{
|
||||
$this->total_spent = $total_spent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
if (empty($this->address)) {
|
||||
$this->address = new MailChimp_WooCommerce_Address();
|
||||
}
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Address $address
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function setAddress(MailChimp_WooCommerce_Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$address = $this->getAddress()->toArray();
|
||||
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->getId(),
|
||||
'email_address' => (string) $this->getEmailAddress(),
|
||||
'opt_in_status' => $this->getOptInStatus(),
|
||||
'company' => (string) $this->getCompany(),
|
||||
'first_name' => (string) $this->getFirstName(),
|
||||
'last_name' => (string) $this->getLastName(),
|
||||
'orders_count' => (int) $this->getOrdersCount(),
|
||||
'total_spent' => floatval(number_format($this->getTotalSpent(), 2)),
|
||||
'address' => (empty($address) ? null : $address),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'email_address', 'opt_in_status', 'company',
|
||||
'first_name', 'last_name', 'orders_count', 'total_spent',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('address', $data) && is_array($data['address'])) {
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
$this->address = $address->fromArray($data['address']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:16 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_LineItem
|
||||
{
|
||||
protected $id;
|
||||
protected $product_id;
|
||||
protected $product_variant_id;
|
||||
protected $quantity;
|
||||
protected $price;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required|string',
|
||||
'product_id' => 'required|string',
|
||||
'product_variant_id' => 'required|string',
|
||||
'quantity' => 'required|integer',
|
||||
'price' => 'required|numeric',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $product_id
|
||||
* @param $variant_id
|
||||
* @param $quantity
|
||||
* @param $price
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public static function make($id, $product_id, $variant_id, $quantity, $price)
|
||||
{
|
||||
$item = new MailChimp_WooCommerce_LineItem();
|
||||
$item->id = $id;
|
||||
$item->product_id = $product_id;
|
||||
$item->product_variant_id = $variant_id;
|
||||
$item->quantity = $quantity;
|
||||
$item->price = $price;
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProductId()
|
||||
{
|
||||
return $this->product_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $product_id
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function setProductId($product_id)
|
||||
{
|
||||
$this->product_id = $product_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProductVariantId()
|
||||
{
|
||||
return $this->product_variant_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $product_variant_id
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function setProductVariantId($product_variant_id)
|
||||
{
|
||||
$this->product_variant_id = $product_variant_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $quantity
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $price
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function setPrice($price)
|
||||
{
|
||||
$this->price = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->id,
|
||||
'product_id' => (string) $this->product_id,
|
||||
'product_variant_id' => (string) $this->product_variant_id,
|
||||
'quantity' => (int) $this->quantity,
|
||||
'price' => (string) $this->price,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'product_id', 'product_variant_id', 'quantity', 'price',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:16 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Order
|
||||
{
|
||||
protected $id = null;
|
||||
protected $landing_site = null;
|
||||
protected $customer = null;
|
||||
protected $campaign_id = null;
|
||||
protected $financial_status = null;
|
||||
protected $fulfillment_status = null;
|
||||
protected $currency_code = null;
|
||||
protected $order_total = null;
|
||||
protected $tax_total = null;
|
||||
protected $discount_total = null;
|
||||
protected $shipping_total = null;
|
||||
protected $updated_at_foreign = null;
|
||||
protected $processed_at_foreign = null;
|
||||
protected $cancelled_at_foreign = null;
|
||||
protected $order_url = null;
|
||||
protected $shipping_address = null;
|
||||
protected $billing_address = null;
|
||||
protected $lines = array();
|
||||
protected $confirm_and_paid = false;
|
||||
protected $promos = array();
|
||||
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
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required|string',
|
||||
'landing_site' => 'required|string',
|
||||
'customer' => 'required',
|
||||
'campaign_id' => 'string',
|
||||
'financial_status' => 'string',
|
||||
'fulfillment_status' => 'string',
|
||||
'currency_code' => 'required|currency_code',
|
||||
'order_total' => 'required|numeric',
|
||||
'tax_total' => 'numeric',
|
||||
'discount_total' => 'numeric',
|
||||
'processed_at_foreign' => 'date',
|
||||
'updated_at_foreign' => 'date',
|
||||
'cancelled_at_foreign' => 'date',
|
||||
'order_url' => 'string',
|
||||
'lines' => 'required|array',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $landing_site
|
||||
* @return $this
|
||||
*/
|
||||
public function setLandingSite($landing_site)
|
||||
{
|
||||
$this->landing_site = $landing_site;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getLandingSite()
|
||||
{
|
||||
return $this->landing_site;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Customer $customer
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setCustomer(MailChimp_WooCommerce_Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
if (empty($this->customer)) {
|
||||
$this->customer = new MailChimp_WooCommerce_Customer();
|
||||
}
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_LineItem $item
|
||||
* @return $this
|
||||
*/
|
||||
public function addItem(MailChimp_WooCommerce_LineItem $item)
|
||||
{
|
||||
$this->lines[] = $item;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $amount
|
||||
* @param bool $is_percentage
|
||||
* @return $this
|
||||
*/
|
||||
public function addDiscount($code, $amount, $is_percentage = false)
|
||||
{
|
||||
$this->promos[] = array(
|
||||
'code' => $code,
|
||||
'amount_discounted' => $amount,
|
||||
'type' => $is_percentage ? 'percent' : 'fixed'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function discounts()
|
||||
{
|
||||
return $this->promos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCampaignId()
|
||||
{
|
||||
return $this->campaign_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $campaign_id
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setCampaignId($campaign_id)
|
||||
{
|
||||
$this->campaign_id = $campaign_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFinancialStatus()
|
||||
{
|
||||
return $this->financial_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $financial_status
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setFinancialStatus($financial_status)
|
||||
{
|
||||
$this->financial_status = $financial_status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFulfillmentStatus()
|
||||
{
|
||||
return $this->fulfillment_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $fulfillment_status
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setFulfillmentStatus($fulfillment_status)
|
||||
{
|
||||
$this->fulfillment_status = $fulfillment_status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCurrencyCode()
|
||||
{
|
||||
return $this->currency_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $currency_code
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setCurrencyCode($currency_code)
|
||||
{
|
||||
$this->currency_code = $currency_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderTotal()
|
||||
{
|
||||
return $this->order_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $order_total
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setOrderTotal($order_total)
|
||||
{
|
||||
$this->order_total = $order_total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderURL($url)
|
||||
{
|
||||
if (($url = wp_http_validate_url($url))) {
|
||||
$this->order_url = $url;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderURL()
|
||||
{
|
||||
return $this->order_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTaxTotal()
|
||||
{
|
||||
return $this->tax_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $tax_total
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setTaxTotal($tax_total)
|
||||
{
|
||||
$this->tax_total = $tax_total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getShippingTotal()
|
||||
{
|
||||
return $this->shipping_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $shipping_total
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setShippingTotal($shipping_total)
|
||||
{
|
||||
$this->shipping_total = $shipping_total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDiscountTotal()
|
||||
{
|
||||
return $this->discount_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $discount_total
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function setDiscountTotal($discount_total)
|
||||
{
|
||||
$this->discount_total = $discount_total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setProcessedAt(\DateTime $time)
|
||||
{
|
||||
$this->processed_at_foreign = $time->format('Y-m-d H:i:s');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getProcessedAt()
|
||||
{
|
||||
return $this->processed_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setCancelledAt(\DateTime $time)
|
||||
{
|
||||
$this->cancelled_at_foreign = $time->format('Y-m-d H:i:s');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCancelledAt()
|
||||
{
|
||||
return $this->cancelled_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdatedAt(\DateTime $time)
|
||||
{
|
||||
$this->updated_at_foreign = $time->format('Y-m-d H:i:s');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getUpdatedAt()
|
||||
{
|
||||
return $this->updated_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bool
|
||||
* @param $bool
|
||||
* @return $this
|
||||
*/
|
||||
public function confirmAndPay($bool)
|
||||
{
|
||||
$this->confirm_and_paid = (bool) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldConfirmAndPay()
|
||||
{
|
||||
return $this->confirm_and_paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Address $address
|
||||
* @return $this
|
||||
*/
|
||||
public function setShippingAddress(MailChimp_WooCommerce_Address $address)
|
||||
{
|
||||
$this->shipping_address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function getShippingAddress()
|
||||
{
|
||||
if (empty($this->shipping_address)) {
|
||||
$this->shipping_address = new MailChimp_WooCommerce_Address();
|
||||
}
|
||||
return $this->shipping_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Address $address
|
||||
* @return $this
|
||||
*/
|
||||
public function setBillingAddress(MailChimp_WooCommerce_Address $address)
|
||||
{
|
||||
$this->billing_address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function getBillingAddress()
|
||||
{
|
||||
if (empty($this->billing_address)) {
|
||||
$this->billing_address = new MailChimp_WooCommerce_Address();
|
||||
}
|
||||
return $this->billing_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->getId(),
|
||||
'landing_site' => (string) $this->getLandingSite(),
|
||||
'customer' => $this->getCustomer()->toArray(),
|
||||
'campaign_id' => (string) $this->getCampaignId(),
|
||||
'financial_status' => (string) $this->getFinancialStatus(),
|
||||
'fulfillment_status' => (string) $this->getFulfillmentStatus(),
|
||||
'currency_code' => (string) $this->getCurrencyCode(),
|
||||
'order_total' => floatval($this->getOrderTotal()),
|
||||
'order_url' => (string) $this->getOrderURL(),
|
||||
'tax_total' => floatval($this->getTaxTotal()),
|
||||
'discount_total' => floatval($this->getDiscountTotal()),
|
||||
'shipping_total' => floatval($this->getShippingTotal()),
|
||||
'processed_at_foreign' => (string) $this->getProcessedAt(),
|
||||
'cancelled_at_foreign' => (string) $this->getCancelledAt(),
|
||||
'updated_at_foreign' => (string) $this->getUpdatedAt(),
|
||||
'shipping_address' => $this->getShippingAddress()->toArray(),
|
||||
'billing_address' => $this->getBillingAddress()->toArray(),
|
||||
'promos' => !empty($this->promos) ? $this->promos : null,
|
||||
'lines' => array_map(function ($item) {
|
||||
/** @var MailChimp_WooCommerce_LineItem $item */
|
||||
return $item->toArray();
|
||||
}, $this->items()),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'landing_site', 'campaign_id', 'financial_status', 'fulfillment_status',
|
||||
'currency_code', 'order_total', 'order_url', 'tax_total', 'discount_total', 'processed_at_foreign',
|
||||
'cancelled_at_foreign', 'updated_at_foreign'
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('shipping_address', $data) && is_array($data['shipping_address'])) {
|
||||
$shipping = new MailChimp_WooCommerce_Address();
|
||||
$this->shipping_address = $shipping->fromArray($data['shipping_address']);
|
||||
}
|
||||
|
||||
if (array_key_exists('billing_address', $data) && is_array($data['billing_address'])) {
|
||||
$billing = new MailChimp_WooCommerce_Address();
|
||||
$this->billing_address = $billing->fromArray($data['billing_address']);
|
||||
}
|
||||
|
||||
if (array_key_exists('promos', $data)) {
|
||||
$this->promos = $data['promos'];
|
||||
}
|
||||
|
||||
if (array_key_exists('lines', $data) && is_array($data['lines'])) {
|
||||
$this->lines = array();
|
||||
foreach ($data['lines'] as $line_item) {
|
||||
$item = new MailChimp_WooCommerce_LineItem();
|
||||
$this->lines[] = $item->fromArray($line_item);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:17 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_ProductVariation
|
||||
{
|
||||
protected $id = null;
|
||||
protected $title = null;
|
||||
protected $url = null;
|
||||
protected $sku = null;
|
||||
protected $price = null;
|
||||
protected $inventory_quantity = null;
|
||||
protected $image_url = null;
|
||||
protected $backorders = null;
|
||||
protected $visibility = null;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'url' => 'url',
|
||||
'sku' => 'string',
|
||||
'price' => 'numeric',
|
||||
'inventory_quantity' => 'integer',
|
||||
'image_url' => 'url',
|
||||
'backorders' => 'string',
|
||||
'visibility' => 'string',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $title
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $url
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getSku()
|
||||
{
|
||||
return $this->sku;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sku
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setSku($sku)
|
||||
{
|
||||
$this->sku = $sku;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $price
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setPrice($price)
|
||||
{
|
||||
$this->price = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getInventoryQuantity()
|
||||
{
|
||||
return $this->inventory_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $inventory_quantity
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setInventoryQuantity($inventory_quantity)
|
||||
{
|
||||
$this->inventory_quantity = $inventory_quantity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getImageUrl()
|
||||
{
|
||||
return !empty($this->image_url) ? $this->image_url : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $image_url
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setImageUrl($image_url)
|
||||
{
|
||||
$this->image_url = $image_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getBackorders()
|
||||
{
|
||||
return $this->backorders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $backorders
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setBackorders($backorders)
|
||||
{
|
||||
$this->backorders = $backorders;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getVisibility()
|
||||
{
|
||||
return $this->visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $visibility
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->visibility = $visibility;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->getId(),
|
||||
'title' => $this->getTitle(),
|
||||
'url' => (string) $this->getUrl(),
|
||||
'sku' => (string) $this->getSku(),
|
||||
'price' => $this->getPrice(),
|
||||
'inventory_quantity' => (int) $this->getInventoryQuantity(),
|
||||
'image_url' => (string) $this->getImageUrl(),
|
||||
'backorders' => $this->getBackorders() ? 'true' : 'false',
|
||||
'visibility' => (string) $this->getVisibility(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'title', 'url', 'sku',
|
||||
'price', 'inventory_quantity', 'image_url', 'backorders',
|
||||
'visibility',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 2:17 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Product
|
||||
{
|
||||
protected $id;
|
||||
protected $title;
|
||||
protected $handle = null;
|
||||
protected $url = null;
|
||||
protected $description = null;
|
||||
protected $type = null;
|
||||
protected $vendor = null;
|
||||
protected $image_url = null;
|
||||
protected $variants = array();
|
||||
protected $published_at_foreign = null;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'handle' => 'string',
|
||||
'url' => 'url',
|
||||
'description' => 'string',
|
||||
'type' => 'string',
|
||||
'vendor' => 'string',
|
||||
'image_url' => 'url',
|
||||
'variants' => 'required|array',
|
||||
'published_at_foreign' => 'date',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $title
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getHandle()
|
||||
{
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $handle
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setHandle($handle)
|
||||
{
|
||||
$this->handle = $handle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $url
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $description
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $type
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getVendor()
|
||||
{
|
||||
return $this->vendor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $vendor
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setVendor($vendor)
|
||||
{
|
||||
$this->vendor = $vendor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getImageUrl()
|
||||
{
|
||||
return $this->image_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $image_url
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setImageUrl($image_url)
|
||||
{
|
||||
$this->image_url = $image_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getVariations()
|
||||
{
|
||||
return $this->variants;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_ProductVariation $variation
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function addVariant(MailChimp_WooCommerce_ProductVariation $variation)
|
||||
{
|
||||
$this->variants[] = $variation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublishedAtForeign()
|
||||
{
|
||||
return $this->published_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function setPublishedAtForeign(\DateTime $time)
|
||||
{
|
||||
$this->published_at_foreign = $time->format('Y-m-d H:i:s');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => (string) $this->getId(),
|
||||
'title' => $this->getTitle(),
|
||||
'handle' => (string) $this->getHandle(),
|
||||
'url' => (string) $this->getUrl(),
|
||||
'description' => (string) $this->getDescription(),
|
||||
'type' => (string) $this->getType(),
|
||||
'vendor' => (string) $this->getVendor(),
|
||||
'image_url' => (string) $this->getImageUrl(),
|
||||
'variants' => array_map(function ($item) {
|
||||
return $item->toArray();
|
||||
}, $this->getVariations()),
|
||||
'published_at_foreign' => (string) $this->getPublishedAtForeign(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'title', 'handle', 'url',
|
||||
'description', 'type', 'vendor', 'image_url',
|
||||
'published_at_foreign',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('variants', $data) && is_array($data['variants'])) {
|
||||
$this->variants = array();
|
||||
foreach ($data['variants'] as $variant) {
|
||||
$variation = new MailChimp_WooCommerce_ProductVariation();
|
||||
$this->variants[] = $variation->fromArray($variant);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 6/13/17
|
||||
* Time: 1:19 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_PromoCode
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @title Promo Rule Foreign ID
|
||||
* @description A unique identifier for the promo code
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Code
|
||||
* @required
|
||||
* @description The discount code
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Promo Redemption Url
|
||||
* @required
|
||||
* @description The url that should be used in the promotion campaign. Eg. A url that applies promo code directly at checkout or a url that points to sale page. Use store url if promotion url is not available.
|
||||
*/
|
||||
protected $redemption_url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Description
|
||||
* @default null
|
||||
* @description Number of times promo code has been used.
|
||||
*/
|
||||
protected $usage_count;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @title Enabled
|
||||
* @default true
|
||||
* @description Whether the promo code is currently enabled. ***
|
||||
*/
|
||||
protected $enabled;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $created_at_foreign;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $updated_at_foreign;
|
||||
|
||||
/**
|
||||
* @var MailChimp_WooCommerce_PromoRule|null
|
||||
*/
|
||||
protected $promo_rule;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return [
|
||||
'id' => 'required',
|
||||
'code' => 'required',
|
||||
'redemption_url' => 'required',
|
||||
'usage_count' => 'integer',
|
||||
'created_at_foreign' => 'date',
|
||||
'updated_at_foreign' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_PromoRule $promo
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function attachPromoRule(MailChimp_WooCommerce_PromoRule $promo)
|
||||
{
|
||||
$this->promo_rule = $promo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_PromoRule|null
|
||||
*/
|
||||
public function getAttachedPromoRule()
|
||||
{
|
||||
return $this->promo_rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRedemptionURL()
|
||||
{
|
||||
return $this->redemption_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function setRedemptionURL($url)
|
||||
{
|
||||
$this->redemption_url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUsageCount()
|
||||
{
|
||||
return $this->usage_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $count
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function setUsageCount($count)
|
||||
{
|
||||
$this->usage_count = $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $enabled
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = (bool) $enabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return (bool) $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty([
|
||||
'id' => (string) $this->getId(),
|
||||
'code' => (string) $this->getCode(),
|
||||
'redemption_url' => (string) $this->getRedemptionURL(),
|
||||
'usage_count' => $this->getUsageCount(),
|
||||
'enabled' => $this->isEnabled(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = [
|
||||
'id', 'code', 'usage_count', 'enabled',
|
||||
'redemption_url', 'created_at_foreign', 'updated_at_foreign',
|
||||
];
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 6/13/17
|
||||
* Time: 1:19 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_PromoRule
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @title Promo Rule Foreign ID
|
||||
* @default = null
|
||||
* @description
|
||||
* A unique identifier for the promo rule. If Ecomm platform does not support promo rule,
|
||||
* use promo code id as promo rule id.
|
||||
* Restricted to UTF-8 characters with max length 50
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Title
|
||||
* @default null
|
||||
* @description The title that will show up in promotion campaign. Restricted to UTF-8 characters with max length 100
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Description
|
||||
* @default null
|
||||
* @description The description of a promotion
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $starts_at;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $ends_at;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @title Amount
|
||||
* @required
|
||||
* @description The amount of discount; Positive dollar or percentage amount.
|
||||
*/
|
||||
protected $amount;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Type
|
||||
* @required
|
||||
* @description One of ‘fixed’ , ‘percentage’
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @title Target
|
||||
* @required
|
||||
* @description One of ‘per_item’, ‘total’, ‘shipping’
|
||||
*/
|
||||
protected $target;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @title Enabled
|
||||
* @default true
|
||||
* @description Whether the promo rule is currently enabled
|
||||
*/
|
||||
protected $enabled = true;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $created_at_foreign;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @title Start Time
|
||||
* @default null
|
||||
* @description The date and time when the promotion starts in ISO 8601 format
|
||||
*/
|
||||
protected $updated_at_foreign;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return [
|
||||
'id' => 'required',
|
||||
'amount' => 'required|number',
|
||||
'type' => 'required',
|
||||
'target' => 'required',
|
||||
'enabled' => 'boolean',
|
||||
'starts_at' => 'date',
|
||||
'ends_at' => 'date',
|
||||
'created_at_foreign' => 'date',
|
||||
'updated_at_foreign' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id
|
||||
* @return MailChimp_WooCommerce_PromoRule
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return MailChimp_WooCommerce_PromoRule
|
||||
*/
|
||||
public function setTitle($name)
|
||||
{
|
||||
$this->title = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @return MailChimp_WooCommerce_PromoRule
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartsAt(\DateTime $date)
|
||||
{
|
||||
$this->starts_at = (string) $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStartsAt()
|
||||
{
|
||||
return $this->starts_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @return $this
|
||||
*/
|
||||
public function setEndsAt(\DateTime $date)
|
||||
{
|
||||
$this->ends_at = (string) $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEndsAt()
|
||||
{
|
||||
return $this->ends_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $enabled
|
||||
* @return $this
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = (bool) $enabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return (bool) $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $amount
|
||||
* @return MailChimp_WooCommerce_PromoRule
|
||||
*/
|
||||
public function setAmount($amount)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTarget()
|
||||
{
|
||||
return $this->target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTypeFixed()
|
||||
{
|
||||
$this->type = 'fixed';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTypePercentage()
|
||||
{
|
||||
$this->type = 'percentage';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTargetTypePerItem()
|
||||
{
|
||||
$this->target = 'per_item';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTargetTypeShipping()
|
||||
{
|
||||
$this->target = 'shipping';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTargetTypeTotal()
|
||||
{
|
||||
$this->target = 'total';
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdatedAt(\DateTime $time)
|
||||
{
|
||||
$this->updated_at_foreign = (string) $time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getUpdatedAt()
|
||||
{
|
||||
return $this->updated_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedAt(\DateTime $time)
|
||||
{
|
||||
$this->created_at_foreign = (string) $time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->created_at_foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty([
|
||||
'id' => (string) $this->getId(),
|
||||
'title' => (string) $this->getTitle(),
|
||||
'description' => (string) $this->getDescription(),
|
||||
'starts_at' => (string) $this->getStartsAt(),
|
||||
'ends_at' => (string) $this->getEndsAt(),
|
||||
'amount' => floatval($this->getAmount()),
|
||||
'type' => (string) $this->getType(),
|
||||
'target' => (string) $this->getTarget(),
|
||||
'enabled' => (bool) $this->isEnabled(),
|
||||
'created_at_foreign' => (string) $this->getCreatedAt(),
|
||||
'updated_at_foreign' => (string) $this->getUpdatedAt(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_PromoRule
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = [
|
||||
'id',
|
||||
'title',
|
||||
'description',
|
||||
'starts_at',
|
||||
'ends_at',
|
||||
'amount',
|
||||
'type',
|
||||
'target',
|
||||
'enabled',
|
||||
'created_at_foreign',
|
||||
'updated_at_foreign'
|
||||
];
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 3/8/16
|
||||
* Time: 3:13 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Store
|
||||
{
|
||||
protected $id = null;
|
||||
protected $is_syncing = false;
|
||||
protected $list_id = null;
|
||||
protected $name = null;
|
||||
protected $domain = null;
|
||||
protected $email_address = null;
|
||||
protected $currency_code = null;
|
||||
protected $money_format = null;
|
||||
protected $primary_locale = null;
|
||||
protected $timezone = null;
|
||||
protected $phone = null;
|
||||
protected $address = null;
|
||||
protected $platform = null;
|
||||
protected $connected_site = null;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidation()
|
||||
{
|
||||
return array(
|
||||
'id' => 'required|string',
|
||||
'list_id' => 'required|string',
|
||||
'name' => 'required|string',
|
||||
'domain' => 'string',
|
||||
'email_address' => 'email',
|
||||
'currency_code' => 'required|currency_code',
|
||||
'primary_locale' => 'locale_basic',
|
||||
'timezone' => 'timezone',
|
||||
'phone' => 'string',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id
|
||||
* @return MailChimp_WooCommerce_Store
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bool
|
||||
* @return $this
|
||||
*/
|
||||
public function flagSyncing($bool)
|
||||
{
|
||||
$this->is_syncing = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSyncing()
|
||||
{
|
||||
return $this->is_syncing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getListId()
|
||||
{
|
||||
return $this->list_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $list_id
|
||||
* @return MailChimp_WooCommerce_Store
|
||||
*/
|
||||
public function setListId($list_id)
|
||||
{
|
||||
$this->list_id = $list_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $name
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $domain
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getEmailAddress()
|
||||
{
|
||||
return $this->email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $email_address
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setEmailAddress($email_address)
|
||||
{
|
||||
$this->email_address = $email_address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCurrencyCode()
|
||||
{
|
||||
return $this->currency_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $currency_code
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setCurrencyCode($currency_code)
|
||||
{
|
||||
$this->currency_code = $currency_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getMoneyFormat()
|
||||
{
|
||||
return $this->money_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $money_format
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setMoneyFormat($money_format)
|
||||
{
|
||||
$this->money_format = $money_format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getPrimaryLocale()
|
||||
{
|
||||
return $this->primary_locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $primary_locale
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setPrimaryLocale($primary_locale)
|
||||
{
|
||||
$this->primary_locale = $primary_locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTimezone()
|
||||
{
|
||||
return $this->timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $timezone
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setTimezone($timezone)
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $phone
|
||||
* @return MailChimp_WooCommerce_Store;
|
||||
*/
|
||||
public function setPhone($phone)
|
||||
{
|
||||
$this->phone = $phone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $platform
|
||||
* @return $this
|
||||
*/
|
||||
public function setPlatform($platform)
|
||||
{
|
||||
$this->platform = $platform;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPlatform()
|
||||
{
|
||||
return $this->platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
if (empty($this->address)) {
|
||||
$this->address = new MailChimp_WooCommerce_Address();
|
||||
}
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Address $address
|
||||
* @return Store;
|
||||
*/
|
||||
public function setAddress(MailChimp_WooCommerce_Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getConnectedSiteForeignID()
|
||||
{
|
||||
return $this->getConnectedSiteParam('site_foreign_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getConnectedSiteScriptUrl()
|
||||
{
|
||||
if (($script = $this->getConnectedSiteParam('site_script'))) {
|
||||
return $script['url'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getConnectedSiteScriptFragment()
|
||||
{
|
||||
if (($script = $this->getConnectedSiteParam('site_script'))) {
|
||||
return $script['fragment'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @return null
|
||||
*/
|
||||
public function getConnectedSiteParam($key, $default = null)
|
||||
{
|
||||
if (empty($this->connected_site)) {
|
||||
return $default;
|
||||
}
|
||||
return array_key_exists($key, $this->connected_site) ? $this->connected_site[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return mailchimp_array_remove_empty(array(
|
||||
'id' => $this->getId(),
|
||||
'is_syncing' => $this->isSyncing(),
|
||||
'platform' => $this->getPlatform(),
|
||||
'list_id' => $this->getListId(),
|
||||
'name' => $this->getName(),
|
||||
'domain' => $this->getDomain(),
|
||||
'email_address' => $this->getEmailAddress(),
|
||||
'currency_code' => $this->getCurrencyCode(),
|
||||
'money_format' => $this->getMoneyFormat(),
|
||||
'primary_locale' => $this->getPrimaryLocale(),
|
||||
'timezone' => $this->getTimezone(),
|
||||
'phone' => $this->getPhone(),
|
||||
'address' => $this->getAddress()->toArray(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return MailChimp_WooCommerce_Store
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
$singles = array(
|
||||
'id', 'list_id', 'name', 'domain', 'is_syncing',
|
||||
'email_address', 'currency_code', 'money_format',
|
||||
'primary_locale', 'timezone', 'phone', 'platform',
|
||||
);
|
||||
|
||||
foreach ($singles as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$this->$key = $data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('address', $data)) {
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
$this->address = $address->fromArray($data['address']);
|
||||
}
|
||||
|
||||
if (array_key_exists('connected_site', $data)) {
|
||||
$this->connected_site = $data['connected_site'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/13/16
|
||||
* Time: 2:32 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Api
|
||||
{
|
||||
protected static $filterable_actions = array(
|
||||
'paginate-resource',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param int $default_page
|
||||
* @param int $default_per
|
||||
* @return array
|
||||
*/
|
||||
public static function filter($default_page = null, $default_per = null)
|
||||
{
|
||||
if (isset($_GET['mailchimp-woocommerce']) && isset($_GET['mailchimp-woocommerce']['action'])) {
|
||||
if (in_array($_GET['mailchimp-woocommerce']['action'], static::$filterable_actions)) {
|
||||
if (empty($default_page)) {
|
||||
$page = isset($_GET['page']) ? (int) $_GET['page'] : null;
|
||||
}
|
||||
if (empty($default_per)) {
|
||||
$per = isset($_GET['per']) ? (int) $_GET['per'] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($page)) $page = 1;
|
||||
if (empty($per)) $per = 5;
|
||||
|
||||
return array($page, $per);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $page
|
||||
* @param null $per
|
||||
* @return object|stdClass
|
||||
*/
|
||||
public function paginateProducts($page = null, $per = null)
|
||||
{
|
||||
return $this->paginate('products', $page, $per);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $page
|
||||
* @param null $per
|
||||
* @return object|stdClass
|
||||
*/
|
||||
public function paginateOrders($page = null, $per = null)
|
||||
{
|
||||
return $this->paginate('orders', $page, $per);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resource
|
||||
* @param int $page
|
||||
* @param int $per
|
||||
* @return object|stdClass
|
||||
*/
|
||||
public function paginate($resource, $page = 1, $per = 5)
|
||||
{
|
||||
if (($sync = $this->engine($resource))) {
|
||||
return $sync->compile($page, $per);
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'endpoint' => $resource,
|
||||
'page' => $page,
|
||||
'count' => 0,
|
||||
'stuffed' => false,
|
||||
'items' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resource
|
||||
* @return bool|MailChimp_WooCommerce_Transform_Orders|MailChimp_WooCommerce_Transform_Products|MailChimp_WooCommerce_Transform_Coupons
|
||||
*/
|
||||
public function engine($resource)
|
||||
{
|
||||
switch ($resource) {
|
||||
case 'products' :
|
||||
return new MailChimp_WooCommerce_Transform_Products();
|
||||
break;
|
||||
case 'orders' :
|
||||
return new MailChimp_WooCommerce_Transform_Orders();
|
||||
break;
|
||||
case 'coupons':
|
||||
return new MailChimp_WooCommerce_Transform_Coupons();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/8/16
|
||||
* Time: 4:16 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_CreateListSubmission
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $props = array();
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->props['name'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bool
|
||||
* @return $this
|
||||
*/
|
||||
public function setUseArchiveBar($bool)
|
||||
{
|
||||
$this->props['use_archive_bar'] = (bool) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $reminder
|
||||
* @return $this
|
||||
*/
|
||||
public function setPermissionReminder($reminder)
|
||||
{
|
||||
$this->props['permission_reminder'] = $reminder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @return $this
|
||||
*/
|
||||
public function setNotifyOnSubscribe($email)
|
||||
{
|
||||
$this->props['notify_on_subscribe'] = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return $this
|
||||
*/
|
||||
public function setNotifyOnUnSubscribe($email)
|
||||
{
|
||||
$this->props['notify_on_unsubscribe'] = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bool
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmailTypeOption($bool)
|
||||
{
|
||||
$this->props['email_type_option'] = (bool) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $public
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisibility($public = true)
|
||||
{
|
||||
$this->props['visibility'] = $public ? 'pub' : 'prv';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $email
|
||||
* @param $subject
|
||||
* @param string $language
|
||||
* @return $this
|
||||
*/
|
||||
public function setCampaignDefaults($name, $email, $subject, $language = 'en')
|
||||
{
|
||||
$this->props['campaign_defaults'] = array(
|
||||
'from_name' => $name,
|
||||
'from_email' => $email,
|
||||
'subject' => $subject,
|
||||
'language' => $language,
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MailChimp_WooCommerce_Address $address
|
||||
* @return $this
|
||||
*/
|
||||
public function setContact(MailChimp_WooCommerce_Address $address)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
if (($company = $address->getCompany()) && !empty($company)) {
|
||||
$data['company'] = $company;
|
||||
}
|
||||
|
||||
if (($street = $address->getAddress1()) && !empty($address)) {
|
||||
$data['address1'] = $street;
|
||||
}
|
||||
|
||||
if (($city = $address->getCity()) && !empty($city)) {
|
||||
$data['city'] = $city;
|
||||
}
|
||||
|
||||
if (($state = $address->getProvince()) && !empty($state)) {
|
||||
$data['state'] = $state;
|
||||
}
|
||||
|
||||
if (($zip = $address->getPostalCode()) && !empty($zip)) {
|
||||
$data['zip'] = $zip;
|
||||
}
|
||||
|
||||
if (($country = $address->getCountry()) && !empty($country)) {
|
||||
$data['country'] = $country;
|
||||
}
|
||||
|
||||
if (($phone = $address->getPhone()) && !empty($phone)) {
|
||||
$data['phone'] = $phone;
|
||||
}
|
||||
|
||||
$this->props['contact'] = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSubmission()
|
||||
{
|
||||
return $this->props;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 10/06/17
|
||||
* Time: 8:29 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Transform_Coupons
|
||||
{
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function compile($page = 1, $limit = 5)
|
||||
{
|
||||
$response = (object) array(
|
||||
'endpoint' => 'coupons',
|
||||
'page' => $page ? $page : 1,
|
||||
'limit' => (int) $limit,
|
||||
'count' => 0,
|
||||
'stuffed' => false,
|
||||
'items' => array(),
|
||||
);
|
||||
|
||||
if ((($coupons = $this->getCouponPosts($page, $limit)) && !empty($coupons))) {
|
||||
foreach ($coupons as $post) {
|
||||
$response->items[] = $this->transform($post->ID);
|
||||
$response->count++;
|
||||
}
|
||||
}
|
||||
|
||||
$response->stuffed = ($response->count > 0 && (int) $response->count === (int) $limit) ? true : false;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $post_id
|
||||
* @return MailChimp_WooCommerce_PromoCode
|
||||
*/
|
||||
public function transform($post_id)
|
||||
{
|
||||
$resource = new WC_Coupon($post_id);
|
||||
$valid = true;
|
||||
|
||||
if (($exp = $resource->get_date_expires()) && current_time('timestamp', true) > $exp->getTimestamp()) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
$rule = new MailChimp_WooCommerce_PromoRule();
|
||||
|
||||
$rule->setId($resource->get_id());
|
||||
$rule->setTitle($resource->get_code());
|
||||
$rule->setDescription($resource->get_description());
|
||||
$rule->setEnabled($valid);
|
||||
$rule->setAmount($resource->get_amount('edit'));
|
||||
|
||||
if (!$rule->getDescription()) {
|
||||
$rule->setDescription($resource->get_code());
|
||||
}
|
||||
|
||||
switch ($resource->get_discount_type()) {
|
||||
case 'fixed_product':
|
||||
$rule->setTypeFixed();
|
||||
$rule->setTargetTypePerItem();
|
||||
break;
|
||||
|
||||
case 'fixed_cart':
|
||||
$rule->setTypeFixed();
|
||||
$rule->setTargetTypeTotal();
|
||||
break;
|
||||
|
||||
case 'percent':
|
||||
$rule->setTypePercentage();
|
||||
$rule->setTargetTypeTotal();
|
||||
$rule->setAmount(($resource->get_amount('edit')/100));
|
||||
break;
|
||||
}
|
||||
|
||||
if (($exp = $resource->get_date_expires())) {
|
||||
$rule->setEndsAt($exp);
|
||||
}
|
||||
|
||||
$code = new MailChimp_WooCommerce_PromoCode();
|
||||
|
||||
$code->setId($resource->get_id());
|
||||
$code->setCode($resource->get_code());
|
||||
$code->setEnabled($valid);
|
||||
$code->setRedemptionURL(get_home_url());
|
||||
$code->setUsageCount($resource->get_usage_count());
|
||||
|
||||
// attach the rule for use.
|
||||
$code->attachPromoRule($rule);
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $posts
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getCouponPosts($page = 1, $posts = 5)
|
||||
{
|
||||
$coupons = get_posts(array(
|
||||
'post_type' => array_merge(array_keys(wc_get_product_types()), array('shop_coupon')),
|
||||
'posts_per_page' => $posts,
|
||||
'paged' => $page,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
));
|
||||
|
||||
if (empty($coupons)) {
|
||||
|
||||
sleep(2);
|
||||
|
||||
$coupons = get_posts(array(
|
||||
'post_type' => array_merge(array_keys(wc_get_product_types()), array('shop_coupon')),
|
||||
'posts_per_page' => $posts,
|
||||
'paged' => $page,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
));
|
||||
|
||||
if (empty($coupons)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $coupons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/13/16
|
||||
* Time: 8:29 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Transform_Orders
|
||||
{
|
||||
public $campaign_id = null;
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function compile($page = 1, $limit = 5)
|
||||
{
|
||||
$response = (object) array(
|
||||
'endpoint' => 'orders',
|
||||
'page' => $page ? $page : 1,
|
||||
'limit' => (int) $limit,
|
||||
'count' => 0,
|
||||
'valid' => 0,
|
||||
'drafts' => 0,
|
||||
'stuffed' => false,
|
||||
'items' => array(),
|
||||
);
|
||||
|
||||
if ((($orders = $this->getOrderPosts($page, $limit)) && !empty($orders))) {
|
||||
foreach ($orders as $post) {
|
||||
$response->count++;
|
||||
|
||||
if ($post->post_status === 'auto-draft') {
|
||||
$response->drafts++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$order = $this->transform($post);
|
||||
if (!$order->isFlaggedAsAmazonOrder()) {
|
||||
$response->valid++;
|
||||
$response->items[] = $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response->stuffed = ($response->count > 0 && (int) $response->count === (int) $limit) ? true : false;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_Post $post
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function transform(WP_Post $post)
|
||||
{
|
||||
$woo = new WC_Order($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.
|
||||
if (!empty($this->campaign_id)) {
|
||||
$order->setCampaignId($this->campaign_id);
|
||||
}
|
||||
|
||||
$order->setProcessedAt($woo->get_date_created()->setTimezone(new \DateTimeZone('UTC')));
|
||||
|
||||
$order->setCurrencyCode($woo->get_currency());
|
||||
|
||||
// grab the current statuses - this will end up being custom at some point.
|
||||
$statuses = $this->getOrderStatuses();
|
||||
|
||||
// grab the order status
|
||||
$status = $woo->get_status();
|
||||
|
||||
// map the fulfillment and financial statuses based on the map above.
|
||||
$fulfillment_status = array_key_exists($status, $statuses) ? $statuses[$status]->fulfillment : null;
|
||||
$financial_status = array_key_exists($status, $statuses) ? $statuses[$status]->financial : $status;
|
||||
|
||||
// set the fulfillment_status
|
||||
$order->setFulfillmentStatus($fulfillment_status);
|
||||
|
||||
// set the financial status
|
||||
$order->setFinancialStatus($financial_status);
|
||||
|
||||
// if the status is processing, we need to send this one first, then send a 'paid' status right after.
|
||||
if ($status === 'processing') {
|
||||
$order->confirmAndPay(true);
|
||||
}
|
||||
|
||||
// only set this if the order is cancelled.
|
||||
if ($status === 'cancelled') {
|
||||
$order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
// set the total
|
||||
$order->setOrderTotal($woo->get_total());
|
||||
|
||||
// set the order URL
|
||||
$order->setOrderURL($woo->get_view_order_url());
|
||||
|
||||
// if we have any tax
|
||||
$order->setTaxTotal($woo->get_total_tax());
|
||||
|
||||
// if we have shipping.
|
||||
$order->setShippingTotal($woo->get_shipping_total());
|
||||
|
||||
// set the order discount
|
||||
$order->setDiscountTotal($woo->get_total_discount());
|
||||
|
||||
// set the customer
|
||||
$order->setCustomer($this->buildCustomerFromOrder($woo));
|
||||
|
||||
// apply the addresses to the order
|
||||
$order->setShippingAddress($this->transformShippingAddress($woo));
|
||||
$order->setBillingAddress($this->transformBillingAddress($woo));
|
||||
|
||||
// loop through all the order items
|
||||
foreach ($woo->get_items() as $key => $order_detail) {
|
||||
/** @var WC_Order_Item_Product $order_detail */
|
||||
|
||||
// add it into the order item container.
|
||||
$item = $this->transformLineItem($key, $order_detail);
|
||||
|
||||
// if we don't have a product post with this id, we need to add a deleted product to the MC side
|
||||
if (!($product = $order_detail->get_product()) || 'trash' === $product->get_status()) {
|
||||
|
||||
$pid = $order_detail->get_product_id();
|
||||
|
||||
// check if it exists, otherwise create a new one.
|
||||
if (($deleted_product = MailChimp_WooCommerce_Transform_Products::deleted($pid))) {
|
||||
// swap out the old item id and product variant id with the deleted version.
|
||||
$item->setProductId("deleted_{$pid}");
|
||||
$item->setProductVariantId("deleted_{$pid}");
|
||||
|
||||
// add the item and continue on the loop.
|
||||
$order->addItem($item);
|
||||
continue;
|
||||
}
|
||||
|
||||
mailchimp_log('order.items.error', "Order #{$woo->get_id()} :: Product {$pid} does not exist!");
|
||||
continue;
|
||||
}
|
||||
|
||||
$order->addItem($item);
|
||||
}
|
||||
|
||||
//if (($refund = $woo->get_total_refunded()) && $refund > 0){
|
||||
// this is where we would be altering the submission to tell us about the refund.
|
||||
//}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $order
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function buildCustomerFromOrder(WC_Order $order)
|
||||
{
|
||||
$customer = new MailChimp_WooCommerce_Customer();
|
||||
|
||||
$customer->setId(md5(trim(strtolower($order->get_billing_email()))));
|
||||
$customer->setCompany($order->get_billing_company());
|
||||
$customer->setEmailAddress(trim($order->get_billing_email()));
|
||||
$customer->setFirstName($order->get_billing_first_name());
|
||||
$customer->setLastName($order->get_billing_last_name());
|
||||
$customer->setAddress($this->transformBillingAddress($order));
|
||||
|
||||
if (!($stats = $this->getCustomerOrderTotals($order->get_user_id()))) {
|
||||
$stats = (object) array('count' => 0, 'total' => 0);
|
||||
}
|
||||
|
||||
$customer->setOrdersCount($stats->count);
|
||||
$customer->setTotalSpent($stats->total);
|
||||
|
||||
// we are saving the post meta for subscribers on each order... so if they have subscribed on checkout
|
||||
$subscriber_meta = get_post_meta($order->get_id(), 'mailchimp_woocommerce_is_subscribed', true);
|
||||
$subscribed_on_order = $subscriber_meta === '' ? false : (bool) $subscriber_meta;
|
||||
$customer->setOptInStatus($subscribed_on_order);
|
||||
|
||||
// if they didn't subscribe on the order, we need to check to make sure they're not already a subscriber
|
||||
// if they are, we just need to make sure that we don't unsubscribe them just because they unchecked this box.
|
||||
if (!$subscribed_on_order) {
|
||||
try {
|
||||
$subscriber = mailchimp_get_api()->member(mailchimp_get_list_id(), $customer->getEmailAddress());
|
||||
$status = !in_array($subscriber['status'], array('unsubscribed', 'transactional'));
|
||||
$customer->setOptInStatus($status);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param WC_Order_Item_Product $order_detail
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
protected function transformLineItem($key, $order_detail)
|
||||
{
|
||||
// fire up a new MC line item
|
||||
$item = new MailChimp_WooCommerce_LineItem();
|
||||
$item->setId($key);
|
||||
|
||||
$item->setPrice($order_detail->get_total());
|
||||
$item->setProductId($order_detail->get_product_id());
|
||||
$variation_id = $order_detail->get_variation_id();
|
||||
if (empty($variation_id)) $variation_id = $order_detail->get_product_id();
|
||||
$item->setProductVariantId($variation_id);
|
||||
$item->setQuantity($order_detail->get_quantity());
|
||||
|
||||
if ($item->getQuantity() > 1) {
|
||||
$current_price = $item->getPrice();
|
||||
$price = ($current_price/$item->getQuantity());
|
||||
$item->setPrice($price);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $order
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function transformBillingAddress(WC_Order $order)
|
||||
{
|
||||
// use the info from the order to compile an address.
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
$address->setAddress1($order->get_billing_address_1());
|
||||
$address->setAddress2($order->get_billing_address_2());
|
||||
$address->setCity($order->get_billing_city());
|
||||
$address->setProvince($order->get_billing_state());
|
||||
$address->setPostalCode($order->get_billing_postcode());
|
||||
$address->setCountry($order->get_billing_country());
|
||||
$address->setPhone($order->get_billing_phone());
|
||||
|
||||
$bfn = $order->get_billing_first_name();
|
||||
$bln = $order->get_billing_last_name();
|
||||
|
||||
// if we have billing names set it here
|
||||
if (!empty($bfn) && !empty($bln)) {
|
||||
$address->setName("{$bfn} {$bln}");
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $order
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function transformShippingAddress(WC_Order $order)
|
||||
{
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
|
||||
$address->setAddress1($order->get_shipping_address_1());
|
||||
$address->setAddress2($order->get_shipping_address_2());
|
||||
$address->setCity($order->get_shipping_city());
|
||||
$address->setProvince($order->get_shipping_state());
|
||||
$address->setPostalCode($order->get_shipping_postcode());
|
||||
$address->setCountry($order->get_shipping_country());
|
||||
|
||||
// shipping does not have a phone number, so maybe use this?
|
||||
$address->setPhone($order->get_billing_phone());
|
||||
|
||||
$sfn = $order->get_shipping_first_name();
|
||||
$sln = $order->get_shipping_last_name();
|
||||
|
||||
// if we have billing names set it here
|
||||
if (!empty($sfn) && !empty($sln)) {
|
||||
$address->setName("{$sfn} {$sln}");
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $posts
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getOrderPosts($page = 1, $posts = 5)
|
||||
{
|
||||
$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',
|
||||
);
|
||||
|
||||
$orders = get_posts($params);
|
||||
if (empty($orders)) {
|
||||
sleep(2);
|
||||
$orders = get_posts($params);
|
||||
}
|
||||
|
||||
return empty($orders) ? false : $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an object with a 'total' and a 'count'.
|
||||
*
|
||||
* @param $user_id
|
||||
* @return object
|
||||
*/
|
||||
public function getCustomerOrderTotals($user_id)
|
||||
{
|
||||
$customer = new WC_Customer($user_id);
|
||||
$customer->get_order_count();
|
||||
$customer->get_total_spent();
|
||||
|
||||
return (object) array(
|
||||
'count' => $customer->get_order_count(),
|
||||
'total' => $customer->get_total_spent()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Pending payment" in the UI fires the order confirmation email MailChimp
|
||||
* "Completed” in the UI fires the MailChimp Order Invoice
|
||||
* "Cancelled" does what we think it does
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses()
|
||||
{
|
||||
return array(
|
||||
// Order received (unpaid)
|
||||
'pending' => (object) array(
|
||||
'financial' => 'pending',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Payment received and stock has been reduced – the order is awaiting fulfillment.
|
||||
// All product orders require processing, except those for digital downloads
|
||||
'processing' => (object) array(
|
||||
'financial' => 'pending',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Awaiting payment – stock is reduced, but you need to confirm payment
|
||||
'on-hold' => (object) array(
|
||||
'financial' => 'on-hold',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Order fulfilled and complete – requires no further action
|
||||
'completed' => (object) array(
|
||||
'financial' => 'fulfilled',
|
||||
'fulfillment' => 'fulfilled'
|
||||
),
|
||||
// Cancelled by an admin or the customer – no further action required
|
||||
'cancelled' => (object) array(
|
||||
'financial' => 'cancelled',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Refunded by an admin – no further action required
|
||||
'refunded' => (object) array(
|
||||
'financial' => 'refunded',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Payment failed or was declined (unpaid). Note that this status may not show immediately and
|
||||
// instead show as Pending until verified (i.e., PayPal)
|
||||
'failed' => (object) array(
|
||||
'financial' => 'failed',
|
||||
'fulfillment' => null
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@mailchimp.com
|
||||
* Date: 7/13/16
|
||||
* Time: 8:29 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Transform_Orders
|
||||
{
|
||||
public $campaign_id = null;
|
||||
protected $use_user_address = false;
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function compile($page = 1, $limit = 5)
|
||||
{
|
||||
$response = (object) array(
|
||||
'endpoint' => 'orders',
|
||||
'page' => $page ? $page : 1,
|
||||
'limit' => (int) $limit,
|
||||
'count' => 0,
|
||||
'valid' => 0,
|
||||
'drafts' => 0,
|
||||
'stuffed' => false,
|
||||
'items' => array(),
|
||||
);
|
||||
|
||||
if ((($orders = $this->getOrderPosts($page, $limit)) && !empty($orders))) {
|
||||
foreach ($orders as $post) {
|
||||
$response->count++;
|
||||
if ($post->post_status === 'auto-draft') {
|
||||
$response->drafts++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$order = $this->transform($post);
|
||||
if (!$order->isFlaggedAsAmazonOrder()) {
|
||||
$response->valid++;
|
||||
$response->items[] = $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response->stuffed = ($response->count > 0 && (int) $response->count === (int) $limit) ? true : false;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $woo
|
||||
* @return array
|
||||
*/
|
||||
protected function dates(WC_Order $woo)
|
||||
{
|
||||
if (method_exists($woo, 'get_date_modified')) {
|
||||
$created_at = $woo->get_date_modified();
|
||||
$updated_at = $woo->get_date_modified();
|
||||
} elseif (property_exists($woo, 'order_date') && property_exists($woo, 'modified_date')) {
|
||||
$created_at = $woo->order_date ? new \DateTime($woo->order_date) : null;
|
||||
$updated_at = $woo->modified_date ? new \DateTime($woo->modified_date) : null;
|
||||
} else {
|
||||
$created_at = $updated_at = new \DateTime();
|
||||
}
|
||||
|
||||
return array($created_at, $updated_at);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_Post $post
|
||||
* @return MailChimp_WooCommerce_Order
|
||||
*/
|
||||
public function transform(WP_Post $post)
|
||||
{
|
||||
$woo = new WC_Order($post);
|
||||
|
||||
$order = new MailChimp_WooCommerce_Order();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
$order->setProcessedAt($woo->get_date_created()->setTimezone(new \DateTimeZone('UTC')));
|
||||
|
||||
$order->setCurrencyCode($woo->get_currency());
|
||||
|
||||
// grab the current statuses - this will end up being custom at some point.
|
||||
$statuses = $this->getOrderStatuses();
|
||||
|
||||
// grab the order status
|
||||
$status = $woo->get_status();
|
||||
|
||||
// map the fulfillment and financial statuses based on the map above.
|
||||
$fulfillment_status = array_key_exists($status, $statuses) ? $statuses[$status]->fulfillment : null;
|
||||
$financial_status = array_key_exists($status, $statuses) ? $statuses[$status]->financial : $status;
|
||||
|
||||
// set the fulfillment_status
|
||||
$order->setFulfillmentStatus($fulfillment_status);
|
||||
|
||||
// set the financial status
|
||||
$order->setFinancialStatus($financial_status);
|
||||
|
||||
// if the status is processing, we need to send this one first, then send a 'paid' status right after.
|
||||
if ($status === 'processing') {
|
||||
$order->confirmAndPay(true);
|
||||
}
|
||||
|
||||
// only set this if the order is cancelled.
|
||||
if ($status === 'cancelled') {
|
||||
$order->setCancelledAt($woo->get_date_modified()->setTimezone(new \DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
// set the total
|
||||
$order->setOrderTotal($woo->get_total());
|
||||
|
||||
// set the order URL
|
||||
$order->setOrderURL($woo->get_view_order_url());
|
||||
|
||||
// if we have any tax
|
||||
$order->setTaxTotal($woo->get_total_tax());
|
||||
|
||||
// if we have shipping.
|
||||
$order->setShippingTotal($woo->get_total_shipping());
|
||||
|
||||
// set the order discount
|
||||
$order->setDiscountTotal($woo->get_total_discount());
|
||||
|
||||
// set the customer
|
||||
$order->setCustomer($this->buildCustomerFromOrder($woo));
|
||||
|
||||
// apply the addresses to the order
|
||||
$addresses = $this->getOrderAddresses($woo);
|
||||
$order->setShippingAddress($addresses->shipping);
|
||||
$order->setBillingAddress($addresses->billing);
|
||||
|
||||
// loop through all the order items
|
||||
foreach ($woo->get_items() as $key => $order_detail) {
|
||||
|
||||
// add it into the order item container.
|
||||
$item = $this->buildLineItem($key, $order_detail);
|
||||
|
||||
// if we don't have a product post with this id, we need to add a deleted product to the MC side
|
||||
if (!($product_post = get_post($item->getProductId()))) {
|
||||
|
||||
// check if it exists, otherwise create a new one.
|
||||
if (($deleted_product = MailChimp_WooCommerce_Transform_Products::deleted($item->getProductId()))) {
|
||||
|
||||
$deleted_product_id = "deleted_{$item->getProductId()}";
|
||||
|
||||
// swap out the old item id and product variant id with the deleted version.
|
||||
$item->setProductId($deleted_product_id);
|
||||
$item->setProductVariantId($deleted_product_id);
|
||||
|
||||
// add the item and continue on the loop.
|
||||
$order->addItem($item);
|
||||
continue;
|
||||
}
|
||||
|
||||
mailchimp_log('order.items.error', "Order #{$woo->get_order_number()} :: Product {$item->getProductId()} does not exist!");
|
||||
continue;
|
||||
}
|
||||
|
||||
$order->addItem($item);
|
||||
}
|
||||
|
||||
// apply the coupon discounts
|
||||
if (function_exists('wc_get_coupon_id_by_code') && ($used_coupons = $woo->get_used_coupons()) && is_array($used_coupons)) {
|
||||
foreach ($used_coupons as $coupon_code) {
|
||||
if (($coupon_id = wc_get_coupon_id_by_code($coupon_code))) {
|
||||
$coupon = new WC_Coupon($coupon_id);
|
||||
$is_percentage = $coupon->get_discount_type() === 'percent';
|
||||
$order->addDiscount($coupon_code, $coupon->get_amount('edit'), $is_percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (($refund = $woo->get_total_refunded()) && $refund > 0){
|
||||
// this is where we would be altering the submission to tell us about the refund.
|
||||
//}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $order
|
||||
* @return MailChimp_WooCommerce_Customer
|
||||
*/
|
||||
public function buildCustomerFromOrder(WC_Order $order)
|
||||
{
|
||||
$customer = new MailChimp_WooCommerce_Customer();
|
||||
|
||||
$customer->setId(md5(trim(strtolower($order->billing_email))));
|
||||
$customer->setCompany($order->billing_company);
|
||||
$customer->setEmailAddress(trim($order->billing_email));
|
||||
$customer->setFirstName($order->billing_first_name);
|
||||
$customer->setLastName($order->billing_last_name);
|
||||
$customer->setOrdersCount(1);
|
||||
$customer->setTotalSpent($order->get_total());
|
||||
|
||||
// we are saving the post meta for subscribers on each order... so if they have subscribed on checkout
|
||||
$subscriber_meta = get_post_meta($order->get_id(), 'mailchimp_woocommerce_is_subscribed', true);
|
||||
$subscribed_on_order = $subscriber_meta === '' ? false : (bool) $subscriber_meta;
|
||||
|
||||
$customer->setOptInStatus($subscribed_on_order);
|
||||
// if they didn't subscribe on the order, we need to check to make sure they're not already a subscriber
|
||||
// if they are, we just need to make sure that we don't unsubscribe them just because they unchecked this box.
|
||||
if (!$subscribed_on_order) {
|
||||
try {
|
||||
$subscriber = mailchimp_get_api()->member(mailchimp_get_list_id(), $customer->getEmailAddress());
|
||||
$status = !in_array($subscriber['status'], array('unsubscribed', 'transactional'));
|
||||
$customer->setOptInStatus($status);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
// use the info from the order to compile an address.
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
$address->setAddress1($order->billing_address_1);
|
||||
$address->setAddress2($order->billing_address_2);
|
||||
$address->setCity($order->billing_city);
|
||||
$address->setProvince($order->billing_state);
|
||||
$address->setPostalCode($order->billing_postcode);
|
||||
$address->setCountry($order->billing_country);
|
||||
$address->setPhone($order->billing_phone);
|
||||
|
||||
// if we have billing names set it here
|
||||
if (!empty($order->billing_first_name) && !empty($order->billing_last_name)) {
|
||||
$address->setName($order->billing_first_name.' '.$order->billing_last_name);
|
||||
}
|
||||
|
||||
$customer->setAddress($address);
|
||||
|
||||
if (($user = get_userdata($order->customer_user))) {
|
||||
/**
|
||||
* IF we wanted to use the user data instead we would do it here.
|
||||
* but we discussed using the billing address instead.
|
||||
*/
|
||||
if ($this->use_user_address) {
|
||||
$customer->setId($user->ID);
|
||||
$customer->setEmailAddress($user->user_email);
|
||||
$customer->setFirstName($user->first_name);
|
||||
$customer->setLastName($user->last_name);
|
||||
|
||||
if (($address = $this->getUserAddress($user->ID))) {
|
||||
if (count($address->toArray()) > 3) {
|
||||
$customer->setAddress($address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!($stats = $this->getCustomerOrderTotals($order->customer_user))) {
|
||||
$stats = (object) array('count' => 0, 'total' => 0);
|
||||
}
|
||||
|
||||
$customer->setOrdersCount($stats->count);
|
||||
$customer->setTotalSpent($stats->total);
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $order_detail
|
||||
* @return MailChimp_WooCommerce_LineItem
|
||||
*/
|
||||
protected function buildLineItem($key, $order_detail)
|
||||
{
|
||||
// fire up a new MC line item
|
||||
$item = new MailChimp_WooCommerce_LineItem();
|
||||
$item->setId($key);
|
||||
|
||||
if (isset($order_detail['item_meta']) && is_array($order_detail['item_meta'])) {
|
||||
|
||||
foreach ($order_detail['item_meta'] as $meta_key => $meta_data_array) {
|
||||
|
||||
if (!isset($meta_data_array[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($meta_key) {
|
||||
|
||||
case '_line_subtotal':
|
||||
$item->setPrice($meta_data_array[0]);
|
||||
break;
|
||||
|
||||
case '_product_id':
|
||||
$item->setProductId($meta_data_array[0]);
|
||||
break;
|
||||
|
||||
case '_variation_id':
|
||||
$item->setProductVariantId($meta_data_array[0]);
|
||||
break;
|
||||
|
||||
case '_qty':
|
||||
$item->setQuantity($meta_data_array[0]);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->getProductVariantId() <= 0) {
|
||||
$item->setProductVariantId($item->getProductId());
|
||||
}
|
||||
|
||||
} elseif (isset($order_detail['item_meta_array']) && is_array($order_detail['item_meta_array'])) {
|
||||
|
||||
/// Some users have the newer version of the item meta.
|
||||
|
||||
foreach ($order_detail['item_meta_array'] as $meta_id => $object) {
|
||||
|
||||
if (!isset($object->key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($object->key) {
|
||||
|
||||
case '_line_subtotal':
|
||||
$item->setPrice($object->value);
|
||||
break;
|
||||
|
||||
case '_product_id':
|
||||
$item->setProductId($object->value);
|
||||
break;
|
||||
|
||||
case '_variation_id':
|
||||
$item->setProductVariantId($object->value);
|
||||
break;
|
||||
|
||||
case '_qty':
|
||||
$item->setQuantity($object->value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->getProductVariantId() <= 0) {
|
||||
$item->setProductVariantId($item->getProductId());
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->getQuantity() > 1) {
|
||||
$current_price = $item->getPrice();
|
||||
$price = ($current_price/$item->getQuantity());
|
||||
$item->setPrice($price);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $posts
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getOrderPosts($page = 1, $posts = 5)
|
||||
{
|
||||
$params = array(
|
||||
'post_type' => 'shop_order',
|
||||
'posts_per_page' => $posts,
|
||||
'paged' => $page,
|
||||
'orderby' => 'id',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
$orders = get_posts($params);
|
||||
|
||||
if (empty($orders)) {
|
||||
sleep(2);
|
||||
$orders = get_posts($params);
|
||||
}
|
||||
|
||||
return empty($orders) ? false : $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an object with a 'total' and a 'count'.
|
||||
*
|
||||
* @param $user_id
|
||||
* @return object
|
||||
*/
|
||||
public function getCustomerOrderTotals($user_id)
|
||||
{
|
||||
$stats = (object) array('count' => 0, 'total' => 0);
|
||||
|
||||
if (!empty($user_id)) {
|
||||
$orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
|
||||
'numberposts' => -1,
|
||||
'meta_key' => '_customer_user',
|
||||
'meta_value' => $user_id,
|
||||
'post_type' => 'shop_order',
|
||||
'post_status' => 'publish'
|
||||
)));
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$woo = new WC_Order($order);
|
||||
$stats->total += $woo->get_total();
|
||||
$stats->count++;
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WC_Order $order
|
||||
* @return object
|
||||
*/
|
||||
public function getOrderAddresses(WC_Order $order)
|
||||
{
|
||||
// use the info from the order to compile an address.
|
||||
$billing = new MailChimp_WooCommerce_Address();
|
||||
$billing->setAddress1($order->billing_address_1);
|
||||
$billing->setAddress2($order->billing_address_2);
|
||||
$billing->setCity($order->billing_city);
|
||||
$billing->setProvince($order->billing_state);
|
||||
$billing->setPostalCode($order->billing_postcode);
|
||||
$billing->setCountry($order->billing_country);
|
||||
$billing->setPhone($order->billing_phone);
|
||||
|
||||
// if we have billing names go ahead and apply them
|
||||
if (!empty($order->billing_first_name) && !empty($order->billing_last_name)) {
|
||||
$billing->setName($order->billing_first_name.' '.$order->billing_last_name);
|
||||
}
|
||||
|
||||
$shipping = new MailChimp_WooCommerce_Address();
|
||||
$shipping->setAddress1($order->shipping_address_1);
|
||||
$shipping->setAddress2($order->shipping_address_2);
|
||||
$shipping->setCity($order->shipping_city);
|
||||
$shipping->setProvince($order->shipping_state);
|
||||
$shipping->setPostalCode($order->shipping_postcode);
|
||||
$shipping->setCountry($order->shipping_country);
|
||||
if (isset($order->shipping_phone)) {
|
||||
$shipping->setPhone($order->shipping_phone);
|
||||
}
|
||||
|
||||
// if we have shipping names go ahead and apply them
|
||||
if (!empty($order->shipping_first_name) && !empty($order->shipping_last_name)) {
|
||||
$shipping->setName($order->shipping_first_name.' '.$order->shipping_last_name);
|
||||
}
|
||||
|
||||
return (object) array('billing' => $billing, 'shipping' => $shipping);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @param string $type
|
||||
* @return MailChimp_WooCommerce_Address
|
||||
*/
|
||||
public function getUserAddress($user_id, $type = 'billing')
|
||||
{
|
||||
$address = new MailChimp_WooCommerce_Address();
|
||||
|
||||
// pull all the meta for this user.
|
||||
$meta = get_user_meta($user_id);
|
||||
|
||||
// loop through all the possible address properties, and if we have on on the user, set the property
|
||||
// because it's more up to date.
|
||||
$address_props = array(
|
||||
$type.'_address_1' => 'setAddress1',
|
||||
$type.'_address_2' => 'setAddress2',
|
||||
$type.'_city' => 'setCity',
|
||||
$type.'_state' => 'setProvince',
|
||||
$type.'_postcode' => 'setPostalCode',
|
||||
$type.'_country' => 'setCountry',
|
||||
$type.'_phone' => 'setPhone',
|
||||
);
|
||||
|
||||
// loop through all the address properties and set the values if we have one.
|
||||
foreach ($address_props as $address_key => $address_call) {
|
||||
if (isset($meta[$address_key]) && !empty($meta[$address_key]) && isset($meta[$address_key][0])) {
|
||||
$address->$address_call($meta[$address_key][0]);
|
||||
}
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses()
|
||||
{
|
||||
return array(
|
||||
// Order received (unpaid)
|
||||
'pending' => (object) array(
|
||||
'financial' => 'pending',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Payment received and stock has been reduced – the order is awaiting fulfillment.
|
||||
// All product orders require processing, except those for digital downloads
|
||||
'processing' => (object) array(
|
||||
'financial' => 'pending',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Awaiting payment – stock is reduced, but you need to confirm payment
|
||||
'on-hold' => (object) array(
|
||||
'financial' => 'on-hold',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Order fulfilled and complete – requires no further action
|
||||
'completed' => (object) array(
|
||||
'financial' => 'fulfilled',
|
||||
'fulfillment' => 'fulfilled'
|
||||
),
|
||||
// Cancelled by an admin or the customer – no further action required
|
||||
'cancelled' => (object) array(
|
||||
'financial' => 'cancelled',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Refunded by an admin – no further action required
|
||||
'refunded' => (object) array(
|
||||
'financial' => 'refunded',
|
||||
'fulfillment' => null
|
||||
),
|
||||
// Payment failed or was declined (unpaid). Note that this status may not show immediately and
|
||||
// instead show as Pending until verified (i.e., PayPal)
|
||||
'failed' => (object) array(
|
||||
'financial' => 'failed',
|
||||
'fulfillment' => null
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/13/16
|
||||
* Time: 8:29 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Transform_Products
|
||||
{
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function compile($page = 1, $limit = 5)
|
||||
{
|
||||
$response = (object) array(
|
||||
'endpoint' => 'products',
|
||||
'page' => $page ? $page : 1,
|
||||
'limit' => (int) $limit,
|
||||
'count' => 0,
|
||||
'stuffed' => false,
|
||||
'items' => array(),
|
||||
);
|
||||
|
||||
if ((($products = $this->getProductPosts($page, $limit)) && !empty($products))) {
|
||||
foreach ($products as $post) {
|
||||
$response->items[] = $this->transform($post);
|
||||
$response->count++;
|
||||
}
|
||||
}
|
||||
|
||||
$response->stuffed = ($response->count > 0 && (int) $response->count === (int) $limit) ? true : false;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_Post $post
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
public function transform(WP_Post $post)
|
||||
{
|
||||
if (!($woo = wc_get_product($post))) {
|
||||
return $this->wooProductNotLoadedCorrectly($post);
|
||||
}
|
||||
|
||||
$variant_posts = $this->getProductVariantPosts($post->ID);
|
||||
|
||||
$variants = $variant_posts ? array_merge(array($woo), $variant_posts) : array($woo);
|
||||
|
||||
$is_variant = count($variants) > 1;
|
||||
|
||||
$product = new MailChimp_WooCommerce_Product();
|
||||
|
||||
$product->setId($woo->get_id());
|
||||
$product->setHandle($post->post_name);
|
||||
$product->setImageUrl($this->getProductImage($post));
|
||||
$product->setDescription($post->post_content);
|
||||
$product->setPublishedAtForeign(mailchimp_date_utc($post->post_date));
|
||||
$product->setTitle($woo->get_title());
|
||||
$product->setUrl($woo->get_permalink());
|
||||
|
||||
foreach ($variants as $variant) {
|
||||
|
||||
$product_variant = $this->variant($is_variant, $variant, $woo->get_title());
|
||||
|
||||
$product_variant_title = $product_variant->getTitle();
|
||||
|
||||
if (empty($product_variant_title)) {
|
||||
$product_variant->setTitle($woo->get_title());
|
||||
}
|
||||
|
||||
$product_variant_image = $product_variant->getImageUrl();
|
||||
|
||||
if (empty($product_variant_image)) {
|
||||
$product_variant->setImageUrl($product->getImageUrl());
|
||||
}
|
||||
|
||||
$product->addVariant($product_variant);
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $is_variant
|
||||
* @param WP_Post $post
|
||||
* @param string $fallback_title
|
||||
* @return MailChimp_WooCommerce_ProductVariation
|
||||
*/
|
||||
public function variant($is_variant, $post, $fallback_title = null)
|
||||
{
|
||||
if ($post instanceof WC_Product || $post instanceof WC_Product_Variation) {
|
||||
$woo = $post;
|
||||
} else {
|
||||
if (isset($post->post_type) && $post->post_type === 'product_variation') {
|
||||
$woo = new WC_Product_Variation($post->ID);
|
||||
} else {
|
||||
$woo = wc_get_product($post);
|
||||
}
|
||||
}
|
||||
|
||||
$variant = new MailChimp_WooCommerce_ProductVariation();
|
||||
|
||||
$variant->setId($woo->get_id());
|
||||
$variant->setUrl($woo->get_permalink());
|
||||
$variant->setImageUrl($this->getProductImage($post));
|
||||
$variant->setPrice($woo->get_price());
|
||||
$variant->setSku($woo->get_sku());
|
||||
$variant->setBackorders($woo->backorders_allowed());
|
||||
|
||||
// only set these properties if the product is currently visible or purchasable.
|
||||
if ($woo->is_purchasable() && $woo->is_visible()) {
|
||||
if ($woo->is_in_stock()) {
|
||||
$variant->setInventoryQuantity(($woo->managing_stock() ? $woo->get_stock_quantity() : 1000000));
|
||||
} else {
|
||||
$variant->setInventoryQuantity(0);
|
||||
}
|
||||
} else {
|
||||
$variant->setInventoryQuantity(0);
|
||||
}
|
||||
|
||||
if ($woo instanceof WC_Product_Variation) {
|
||||
|
||||
$variation_title = $woo->get_title();
|
||||
if (empty($variation_title)) $variation_title = $fallback_title;
|
||||
|
||||
$title = array($variation_title);
|
||||
|
||||
foreach ($woo->get_variation_attributes() as $attribute => $value) {
|
||||
if (is_string($value)) {
|
||||
$name = ucfirst(str_replace(array('attribute_pa_', 'attribute_'), '', $attribute));
|
||||
$title[] = "$name = $value";
|
||||
}
|
||||
}
|
||||
|
||||
$variant->setTitle(implode(' :: ', $title));
|
||||
$variant->setVisibility(($woo->variation_is_visible() ? 'visible' : ''));
|
||||
} else {
|
||||
$variant->setVisibility(($woo->is_visible() ? 'visible' : ''));
|
||||
$variant->setTitle($woo->get_title());
|
||||
}
|
||||
|
||||
return $variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $posts
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getProductPosts($page = 1, $posts = 5)
|
||||
{
|
||||
$products = get_posts(array(
|
||||
'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
|
||||
'posts_per_page' => $posts,
|
||||
'paged' => $page,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
));
|
||||
|
||||
if (empty($products)) {
|
||||
|
||||
sleep(2);
|
||||
|
||||
$products = get_posts(array(
|
||||
'post_type' => array_merge(array_keys(wc_get_product_types()), array('product')),
|
||||
'posts_per_page' => $posts,
|
||||
'paged' => $page,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
));
|
||||
|
||||
if (empty($products)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getProductVariantPosts($id)
|
||||
{
|
||||
$variants = get_posts(array(
|
||||
'numberposts' => 99999,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'ID',
|
||||
'post_type' => 'product_variation',
|
||||
'post_parent' => $id,
|
||||
));
|
||||
|
||||
if (empty($variants)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return mailchimp_get_option('mailchimp_product_image_key', 'medium');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool|MailChimp_WooCommerce_Product
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deleted($id)
|
||||
{
|
||||
$store_id = mailchimp_get_store_id();
|
||||
$api = mailchimp_get_api();
|
||||
|
||||
if (!($product = $api->getStoreProduct($store_id, "deleted_{$id}"))) {
|
||||
$product = new MailChimp_WooCommerce_Product();
|
||||
|
||||
$product->setId("deleted_{$id}");
|
||||
$product->setTitle("deleted_{$id}");
|
||||
|
||||
$variant = new MailChimp_WooCommerce_ProductVariation();
|
||||
$variant->setId("deleted_{$id}");
|
||||
$variant->setTitle("deleted_{$id}");
|
||||
|
||||
$product->addVariant($variant);
|
||||
|
||||
return $api->addStoreProduct($store_id, $product);
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_Post $post
|
||||
* @return MailChimp_WooCommerce_Product
|
||||
*/
|
||||
protected function wooProductNotLoadedCorrectly($post)
|
||||
{
|
||||
$product = new MailChimp_WooCommerce_Product();
|
||||
$product->setId($post->ID);
|
||||
$product->setHandle($post->post_name);
|
||||
$product->setDescription($post->post_content);
|
||||
$product->setImageUrl($this->getProductImage($post));
|
||||
|
||||
$variant = $this->variant(false, $post, $post->post_name);
|
||||
|
||||
if (!$variant->getImageUrl()) {
|
||||
$variant->setImageUrl($product->getImageUrl());
|
||||
}
|
||||
|
||||
$product->addVariant($variant);
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
*
|
||||
* User: kingpin
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 6/18/15
|
||||
* Time: 11:13 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_Error extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
*
|
||||
* User: kingpin
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 6/18/15
|
||||
* Time: 11:13 AM
|
||||
*/
|
||||
class MailChimp_WooCommerce_ServerError extends MailChimp_WooCommerce_Error
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/12/16
|
||||
* Time: 1:38 PM
|
||||
*/
|
||||
class MailChimp_WooCommerce_CurrencyCodes
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
return array(
|
||||
'AFA' => array('Afghan Afghani', '971'),
|
||||
'AWG' => array('Aruban Florin', '533'),
|
||||
'AUD' => array('Australian Dollars', '036'),
|
||||
'ARS' => array('Argentine Pes', '032'),
|
||||
'AZN' => array('Azerbaijanian Manat', '944'),
|
||||
'BSD' => array('Bahamian Dollar', '044'),
|
||||
'BDT' => array('Bangladeshi Taka', '050'),
|
||||
'BBD' => array('Barbados Dollar', '052'),
|
||||
'BYN' => array('Belarussian Rouble', '974'),
|
||||
'BOB' => array('Bolivian Boliviano', '068'),
|
||||
'BRL' => array('Brazilian Real', '986'),
|
||||
'GBP' => array('British Pounds Sterling', '826'),
|
||||
'BGN' => array('Bulgarian Lev', '975'),
|
||||
'KHR' => array('Cambodia Riel', '116'),
|
||||
'CAD' => array('Canadian Dollars', '124'),
|
||||
'KYD' => array('Cayman Islands Dollar', '136'),
|
||||
'CLP' => array('Chilean Peso', '152'),
|
||||
'CNY' => array('Chinese Renminbi Yuan', '156'),
|
||||
'COP' => array('Colombian Peso', '170'),
|
||||
'CRC' => array('Costa Rican Colon', '188'),
|
||||
'HRK' => array('Croatia Kuna', '191'),
|
||||
'CPY' => array('Cypriot Pounds', '196'),
|
||||
'CZK' => array('Czech Koruna', '203'),
|
||||
'DKK' => array('Danish Krone', '208'),
|
||||
'DOP' => array('Dominican Republic Peso', '214'),
|
||||
'XCD' => array('East Caribbean Dollar', '951'),
|
||||
'EGP' => array('Egyptian Pound', '818'),
|
||||
'ERN' => array('Eritrean Nakfa', '232'),
|
||||
'EEK' => array('Estonia Kroon', '233'),
|
||||
'EUR' => array('Euro', '978'),
|
||||
'GEL' => array('Georgian Lari', '981'),
|
||||
'GHC' => array('Ghana Cedi', '288'),
|
||||
'GIP' => array('Gibraltar Pound', '292'),
|
||||
'GTQ' => array('Guatemala Quetzal', '320'),
|
||||
'HNL' => array('Honduras Lempira', '340'),
|
||||
'HKD' => array('Hong Kong Dollars', '344'),
|
||||
'HUF' => array('Hungary Forint', '348'),
|
||||
'ISK' => array('Icelandic Krona', '352'),
|
||||
'INR' => array('Indian Rupee', '356'),
|
||||
'IDR' => array('Indonesia Rupiah', '360'),
|
||||
'ILS' => array('Israel Shekel', '376'),
|
||||
'JMD' => array('Jamaican Dollar', '388'),
|
||||
'JPY' => array('Japanese yen', '392'),
|
||||
'KZT' => array('Kazakhstan Tenge', '368'),
|
||||
'KES' => array('Kenyan Shilling', '404'),
|
||||
'KWD' => array('Kuwaiti Dinar', '414'),
|
||||
'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'),
|
||||
'MYR' => array('Malaysian Ringgit', '458'),
|
||||
'MTL' => array('Maltese Lira', '470'),
|
||||
'BAM' => array('Marka', '977'),
|
||||
'MUR' => array('Mauritius Rupee', '480'),
|
||||
'MXN' => array('Mexican Pesos', '484'),
|
||||
'MZM' => array('Mozambique Metical', '508'),
|
||||
'NPR' => array('Nepalese Rupee', '524'),
|
||||
'ANG' => array('Netherlands Antilles Guilder', '532'),
|
||||
'TWD' => array('New Taiwanese Dollars', '901'),
|
||||
'NZD' => array('New Zealand Dollars', '554'),
|
||||
'NIO' => array('Nicaragua Cordoba', '558'),
|
||||
'NGN' => array('Nigeria Naira', '566'),
|
||||
'KPW' => array('North Korean Won', '408'),
|
||||
'NOK' => array('Norwegian Krone', '578'),
|
||||
'OMR' => array('Omani Riyal', '512'),
|
||||
'PKR' => array('Pakistani Rupee', '586'),
|
||||
'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'),
|
||||
'SAR' => array('Saudi Riyal', '682'),
|
||||
'CSD' => array('Serbian Dinar', '891'),
|
||||
'SCR' => array('Seychelles Rupee', '690'),
|
||||
'SGD' => array('Singapore Dollars', '702'),
|
||||
'SKK' => array('Slovak Koruna', '703'),
|
||||
'SIT' => array('Slovenia Tolar', '705'),
|
||||
'ZAR' => array('South African Rand', '710'),
|
||||
'KRW' => array('South Korean Won', '410'),
|
||||
'LKR' => array('Sri Lankan Rupee', '144'),
|
||||
'SRD' => array('Surinam Dollar', '968'),
|
||||
'SEK' => array('Swedish Krona', '752'),
|
||||
'CHF' => array('Swiss Francs', '756'),
|
||||
'TZS' => array('Tanzanian Shilling', '834'),
|
||||
'THB' => array('Thai Baht', '764'),
|
||||
'TTD' => array('Trinidad and Tobago Dollar', '780'),
|
||||
'TRY' => array('Turkish New Lira', '949'),
|
||||
'AED' => array('UAE Dirham', '784'),
|
||||
'USD' => array('US Dollars', '840'),
|
||||
'UGX' => array('Ugandian Shilling', '800'),
|
||||
'UAH' => array('Ukraine Hryvna', '980'),
|
||||
'UYU' => array('Uruguayan Peso', '858'),
|
||||
'UZS' => array('Uzbekistani Som', '860'),
|
||||
'VEB' => array('Venezuela Bolivar', '862'),
|
||||
'VND' => array('Vietnam Dong', '704'),
|
||||
'AMK' => array('Zambian Kwacha', '894'),
|
||||
'ZWD' => array('Zimbabwe Dollar', '716'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$response = array();
|
||||
foreach (static::all() as $key => $data) {
|
||||
$response[$key] = $data[0];
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vextras.
|
||||
*
|
||||
* Name: Ryan Hungate
|
||||
* Email: ryan@vextras.com
|
||||
* Date: 7/12/16
|
||||
* Time: 2:07 PM
|
||||
*/
|
||||
class MailChimp_Api_Locales
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
return array(
|
||||
"af_NA"=> "Afrikaans (Namibia)",
|
||||
"af_ZA"=> "Afrikaans (South Africa)",
|
||||
"af"=> "Afrikaans",
|
||||
"ak_GH"=> "Akan (Ghana)",
|
||||
"ak"=> "Akan",
|
||||
"sq_AL"=> "Albanian (Albania)",
|
||||
"sq"=> "Albanian",
|
||||
"am_ET"=> "Amharic (Ethiopia)",
|
||||
"am"=> "Amharic",
|
||||
"ar_DZ"=> "Arabic (Algeria)",
|
||||
"ar_BH"=> "Arabic (Bahrain)",
|
||||
"ar_EG"=> "Arabic (Egypt)",
|
||||
"ar_IQ"=> "Arabic (Iraq)",
|
||||
"ar_JO"=> "Arabic (Jordan)",
|
||||
"ar_KW"=> "Arabic (Kuwait)",
|
||||
"ar_LB"=> "Arabic (Lebanon)",
|
||||
"ar_LY"=> "Arabic (Libya)",
|
||||
"ar_MA"=> "Arabic (Morocco)",
|
||||
"ar_OM"=> "Arabic (Oman)",
|
||||
"ar_QA"=> "Arabic (Qatar)",
|
||||
"ar_SA"=> "Arabic (Saudi Arabia)",
|
||||
"ar_SD"=> "Arabic (Sudan)",
|
||||
"ar_SY"=> "Arabic (Syria)",
|
||||
"ar_TN"=> "Arabic (Tunisia)",
|
||||
"ar_AE"=> "Arabic (United Arab Emirates)",
|
||||
"ar_YE"=> "Arabic (Yemen)",
|
||||
"ar"=> "Arabic",
|
||||
"hy_AM"=> "Armenian (Armenia)",
|
||||
"hy"=> "Armenian",
|
||||
"as_IN"=> "Assamese (India)",
|
||||
"as"=> "Assamese",
|
||||
"asa_TZ"=> "Asu (Tanzania)",
|
||||
"asa"=> "Asu",
|
||||
"az_Cyrl"=> "Azerbaijani (Cyrillic)",
|
||||
"az_Cyrl_AZ"=> "Azerbaijani (Cyrillic, Azerbaijan)",
|
||||
"az_Latn"=> "Azerbaijani (Latin)",
|
||||
"az_Latn_AZ"=> "Azerbaijani (Latin, Azerbaijan)",
|
||||
"az"=> "Azerbaijani",
|
||||
"bm_ML"=> "Bambara (Mali)",
|
||||
"bm"=> "Bambara",
|
||||
"eu_ES"=> "Basque (Spain)",
|
||||
"eu"=> "Basque",
|
||||
"be_BY"=> "Belarusian (Belarus)",
|
||||
"be"=> "Belarusian",
|
||||
"bem_ZM"=> "Bemba (Zambia)",
|
||||
"bem"=> "Bemba",
|
||||
"bez_TZ"=> "Bena (Tanzania)",
|
||||
"bez"=> "Bena",
|
||||
"bn_BD"=> "Bengali (Bangladesh)",
|
||||
"bn_IN"=> "Bengali (India)",
|
||||
"bn"=> "Bengali",
|
||||
"bs_BA"=> "Bosnian (Bosnia and Herzegovina)",
|
||||
"bs"=> "Bosnian",
|
||||
"bg_BG"=> "Bulgarian (Bulgaria)",
|
||||
"bg"=> "Bulgarian",
|
||||
"my_MM"=> "Burmese (Myanmar [Burma])",
|
||||
"my"=> "Burmese",
|
||||
"ca_ES"=> "Catalan (Spain)",
|
||||
"ca"=> "Catalan",
|
||||
"tzm_Latn"=> "Central Morocco Tamazight (Latin)",
|
||||
"tzm_Latn_MA"=> "Central Morocco Tamazight (Latin, Morocco)",
|
||||
"tzm"=> "Central Morocco Tamazight",
|
||||
"chr_US"=> "Cherokee (United States)",
|
||||
"chr"=> "Cherokee",
|
||||
"cgg_UG"=> "Chiga (Uganda)",
|
||||
"cgg"=> "Chiga",
|
||||
"zh_Hans"=> "Chinese (Simplified Han)",
|
||||
"zh_Hans_CN"=> "Chinese (Simplified Han, China)",
|
||||
"zh_Hans_HK"=> "Chinese (Simplified Han, Hong Kong SAR China)",
|
||||
"zh_Hans_MO"=> "Chinese (Simplified Han, Macau SAR China)",
|
||||
"zh_Hans_SG"=> "Chinese (Simplified Han, Singapore)",
|
||||
"zh_Hant"=> "Chinese (Traditional Han)",
|
||||
"zh_Hant_HK"=> "Chinese (Traditional Han, Hong Kong SAR China)",
|
||||
"zh_Hant_MO"=> "Chinese (Traditional Han, Macau SAR China)",
|
||||
"zh_Hant_TW"=> "Chinese (Traditional Han, Taiwan)",
|
||||
"zh"=> "Chinese",
|
||||
"kw_GB"=> "Cornish (United Kingdom)",
|
||||
"kw"=> "Cornish",
|
||||
"hr_HR"=> "Croatian (Croatia)",
|
||||
"hr"=> "Croatian",
|
||||
"cs_CZ"=> "Czech (Czech Republic)",
|
||||
"cs"=> "Czech",
|
||||
"da_DK"=> "Danish (Denmark)",
|
||||
"da"=> "Danish",
|
||||
"nl_BE"=> "Dutch (Belgium)",
|
||||
"nl_NL"=> "Dutch (Netherlands)",
|
||||
"nl"=> "Dutch",
|
||||
"ebu_KE"=> "Embu (Kenya)",
|
||||
"ebu"=> "Embu",
|
||||
"en_AS"=> "English (American Samoa)",
|
||||
"en_AU"=> "English (Australia)",
|
||||
"en_BE"=> "English (Belgium)",
|
||||
"en_BZ"=> "English (Belize)",
|
||||
"en_BW"=> "English (Botswana)",
|
||||
"en_CA"=> "English (Canada)",
|
||||
"en_GU"=> "English (Guam)",
|
||||
"en_HK"=> "English (Hong Kong SAR China)",
|
||||
"en_IN"=> "English (India)",
|
||||
"en_IE"=> "English (Ireland)",
|
||||
"en_JM"=> "English (Jamaica)",
|
||||
"en_MT"=> "English (Malta)",
|
||||
"en_MH"=> "English (Marshall Islands)",
|
||||
"en_MU"=> "English (Mauritius)",
|
||||
"en_NA"=> "English (Namibia)",
|
||||
"en_NZ"=> "English (New Zealand)",
|
||||
"en_MP"=> "English (Northern Mariana Islands)",
|
||||
"en_PK"=> "English (Pakistan)",
|
||||
"en_PH"=> "English (Philippines)",
|
||||
"en_SG"=> "English (Singapore)",
|
||||
"en_ZA"=> "English (South Africa)",
|
||||
"en_TT"=> "English (Trinidad and Tobago)",
|
||||
"en_UM"=> "English (U.S. Minor Outlying Islands)",
|
||||
"en_VI"=> "English (U.S. Virgin Islands)",
|
||||
"en_GB"=> "English (United Kingdom)",
|
||||
"en_US"=> "English (United States)",
|
||||
"en_ZW"=> "English (Zimbabwe)",
|
||||
"en"=> "English",
|
||||
"eo"=> "Esperanto",
|
||||
"et_EE"=> "Estonian (Estonia)",
|
||||
"et"=> "Estonian",
|
||||
"ee_GH"=> "Ewe (Ghana)",
|
||||
"ee_TG"=> "Ewe (Togo)",
|
||||
"ee"=> "Ewe",
|
||||
"fo_FO"=> "Faroese (Faroe Islands)",
|
||||
"fo"=> "Faroese",
|
||||
"fil_PH"=> "Filipino (Philippines)",
|
||||
"fil"=> "Filipino",
|
||||
"fi_FI"=> "Finnish (Finland)",
|
||||
"fi"=> "Finnish",
|
||||
"fr_BE"=> "French (Belgium)",
|
||||
"fr_BJ"=> "French (Benin)",
|
||||
"fr_BF"=> "French (Burkina Faso)",
|
||||
"fr_BI"=> "French (Burundi)",
|
||||
"fr_CM"=> "French (Cameroon)",
|
||||
"fr_CA"=> "French (Canada)",
|
||||
"fr_CF"=> "French (Central African Republic)",
|
||||
"fr_TD"=> "French (Chad)",
|
||||
"fr_KM"=> "French (Comoros)",
|
||||
"fr_CG"=> "French (Congo - Brazzaville)",
|
||||
"fr_CD"=> "French (Congo - Kinshasa)",
|
||||
"fr_CI"=> "French (Côte d’Ivoire)",
|
||||
"fr_DJ"=> "French (Djibouti)",
|
||||
"fr_GQ"=> "French (Equatorial Guinea)",
|
||||
"fr_FR"=> "French (France)",
|
||||
"fr_GA"=> "French (Gabon)",
|
||||
"fr_GP"=> "French (Guadeloupe)",
|
||||
"fr_GN"=> "French (Guinea)",
|
||||
"fr_LU"=> "French (Luxembourg)",
|
||||
"fr_MG"=> "French (Madagascar)",
|
||||
"fr_ML"=> "French (Mali)",
|
||||
"fr_MQ"=> "French (Martinique)",
|
||||
"fr_MC"=> "French (Monaco)",
|
||||
"fr_NE"=> "French (Niger)",
|
||||
"fr_RW"=> "French (Rwanda)",
|
||||
"fr_RE"=> "French (Réunion)",
|
||||
"fr_BL"=> "French (Saint Barthélemy)",
|
||||
"fr_MF"=> "French (Saint Martin)",
|
||||
"fr_SN"=> "French (Senegal)",
|
||||
"fr_CH"=> "French (Switzerland)",
|
||||
"fr_TG"=> "French (Togo)",
|
||||
"fr"=> "French",
|
||||
"ff_SN"=> "Fulah (Senegal)",
|
||||
"ff"=> "Fulah",
|
||||
"gl_ES"=> "Galician (Spain)",
|
||||
"gl"=> "Galician",
|
||||
"lg_UG"=> "Ganda (Uganda)",
|
||||
"lg"=> "Ganda",
|
||||
"ka_GE"=> "Georgian (Georgia)",
|
||||
"ka"=> "Georgian",
|
||||
"de_AT"=> "German (Austria)",
|
||||
"de_BE"=> "German (Belgium)",
|
||||
"de_DE"=> "German (Germany)",
|
||||
"de_LI"=> "German (Liechtenstein)",
|
||||
"de_LU"=> "German (Luxembourg)",
|
||||
"de_CH"=> "German (Switzerland)",
|
||||
"de"=> "German",
|
||||
"el_CY"=> "Greek (Cyprus)",
|
||||
"el_GR"=> "Greek (Greece)",
|
||||
"el"=> "Greek",
|
||||
"gu_IN"=> "Gujarati (India)",
|
||||
"gu"=> "Gujarati",
|
||||
"guz_KE"=> "Gusii (Kenya)",
|
||||
"guz"=> "Gusii",
|
||||
"ha_Latn"=> "Hausa (Latin)",
|
||||
"ha_Latn_GH"=> "Hausa (Latin, Ghana)",
|
||||
"ha_Latn_NE"=> "Hausa (Latin, Niger)",
|
||||
"ha_Latn_NG"=> "Hausa (Latin, Nigeria)",
|
||||
"ha"=> "Hausa",
|
||||
"haw_US"=> "Hawaiian (United States)",
|
||||
"haw"=> "Hawaiian",
|
||||
"he_IL"=> "Hebrew (Israel)",
|
||||
"he"=> "Hebrew",
|
||||
"hi_IN"=> "Hindi (India)",
|
||||
"hi"=> "Hindi",
|
||||
"hu_HU"=> "Hungarian (Hungary)",
|
||||
"hu"=> "Hungarian",
|
||||
"is_IS"=> "Icelandic (Iceland)",
|
||||
"is"=> "Icelandic",
|
||||
"ig_NG"=> "Igbo (Nigeria)",
|
||||
"ig"=> "Igbo",
|
||||
"id_ID"=> "Indonesian (Indonesia)",
|
||||
"id"=> "Indonesian",
|
||||
"ga_IE"=> "Irish (Ireland)",
|
||||
"ga"=> "Irish",
|
||||
"it_IT"=> "Italian (Italy)",
|
||||
"it_CH"=> "Italian (Switzerland)",
|
||||
"it"=> "Italian",
|
||||
"ja_JP"=> "Japanese (Japan)",
|
||||
"ja"=> "Japanese",
|
||||
"kea_CV"=> "Kabuverdianu (Cape Verde)",
|
||||
"kea"=> "Kabuverdianu",
|
||||
"kab_DZ"=> "Kabyle (Algeria)",
|
||||
"kab"=> "Kabyle",
|
||||
"kl_GL"=> "Kalaallisut (Greenland)",
|
||||
"kl"=> "Kalaallisut",
|
||||
"kln_KE"=> "Kalenjin (Kenya)",
|
||||
"kln"=> "Kalenjin",
|
||||
"kam_KE"=> "Kamba (Kenya)",
|
||||
"kam"=> "Kamba",
|
||||
"kn_IN"=> "Kannada (India)",
|
||||
"kn"=> "Kannada",
|
||||
"kk_Cyrl"=> "Kazakh (Cyrillic)",
|
||||
"kk_Cyrl_KZ"=> "Kazakh (Cyrillic, Kazakhstan)",
|
||||
"kk"=> "Kazakh",
|
||||
"km_KH"=> "Khmer (Cambodia)",
|
||||
"km"=> "Khmer",
|
||||
"ki_KE"=> "Kikuyu (Kenya)",
|
||||
"ki"=> "Kikuyu",
|
||||
"rw_RW"=> "Kinyarwanda (Rwanda)",
|
||||
"rw"=> "Kinyarwanda",
|
||||
"kok_IN"=> "Konkani (India)",
|
||||
"kok"=> "Konkani",
|
||||
"ko_KR"=> "Korean (South Korea)",
|
||||
"ko"=> "Korean",
|
||||
"khq_ML"=> "Koyra Chiini (Mali)",
|
||||
"khq"=> "Koyra Chiini",
|
||||
"ses_ML"=> "Koyraboro Senni (Mali)",
|
||||
"ses"=> "Koyraboro Senni",
|
||||
"lag_TZ"=> "Langi (Tanzania)",
|
||||
"lag"=> "Langi",
|
||||
"lv_LV"=> "Latvian (Latvia)",
|
||||
"lv"=> "Latvian",
|
||||
"lt_LT"=> "Lithuanian (Lithuania)",
|
||||
"lt"=> "Lithuanian",
|
||||
"luo_KE"=> "Luo (Kenya)",
|
||||
"luo"=> "Luo",
|
||||
"luy_KE"=> "Luyia (Kenya)",
|
||||
"luy"=> "Luyia",
|
||||
"mk_MK"=> "Macedonian (Macedonia)",
|
||||
"mk"=> "Macedonian",
|
||||
"jmc_TZ"=> "Machame (Tanzania)",
|
||||
"jmc"=> "Machame",
|
||||
"kde_TZ"=> "Makonde (Tanzania)",
|
||||
"kde"=> "Makonde",
|
||||
"mg_MG"=> "Malagasy (Madagascar)",
|
||||
"mg"=> "Malagasy",
|
||||
"ms_BN"=> "Malay (Brunei)",
|
||||
"ms_MY"=> "Malay (Malaysia)",
|
||||
"ms"=> "Malay",
|
||||
"ml_IN"=> "Malayalam (India)",
|
||||
"ml"=> "Malayalam",
|
||||
"mt_MT"=> "Maltese (Malta)",
|
||||
"mt"=> "Maltese",
|
||||
"gv_GB"=> "Manx (United Kingdom)",
|
||||
"gv"=> "Manx",
|
||||
"mr_IN"=> "Marathi (India)",
|
||||
"mr"=> "Marathi",
|
||||
"mas_KE"=> "Masai (Kenya)",
|
||||
"mas_TZ"=> "Masai (Tanzania)",
|
||||
"mas"=> "Masai",
|
||||
"mer_KE"=> "Meru (Kenya)",
|
||||
"mer"=> "Meru",
|
||||
"mfe_MU"=> "Morisyen (Mauritius)",
|
||||
"mfe"=> "Morisyen",
|
||||
"naq_NA"=> "Nama (Namibia)",
|
||||
"naq"=> "Nama",
|
||||
"ne_IN"=> "Nepali (India)",
|
||||
"ne_NP"=> "Nepali (Nepal)",
|
||||
"ne"=> "Nepali",
|
||||
"nd_ZW"=> "North Ndebele (Zimbabwe)",
|
||||
"nd"=> "North Ndebele",
|
||||
"nb_NO"=> "Norwegian Bokmål (Norway)",
|
||||
"nb"=> "Norwegian Bokmål",
|
||||
"nn_NO"=> "Norwegian Nynorsk (Norway)",
|
||||
"nn"=> "Norwegian Nynorsk",
|
||||
"nyn_UG"=> "Nyankole (Uganda)",
|
||||
"nyn"=> "Nyankole",
|
||||
"or_IN"=> "Oriya (India)",
|
||||
"or"=> "Oriya",
|
||||
"om_ET"=> "Oromo (Ethiopia)",
|
||||
"om_KE"=> "Oromo (Kenya)",
|
||||
"om"=> "Oromo",
|
||||
"ps_AF"=> "Pashto (Afghanistan)",
|
||||
"ps"=> "Pashto",
|
||||
"fa_AF"=> "Persian (Afghanistan)",
|
||||
"fa_IR"=> "Persian (Iran)",
|
||||
"fa"=> "Persian",
|
||||
"pl_PL"=> "Polish (Poland)",
|
||||
"pl"=> "Polish",
|
||||
"pt_BR"=> "Portuguese (Brazil)",
|
||||
"pt_GW"=> "Portuguese (Guinea-Bissau)",
|
||||
"pt_MZ"=> "Portuguese (Mozambique)",
|
||||
"pt_PT"=> "Portuguese (Portugal)",
|
||||
"pt"=> "Portuguese",
|
||||
"pa_Arab"=> "Punjabi (Arabic)",
|
||||
"pa_Arab_PK"=> "Punjabi (Arabic, Pakistan)",
|
||||
"pa_Guru"=> "Punjabi (Gurmukhi)",
|
||||
"pa_Guru_IN"=> "Punjabi (Gurmukhi, India)",
|
||||
"pa"=> "Punjabi",
|
||||
"ro_MD"=> "Romanian (Moldova)",
|
||||
"ro_RO"=> "Romanian (Romania)",
|
||||
"ro"=> "Romanian",
|
||||
"rm_CH"=> "Romansh (Switzerland)",
|
||||
"rm"=> "Romansh",
|
||||
"rof_TZ"=> "Rombo (Tanzania)",
|
||||
"rof"=> "Rombo",
|
||||
"ru_MD"=> "Russian (Moldova)",
|
||||
"ru_RU"=> "Russian (Russia)",
|
||||
"ru_UA"=> "Russian (Ukraine)",
|
||||
"ru"=> "Russian",
|
||||
"rwk_TZ"=> "Rwa (Tanzania)",
|
||||
"rwk"=> "Rwa",
|
||||
"saq_KE"=> "Samburu (Kenya)",
|
||||
"saq"=> "Samburu",
|
||||
"sg_CF"=> "Sango (Central African Republic)",
|
||||
"sg"=> "Sango",
|
||||
"seh_MZ"=> "Sena (Mozambique)",
|
||||
"seh"=> "Sena",
|
||||
"sr_Cyrl"=> "Serbian (Cyrillic)",
|
||||
"sr_Cyrl_BA"=> "Serbian (Cyrillic, Bosnia and Herzegovina)",
|
||||
"sr_Cyrl_ME"=> "Serbian (Cyrillic, Montenegro)",
|
||||
"sr_Cyrl_RS"=> "Serbian (Cyrillic, Serbia)",
|
||||
"sr_Latn"=> "Serbian (Latin)",
|
||||
"sr_Latn_BA"=> "Serbian (Latin, Bosnia and Herzegovina)",
|
||||
"sr_Latn_ME"=> "Serbian (Latin, Montenegro)",
|
||||
"sr_Latn_RS"=> "Serbian (Latin, Serbia)",
|
||||
"sr"=> "Serbian",
|
||||
"sn_ZW"=> "Shona (Zimbabwe)",
|
||||
"sn"=> "Shona",
|
||||
"ii_CN"=> "Sichuan Yi (China)",
|
||||
"ii"=> "Sichuan Yi",
|
||||
"si_LK"=> "Sinhala (Sri Lanka)",
|
||||
"si"=> "Sinhala",
|
||||
"sk_SK"=> "Slovak (Slovakia)",
|
||||
"sk"=> "Slovak",
|
||||
"sl_SI"=> "Slovenian (Slovenia)",
|
||||
"sl"=> "Slovenian",
|
||||
"xog_UG"=> "Soga (Uganda)",
|
||||
"xog"=> "Soga",
|
||||
"so_DJ"=> "Somali (Djibouti)",
|
||||
"so_ET"=> "Somali (Ethiopia)",
|
||||
"so_KE"=> "Somali (Kenya)",
|
||||
"so_SO"=> "Somali (Somalia)",
|
||||
"so"=> "Somali",
|
||||
"es_AR"=> "Spanish (Argentina)",
|
||||
"es_BO"=> "Spanish (Bolivia)",
|
||||
"es_CL"=> "Spanish (Chile)",
|
||||
"es_CO"=> "Spanish (Colombia)",
|
||||
"es_CR"=> "Spanish (Costa Rica)",
|
||||
"es_DO"=> "Spanish (Dominican Republic)",
|
||||
"es_EC"=> "Spanish (Ecuador)",
|
||||
"es_SV"=> "Spanish (El Salvador)",
|
||||
"es_GQ"=> "Spanish (Equatorial Guinea)",
|
||||
"es_GT"=> "Spanish (Guatemala)",
|
||||
"es_HN"=> "Spanish (Honduras)",
|
||||
"es_419"=> "Spanish (Latin America)",
|
||||
"es_MX"=> "Spanish (Mexico)",
|
||||
"es_NI"=> "Spanish (Nicaragua)",
|
||||
"es_PA"=> "Spanish (Panama)",
|
||||
"es_PY"=> "Spanish (Paraguay)",
|
||||
"es_PE"=> "Spanish (Peru)",
|
||||
"es_PR"=> "Spanish (Puerto Rico)",
|
||||
"es_ES"=> "Spanish (Spain)",
|
||||
"es_US"=> "Spanish (United States)",
|
||||
"es_UY"=> "Spanish (Uruguay)",
|
||||
"es_VE"=> "Spanish (Venezuela)",
|
||||
"es"=> "Spanish",
|
||||
"sw_KE"=> "Swahili (Kenya)",
|
||||
"sw_TZ"=> "Swahili (Tanzania)",
|
||||
"sw"=> "Swahili",
|
||||
"sv_FI"=> "Swedish (Finland)",
|
||||
"sv_SE"=> "Swedish (Sweden)",
|
||||
"sv"=> "Swedish",
|
||||
"gsw_CH"=> "Swiss German (Switzerland)",
|
||||
"gsw"=> "Swiss German",
|
||||
"shi_Latn"=> "Tachelhit (Latin)",
|
||||
"shi_Latn_MA"=> "Tachelhit (Latin, Morocco)",
|
||||
"shi_Tfng"=> "Tachelhit (Tifinagh)",
|
||||
"shi_Tfng_MA"=> "Tachelhit (Tifinagh, Morocco)",
|
||||
"shi"=> "Tachelhit",
|
||||
"dav_KE"=> "Taita (Kenya)",
|
||||
"dav"=> "Taita",
|
||||
"ta_IN"=> "Tamil (India)",
|
||||
"ta_LK"=> "Tamil (Sri Lanka)",
|
||||
"ta"=> "Tamil",
|
||||
"te_IN"=> "Telugu (India)",
|
||||
"te"=> "Telugu",
|
||||
"teo_KE"=> "Teso (Kenya)",
|
||||
"teo_UG"=> "Teso (Uganda)",
|
||||
"teo"=> "Teso",
|
||||
"th_TH"=> "Thai (Thailand)",
|
||||
"th"=> "Thai",
|
||||
"bo_CN"=> "Tibetan (China)",
|
||||
"bo_IN"=> "Tibetan (India)",
|
||||
"bo"=> "Tibetan",
|
||||
"ti_ER"=> "Tigrinya (Eritrea)",
|
||||
"ti_ET"=> "Tigrinya (Ethiopia)",
|
||||
"ti"=> "Tigrinya",
|
||||
"to_TO"=> "Tonga (Tonga)",
|
||||
"to"=> "Tonga",
|
||||
"tr_TR"=> "Turkish (Turkey)",
|
||||
"tr"=> "Turkish",
|
||||
"uk_UA"=> "Ukrainian (Ukraine)",
|
||||
"uk"=> "Ukrainian",
|
||||
"ur_IN"=> "Urdu (India)",
|
||||
"ur_PK"=> "Urdu (Pakistan)",
|
||||
"ur"=> "Urdu",
|
||||
"uz_Arab"=> "Uzbek (Arabic)",
|
||||
"uz_Arab_AF"=> "Uzbek (Arabic, Afghanistan)",
|
||||
"uz_Cyrl"=> "Uzbek (Cyrillic)",
|
||||
"uz_Cyrl_UZ"=> "Uzbek (Cyrillic, Uzbekistan)",
|
||||
"uz_Latn"=> "Uzbek (Latin)",
|
||||
"uz_Latn_UZ"=> "Uzbek (Latin, Uzbekistan)",
|
||||
"uz"=> "Uzbek",
|
||||
"vi_VN"=> "Vietnamese (Vietnam)",
|
||||
"vi"=> "Vietnamese",
|
||||
"vun_TZ"=> "Vunjo (Tanzania)",
|
||||
"vun"=> "Vunjo",
|
||||
"cy_GB"=> "Welsh (United Kingdom)",
|
||||
"cy"=> "Welsh",
|
||||
"yo_NG"=> "Yoruba (Nigeria)",
|
||||
"yo"=> "Yoruba",
|
||||
"zu_ZA"=> "Zulu (South Africa)",
|
||||
"zu"=> "Zulu"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function simple()
|
||||
{
|
||||
$response = array();
|
||||
foreach (static::all() as $key => $value) {
|
||||
if (!strpos($key, '_') > 0) {
|
||||
$response[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user