-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#13 - order status update #35
Changes from 11 commits
e56159e
602536b
c9b60a1
64a8102
d2a0603
c6a462c
e0c6ecb
fc2d94e
2c53411
2795294
b291143
74b7bca
e47fb90
0a6fd49
f636e18
78de538
dbe45b0
515a865
80b0dd5
10277da
f1c99d1
3de5561
268bef1
f25bdb9
30a21e5
bc995fe
584a970
30eb861
f72e6f7
f971642
7e215b8
4d2c607
cbf206c
12f5710
23e3324
c917770
0e3dcd0
e56453f
f7a67f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Order | ||
|
||
## Access | ||
|
||
Accessing order operation can be done from the store. | ||
|
||
```php | ||
<?php | ||
$orderApi = $session->getMainStore()->getOrderApi(); | ||
``` | ||
|
||
## Operations | ||
|
||
From order API you can then access all available operation : | ||
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$orderApi | ||
->newOperations() | ||
->accept('ref3', 'amazon') | ||
->refuse('ref4', 'amazon') | ||
->ship('ref5', 'amazon') | ||
->cancel('ref1', 'amazon') | ||
->execute(); | ||
``` | ||
|
||
### Accept | ||
|
||
The accept operation accept 3 parameters : | ||
1. [mandatory] `$reference` : Order reference (eg: 'reference1') | ||
2. [mandatory] `$channelName` : The channel where the order is from (eg: 'amazon') | ||
3. [optional] `$reason` : The reason of the acceptance (eq: 'Why we accept the order') | ||
|
||
Example : | ||
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$orderApi | ||
->newOperations() | ||
->accept('ref1', 'amazon') | ||
->accept('ref2', 'amazon', 'Why we accept it') | ||
->execute(); | ||
``` | ||
|
||
### Cancel | ||
|
||
The cancel operation accept 3 parameters : | ||
1. [mandatory] `$reference` : Order reference (eg: 'reference1') | ||
2. [mandatory] `$channelName` : The channel where the order is from (eg: 'amazon') | ||
3. [optional] `$reason` : The reason of the cancelling (eq: 'Why we cancel the order') | ||
|
||
Example : | ||
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$orderApi | ||
->newOperations() | ||
->cancel('ref1', 'amazon') | ||
->cancel('ref2', 'amazon', 'Why we accept it') | ||
->execute(); | ||
``` | ||
|
||
### Refuse | ||
|
||
The refuse operation accept 3 parameters : | ||
1. [mandatory] `$reference` : Order reference (eg: 'reference1') | ||
2. [mandatory] `$channelName` : The channel where the order is from (eg: 'amazon') | ||
3. [optional] `$refund` : Item references to refund (eq: `['itemref1', 'itemref2']`) | ||
|
||
Example : | ||
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$orderApi | ||
->newOperations() | ||
->refuse('ref1', 'amazon') | ||
->refuse('ref2', 'amazon', ['itemref1', 'itemref2']) | ||
->execute(); | ||
``` | ||
|
||
### Ship | ||
|
||
The ship operation accept 3 parameters : | ||
1. [mandatory] `$reference` : Order reference (eg: 'reference1') | ||
2. [mandatory] `$channelName` : The channel where the order is from (eg: 'amazon') | ||
3. [optional] `$carrier` : The carrier name used for the shipment (eq: 'ups') | ||
3. [optional] `$trackingNumber` : Tracking number (eq: '01234598abcdef') | ||
3. [optional] `$trackingLink` : Tracking link (eq: 'http://tracking.url/') | ||
|
||
Example : | ||
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$orderApi | ||
->newOperations() | ||
->ship('ref1', 'amazon') | ||
->ship('ref2', 'amazon', 'ups', '123456789abcdefg', 'http://tracking.url/') | ||
->execute(); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace ShoppingFeed\Sdk\Api\Order; | ||
|
||
use ShoppingFeed\Sdk\Resource\AbstractCollection; | ||
|
||
class OrderCollection extends AbstractCollection | ||
{ | ||
protected $resourceClass = OrderResource::class; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
namespace ShoppingFeed\Sdk\Api\Order; | ||
|
||
use ShoppingFeed\Sdk\Api\Order as ApiOrder; | ||
use ShoppingFeed\Sdk\Order\OrderOperation; | ||
use ShoppingFeed\Sdk\Resource\AbstractDomainResource; | ||
|
||
/** | ||
* @method ApiOrder\OrderResource[] getIterator() | ||
* @method ApiOrder\OrderResource[] getAll($page = 1, $limit = 100) | ||
*/ | ||
class OrderDomain extends AbstractDomainResource | ||
{ | ||
/** | ||
* @var OrderOperation | ||
*/ | ||
private $orderOperations; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $resourceClass = ApiOrder\OrderResource::class; | ||
|
||
/** | ||
* Init new order operation queue | ||
* | ||
* @return OrderDomain | ||
*/ | ||
public function newOperations($orderOperation = null) | ||
{ | ||
$this->orderOperations = $orderOperation; | ||
if (! $this->orderOperations) { | ||
$this->orderOperations = new OrderOperation(); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Notify market place of order acceptance | ||
* | ||
* @param string $reference Order reference | ||
* @param string $channelName Channel to notify | ||
* @param string $reason Optional reason of acceptance | ||
* | ||
* @return OrderDomain | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function accept($reference, $channelName, $reason = '') | ||
{ | ||
$this->orderOperations->addOperation( | ||
$reference, | ||
$channelName, | ||
OrderOperation::TYPE_ACCEPT, | ||
compact('reason') | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Notify market place of order cancellation | ||
* | ||
* @param string $reference Order reference | ||
* @param string $channelName Channel to notify | ||
* @param string $reason Optional reason of cancellation | ||
* | ||
* @return OrderDomain | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function cancel($reference, $channelName, $reason = '') | ||
{ | ||
$this->orderOperations->addOperation( | ||
$reference, | ||
$channelName, | ||
OrderOperation::TYPE_CANCEL, | ||
compact('reason') | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Notify market place of order shipment sent | ||
* | ||
* @param string $reference Order reference | ||
* @param string $channelName Channel to notify | ||
* @param string $carrier Optional carrier name | ||
* @param string $trackingNumber Optional tracking number | ||
* @param string $trackingLink Optional tracking link | ||
* | ||
* @return OrderDomain | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function ship($reference, $channelName, $carrier = '', $trackingNumber = '', $trackingLink = '') | ||
{ | ||
$this->orderOperations->addOperation( | ||
$reference, | ||
$channelName, | ||
OrderOperation::TYPE_SHIP, | ||
compact('carrier', 'trackingNumber', 'trackingLink') | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Notify market place of order refusal | ||
* | ||
* @param string $reference Order reference | ||
* @param string $channelName Channel to notify | ||
* @param array $refund Order item reference that will be refunded | ||
* | ||
* @return OrderDomain | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function refuse($reference, $channelName, $refund = []) | ||
{ | ||
$this->orderOperations->addOperation( | ||
$reference, | ||
$channelName, | ||
OrderOperation::TYPE_REFUSE, | ||
compact('refund') | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Execute order operations | ||
* | ||
* @return mixed|OrderCollection | ||
*/ | ||
public function execute() | ||
{ | ||
return $this->orderOperations->execute($this->link); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,105 @@ | ||||||||||||||||||
<?php | ||||||||||||||||||
namespace ShoppingFeed\Sdk\Api\Order; | ||||||||||||||||||
|
||||||||||||||||||
use ShoppingFeed\Sdk\Resource\AbstractResource; | ||||||||||||||||||
|
||||||||||||||||||
class OrderResource extends AbstractResource | ||||||||||||||||||
{ | ||||||||||||||||||
/** | ||||||||||||||||||
* @return int | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getId() | ||||||||||||||||||
{ | ||||||||||||||||||
return (int) $this->getProperty('id'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return string | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getReference() | ||||||||||||||||||
{ | ||||||||||||||||||
return (string) $this->getProperty('reference'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return null|string | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getStoreReference() | ||||||||||||||||||
{ | ||||||||||||||||||
return $this->getProperty('storeReference'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return string | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getStatus() | ||||||||||||||||||
{ | ||||||||||||||||||
return (string) $this->getProperty('status'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return false|\DateTimeImmutable | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getAcknowledgedAt() | ||||||||||||||||||
{ | ||||||||||||||||||
$dateValue = $this->getProperty('acknowledgedAt'); | ||||||||||||||||||
if (false === $dateValue) { | ||||||||||||||||||
return false; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
return date_create_immutable(is_null($dateValue) ? 'now' : $dateValue); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return false|\DateTimeImmutable | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getUpdateddAt() | ||||||||||||||||||
{ | ||||||||||||||||||
$dateValue = $this->getProperty('updatedAt'); | ||||||||||||||||||
if (false === $dateValue) { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getProperty ne retourne jamais php-sdk/src/Hal/HalResource.php Lines 75 to 82 in 50150d4
|
||||||||||||||||||
return false; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ddattee null|\DateTimeImmutable, on évite de retourner deux types différents. ça nous permet également de migrer vers php7 avec le support des types de retour |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
return date_create_immutable(is_null($dateValue) ? 'now' : $dateValue); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return \DateTimeImmutable | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getCreatedAt() | ||||||||||||||||||
{ | ||||||||||||||||||
return date_create_immutable($this->getProperty('createdAt')); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return array | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getShippingAddress() | ||||||||||||||||||
{ | ||||||||||||||||||
return $this->getProperty('shippingAddress'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return array | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getBillingAddress() | ||||||||||||||||||
{ | ||||||||||||||||||
return $this->getProperty('billingAddress'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return array | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getPaymentInformation() | ||||||||||||||||||
{ | ||||||||||||||||||
return $this->getProperty('payment'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @return array | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getShipment() | ||||||||||||||||||
{ | ||||||||||||||||||
return $this->getProperty('shipment'); | ||||||||||||||||||
} | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comme discuté, maintenir l'état de orderOperations dans cette classe expose à des effets de bord sur d'éventuels calls consécutifs