public function updateOrder(Order $order) { $payload = $order->toPost(); $response = $this->connection->put('/Orders/' . $order->getOrderNumber(), $payload); $body = $response->getBody(); $orderResponse = null; if (!empty($body['ErrorCode'])) { $orderResponse = new ErrorResponse(); $orderResponse->setErrorCode($body['ErrorCode'])->setMessage($body['Message'])->setIsError(true); } else { $orderResponse = new OrderResponse(); $order = new Order(); $order->setOrderNumber($body['OrderNumber'])->setEmailAddress($body['EmailAddress'])->setPurchaseDate($body['PurchaseDate'])->setCreated($body['Created'])->setLastUpdated($body['LastUpdated'])->setTotalItems($body['TotalItems'])->setTotalAmount($body['TotalAmount'])->setTotalWeight($body['TotalWeight'])->setIsActive($body['IsActive']); foreach ($body['OrderItems'] as $item) { $orderItem = new OrderItem(); $orderItem->setOrderItemId($item['OrderItemID'])->setProductId($item['ProductID'])->setOrderNumber($item['OrderNumber'])->setEmailAddress($item['EmailAddress'])->setProductName($item['ProductName'])->setSku($item['SKU'])->setQuantity($item['Quantity'])->setUnitPrice($item['UnitPrice'])->setWeight($item['Weight'])->setStatus($item['Status'])->setTotalAmount($item['TotalAmount'])->setPurchaseDate($item['PurchaseDate'])->setCreated($item['Created'])->setLastUpdated($item['LastUpdated']); $order->getOrderItems()->addOrderItem($orderItem); } $orderResponse->setOrder($order); } return $orderResponse; }
public function testImportMultipleOrders(Connection $connection) { $orders = new OrdersCollection(); $order1 = new Order(); $order1->setEmailAddress("*****@*****.**")->setOrderNumber("jasldkjf")->setPurchaseDate("12/1/2011"); $orderItem1 = new OrderItem(); $orderItem1->setProductName("name")->setSku("1218")->setQuantity("2")->setUnitPrice("3.33")->setWeight("8.1")->setStatus("0"); $order1->getOrderItems()->addOrderItem($orderItem1); $orderItem2 = new OrderItem(); $orderItem2->setProductName("new prod")->setSku("23456")->setQuantity("3")->setUnitPrice("4.33")->setWeight("2.1")->setStatus("0"); $order1->getOrderItems()->addOrderItem($orderItem2); $order2 = new Order(); $order2->setEmailAddress("*****@*****.**")->setOrderNumber("1004")->setPurchaseDate("2011-08-10"); $orderItem3 = new OrderItem(); $orderItem3->setProductName("new_product")->setSku("1235456")->setQuantity("3")->setUnitPrice("3")->setWeight("3")->setStatus("3"); $order2->getOrderItems()->addOrderItem($orderItem3); $orders->addOrder($order1); $orders->addOrder($order2); $ordersResource = new Orders($connection); return $ordersResource->addMultiple($orders); }