Skip to content

Commit

Permalink
Accept draft orders with line item props (#12)
Browse files Browse the repository at this point in the history
- Draft orders with line item props or note attributes were being
refused with error note_attributes:expected Hash to be a Array
- It seems the draft order API expects line item properties and note attributes
to be wrapped in an array:
https://help.shopify.com/api/reference/draftorder#note-attributes-property
  • Loading branch information
walrusk authored and jerairrest committed Sep 28, 2017
1 parent 5fd88d1 commit f540a06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Services/DraftOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public function createDraftOrderFromCart(CartModel $cart)

$draftOrderModel->setLineItems($draftOrderLineItems);
$draftOrderModel->setNote($cart->getNote());
$draftOrderModel->setNoteAttributes($cart->getAttributes());

$cartAttributes = $cart->getAttributes();
if (!empty($cartAttributes)) {
$draftOrderModel->setNoteAttributes([$cartAttributes]);
}

return $draftOrderModel;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Services/DraftOrderLineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function createDraftOrderLineItemFromCartItem(CartItem $cartItem)
}
}

$lineItemProperties = $draftOrderLineItem->getProperties();
if (!empty($lineItemProperties)) {
$draftOrderLineItem->setProperties([$lineItemProperties]);
}

return $draftOrderLineItem;
}

Expand Down

0 comments on commit f540a06

Please sign in to comment.