Skip to content
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

Merged
merged 39 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e56159e
#12 - Order - adding main API classes
May 7, 2018
602536b
#13 - Order - adding status operation api calls
May 14, 2018
c9b60a1
#13 - Order - generalizing grouping of bulk operations
May 14, 2018
64a8102
#13 - Order - adding unit test
May 14, 2018
d2a0603
#13 - Composer - checking phpunit before phpcs for it is more important
May 14, 2018
c6a462c
#13 - updating bulk operation unit test
May 14, 2018
e0c6ecb
#13 - Doc - updating doc after renaming method
May 14, 2018
fc2d94e
#13 - Store - better naming of sub-api access
May 18, 2018
2c53411
#13 - Order - adding propererties retreival to order resource
May 18, 2018
2795294
#13 - UT - adding ut for order resource and updating store's
May 18, 2018
b291143
#13 - Order - updating ut to pass php 7+ tests
May 18, 2018
74b7bca
#13 - Order - extracting order operation from domain
May 22, 2018
e47fb90
#13 - Order - updating ut
May 22, 2018
0a6fd49
#13 - Order - returning null when false date to avoid multiple type r…
May 22, 2018
f636e18
#13 - Order - throw sdk local exception instead of a generic one
May 22, 2018
78de538
#13 - Order - updating ut
May 22, 2018
dbe45b0
#13 - cleaning phpunit file
May 22, 2018
515a865
#13 - removing newOperations method
May 28, 2018
80b0dd5
#13 - code style
May 28, 2018
10277da
#16 - adding operation acknowledge and unacknowledge
May 16, 2018
f1c99d1
#16 - updating to match last modification on order status update
May 28, 2018
3de5561
#16 - updating doc for un/acknowledge
May 28, 2018
268bef1
#13 - renaming operation filtering on send
May 28, 2018
f25bdb9
#13 - adding ticket resource to materialize return of operation API
May 28, 2018
30a21e5
#13 - removing unnecessary check
May 28, 2018
bc995fe
#13 - adding ticket description on order operation doc
May 28, 2018
584a970
#13 - doc orth
May 28, 2018
30eb861
#13 - fixing test for php7
May 28, 2018
f72e6f7
Inventory - roll back on out of scope modification
May 28, 2018
f971642
#13 - ut renaming var
May 28, 2018
7e215b8
#38 - adding ticket resource and collection basics
May 28, 2018
4d2c607
#13 - var name
May 28, 2018
cbf206c
#13 - adding ticket collection specific to order workflow
May 29, 2018
12f5710
#13 - moving execute back to domain object
May 31, 2018
23e3324
#13 - fixing ut
May 31, 2018
c917770
#13 - moving OrderOperation into API
May 31, 2018
0e3dcd0
#13 - cleanup exception declaration
Jun 1, 2018
e56453f
#18 - fix doc, changing access type, moving ticketReference in constr…
Jun 4, 2018
f7a67f9
#18 - fixing ut
Jun 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ foreach ($stores as $store) {
### SDK resources documentation

- [Inventory management](docs/catalog.md)
- [Order management](docs/order.md)


### Generates XML compliant feed for import
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"scripts": {
"test": [
"@php vendor/bin/phpcs --colors --report=full --standard=resources/phpcs/ruleset.xml --report-checkstyle=build/phpcs/phpcs.xml --report-emacs=build/phpcs/phpcs.log --extensions=php -p src",
"@php vendor/bin/phpunit --configuration=phpunit.xml --coverage-html=build/phpunit/coverage/"
"@php vendor/bin/phpunit --configuration=phpunit.xml --coverage-html=build/phpunit/coverage/",
"@php vendor/bin/phpcs --colors --report=full --standard=resources/phpcs/ruleset.xml --report-checkstyle=build/phpcs/phpcs.xml --report-emacs=build/phpcs/phpcs.log --extensions=php -p src"
]
},
"scripts-descriptions": {
Expand Down
2 changes: 1 addition & 1 deletion docs/inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Accessing to the inventory API can be done from store resource

```php
<?php
$inventoryApi = $session->getMainStore()->getInventory();
$inventoryApi = $session->getMainStore()->getInventoryApi();
```

Find a inventory item by product's reference (sku):
Expand Down
99 changes: 99 additions & 0 deletions docs/order.md
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();
```
9 changes: 9 additions & 0 deletions src/Api/Order/OrderCollection.php
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;
}
142 changes: 142 additions & 0 deletions src/Api/Order/OrderDomain.php
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();
Copy link
Contributor

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

}

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);
}
}
105 changes: 105 additions & 0 deletions src/Api/Order/OrderResource.php
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) {
Copy link
Contributor

@ronan-gloo ronan-gloo May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getProperty ne retourne jamais FALSE, donc se référer à la doc API pour les valeurs non existantes :

public function getProperty($name, $default = null)
{
if (isset($this->properties[$name])) {
return $this->properties[$name];
}
return $default;
}

return false;
Copy link
Contributor

Choose a reason for hiding this comment

The 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');
}
}
Loading