Skip to content

Commit

Permalink
Fix issue syncing orders or carts that are missing addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Aug 23, 2019
1 parent 656592c commit a492a07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [Unreleased] 1.1.9
### Fixed
- Fix error when syncing products without public urls (Fixes #9)
- Fix issue syncing orders or carts that are missing addresses

## 1.1.8 - 2019-08-01
### Fixed
- Fix order sync error when address 2 isn't set (Fixes #7)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ether/mailchimp-commerce",
"description": "Mailchimp integration with Craft Commerce",
"version": "1.1.8",
"version": "1.1.9",
"type": "craft-plugin",
"keywords": [
"mailchimp",
Expand Down
18 changes: 13 additions & 5 deletions src/services/OrdersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ private function _buildOrderData ($orderId)
'last_name' => $order->billingAddress ? $order->billingAddress->lastName : '',
'orders_count' => (int) Order::find()->customer($order->customer)->isCompleted()->count(),
'total_spent' => (float) Order::find()->customer($order->customer)->isCompleted()->sum('[[commerce_orders.totalPaid]]') ?: 0,
'address' => self::_address($order->billingAddress),
],
];

if ($order->billingAddress)
$data['customer']['address'] = self::_address($order->billingAddress);

$cid = (new Query())
->select('cid')
->from('{{%mc_orders_synced}}')
Expand Down Expand Up @@ -281,16 +283,22 @@ private function _buildOrderData ($orderId)

if ($order->isCompleted)
{
$data = array_merge($data, [
$completeData = [
'financial_status' => $order->lastTransaction ? $order->lastTransaction->status : 'paid',
'discount_total' => (float) $order->getAdjustmentsTotalByType('discount'),
'tax_total' => (float) $order->getAdjustmentsTotalByType('tax'),
'shipping_total' => (float) $order->getAdjustmentsTotalByType('shipping'),
'processed_at_foreign' => $order->dateOrdered->format('c'),
'updated_at_foreign' => $order->dateUpdated->format('c'),
'shipping_address' => self::_address($order->shippingAddress),
'billing_address' => self::_address($order->billingAddress),
]);
];

if ($order->shippingAddress)
$completeData['shipping_address'] = self::_address($order->shippingAddress);

if ($order->billingAddress)
$completeData['billing_address'] = self::_address($order->billingAddress);

$data = array_merge($data, $completeData);

if ($order->returnUrl)
$data['order_url'] = UrlHelper::siteUrl($order->returnUrl);
Expand Down

0 comments on commit a492a07

Please sign in to comment.