Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
feat(OrderFromCart): support state, orderState, shipmentState at Orde…
Browse files Browse the repository at this point in the history
…rCreateFromCart

closes #412, #417
  • Loading branch information
nikossvnk committed Jul 23, 2018
1 parent eba565c commit 5fd4375
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
73 changes: 73 additions & 0 deletions src/Core/Request/Orders/OrderCreateFromCartRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Commercetools\Core\Request\Orders;

use Commercetools\Core\Model\State\StateReference;
use Psr\Http\Message\ResponseInterface;
use Commercetools\Core\Client\HttpMethod;
use Commercetools\Core\Client\HttpRequestInterface;
Expand All @@ -29,11 +30,17 @@ class OrderCreateFromCartRequest extends AbstractApiRequest
const VERSION = 'version';
const ORDER_NUMBER = 'orderNumber';
const PAYMENT_STATE = 'paymentState';
const ORDER_STATE = 'orderState';
const STATE = 'state';
const SHIPMENT_STATE = 'shipmentState';

protected $cartId;
protected $version;
protected $orderNumber;
protected $paymentState;
protected $orderState;
protected $state;
protected $shipmentState;

protected $resultClass = Order::class;

Expand Down Expand Up @@ -113,6 +120,63 @@ public function setPaymentState($paymentState)
return $this;
}

/**
* @return mixed
*/
public function getOrderState()
{
return $this->orderState;
}

/**
* @param $orderState
* @return $this
*/
public function setOrderState($orderState)
{
$this->orderState = $orderState;

return $this;
}

/**
* @return mixed
*/
public function getState()
{
return $this->state;
}

/**
* @param StateReference $state
* @return $this
*/
public function setState(StateReference $state)
{
$this->state = $state;

return $this;
}

/**
* @return mixed
*/
public function getShipmentState()
{
return $this->shipmentState;
}

/**
* @param $shipmentState
* @return $this
*/
public function setShipmentState($shipmentState)
{
$this->shipmentState = $shipmentState;

return $this;
}

/**
* @param string $cartId
* @param int $version
Expand Down Expand Up @@ -161,6 +225,15 @@ public function httpRequest()
if (!is_null($this->orderNumber)) {
$payload[static::ORDER_NUMBER] = $this->getOrderNumber();
}
if (!is_null($this->orderState)) {
$payload[static::ORDER_STATE] = $this->getOrderState();
}
if (!is_null($this->state)) {
$payload[static::STATE] = $this->getState();
}
if (!is_null($this->shipmentState)) {
$payload[static::SHIPMENT_STATE] = $this->getShipmentState();
}
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
}
}
15 changes: 13 additions & 2 deletions tests/unit/Request/Orders/OrderCreateFromCartRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Commercetools\Core\Client\HttpMethod;
use Commercetools\Core\Model\Order\Order;
use Commercetools\Core\Model\State\StateReference;
use Commercetools\Core\RequestTestCase;
use Commercetools\Core\Response\ResourceResponse;

Expand Down Expand Up @@ -64,16 +65,26 @@ public function testHttpRequestObject()
* @var OrderCreateFromCartRequest $request
*/
$request = OrderCreateFromCartRequest::ofCartIdAndVersion('12345', 1);
$stateReference = StateReference::ofId('123');
$request->setOrderNumber('12345678')
->setPaymentState('paid');
->setPaymentState('paid')
->setOrderState('Confirmed')
->setShipmentState('Ready')
->setState($stateReference);

$httpRequest = $request->httpRequest();

$expectedResult = [
'id' => '12345',
'version' => 1,
'orderNumber' => '12345678',
'paymentState' => 'paid'
'paymentState' => 'paid',
'orderState' => 'Confirmed',
'shipmentState' => 'Ready',
'state' => [
'typeId' => 'state',
'id' => '123'
]
];
$this->assertJsonStringEqualsJsonString(json_encode($expectedResult), (string)$httpRequest->getBody());
}
Expand Down

0 comments on commit 5fd4375

Please # to comment.