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

Conversation

ddattee
Copy link
Contributor

@ddattee ddattee commented May 14, 2018

Adding accept, refuse, ship, and cancel order operations call and resolve #13 and resolve #16 .

@ddattee ddattee added the enhancement New feature or request label May 14, 2018
@ddattee ddattee added this to the v0.2 milestone May 14, 2018
@ddattee ddattee self-assigned this May 14, 2018
{
$dateValue = $this->getProperty('updatedAt');
if (false === $dateValue) {
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

public function addOperation($reference, $channelName, $type, $data = [])
{
if (! in_array($type, $this->allowedOperationTypes)) {
throw new \Exception(sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

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

Pas d'exception du scope global, sinon le client ne pourra pas cibler précisément les exceptions du SDK à plus haut niveau dans son code.

}
},
'group1'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Une règle des tests unitaire est de les garder le plus simple possible, et donc éviter les block.
Essaie aussi d'expliquer tes intentions (dans le nom du test case, et avec des commentaires lors des assertions), car à la lecture, ce n'est pas tout de suite évident de savoir quel comportement est vérifié ici

{
$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 OrderOperation
*/
public function newOperations()
Copy link
Contributor

Choose a reason for hiding this comment

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

Merci de supprimer ce shortcut (et de mettre la documentation à jour pour être conforme avec ce que l'on a fait sur inventory:

<?php
$op = new OrderOperation();
$api->execute($op);

docs/order.md Outdated
->newOperations()
->ship('ref1', 'amazon')
->ship('ref2', 'amazon', 'ups', '123456789abcdefg', 'http://tracking.url/')
->execute($orderApi->getLink());
Copy link
Contributor

Choose a reason for hiding this comment

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

Quelles est (sont) la (les) valeurs de retour pour chacune des opérations ?

*/
protected function eachBatch(callable $callback)
protected function eachBatch(callable $callback, $groupedBy = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ce n'est pas un "regroupement", mais un filtre (ex du GROUP BY sql)

Copy link
Contributor Author

@ddattee ddattee May 28, 2018

Choose a reason for hiding this comment

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

La il s'agit bien d'un regroupement : on regroupe les requetes par operations car les batch ne peuvent être fait que sur une opération à la fois car on a 1 url par operation.
X batchs pour les cancels, Y batchs pour les accepts...

Copy link
Contributor

Choose a reason for hiding this comment

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

vu ce cette classe, c'est bien un filtre, puisque seulement la clé $groupedBy est exécutée

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok compris

$this->getPoolSize()
);

return new Api\Order\OrderCollection($resources);
Copy link
Contributor

Choose a reason for hiding this comment

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

On ne retourne pas une collection de order, mais des "tickets" puisque ces ops sont async

@ronan-gloo
Copy link
Contributor

ronan-gloo commented May 28, 2018

@ddattee Petite question: Quant est-il de acknowlegde / unacknowlegde ?
Ce sont principalement ces opérations que les plugins ont besoin

{
// Create requests per batch
$requests = [];
foreach ($this->allowedOperationTypes as $type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ton regroupement est fait ici ;)


class UnexpectedTypeException extends \Exception
{

Copy link
Contributor

Choose a reason for hiding this comment

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

space

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;
}

@ddattee
Copy link
Contributor Author

ddattee commented May 28, 2018

@ronan-gloo un/acknowledge operation were on another branch I added them to this PR

docs/order.md Outdated
```php
<?php
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */
$operations = new \ShoppingFeed\Sdk\Order\OrderOperation();
Copy link
Contributor

Choose a reason for hiding this comment

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

UpdateOperation 😄

docs/order.md Outdated
->refuse('ref4', 'amazon')
->ship('ref5', 'amazon')
->cancel('ref3', 'amazon')
->execute($orderApi->getLink());
Copy link
Contributor

Choose a reason for hiding this comment

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

cf commentaire sur inventory #36 (comment)

@ronan-gloo
Copy link
Contributor

@ddattee Operations should be located at AP namespace level, it makes the sdk organisation more predictable and consistent.

@ddattee ddattee force-pushed the order-status-update branch from 3ac8339 to c917770 Compare May 31, 2018 13:52
@ddattee
Copy link
Contributor Author

ddattee commented May 31, 2018

@ronan-gloo done and I updated InventoryUpdate too.

},
null,
[],
$this->getPoolSize()
Copy link
Contributor

Choose a reason for hiding this comment

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

Pour la prochaine implémentation d'opérations sur une resource, faudra réfléchir à factoriser le tout pour éviter la duplication de code ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oui et faciliter le test des closure :)

Copy link
Contributor

@ronan-gloo ronan-gloo left a comment

Choose a reason for hiding this comment

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

Cf commentaires.

Faut assurer checker le coverage sur les classes API, on n'est pas à 100% là ;)

docs/order.md Outdated
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */
$updateOperation = new \ShoppingFeed\Sdk\Api\Order\OrderOperation();
/** @var \ShoppingFeed\Sdk\Api\Order\OrderTicketCollection $ticketCollection */
$ticketCollection = $updateOperation
Copy link
Contributor

Choose a reason for hiding this comment

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

c'est la méthode execute qui retourne $ticketCollection non ?

* @param Request $request
* @param $ticketReferences
*/
public function associateTicketWithReference(
Copy link
Contributor

Choose a reason for hiding this comment

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

Cette méthode ne doit pas faire partir de l'API publique de la classe, faudrait la passer en private

*
* @return OrderTicketCollection
*/
public function setTicketReferences($ticketReferences)
Copy link
Contributor

Choose a reason for hiding this comment

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

Les références devraient être passées à la construction de l'objet, car là on ouvre l'accès aux modifications depuis l'extérieur.

Faudrait aussi caster $ticketReferences en array

*
* @throws Order\Exception\TicketNotFoundException
*/
public function getShippedTicket($reference)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pour toutes les méthodes:

  • Le paramètre $reference devrait être optionnel : dans ce cas, on retourne tous les tickets liés aux opérations "shipped"

  • côté sémantique, le "ticket" est redondant, c'est une collection de tickets ;)

Copy link
Contributor Author

@ddattee ddattee Jun 4, 2018

Choose a reason for hiding this comment

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

@ronan-gloo donc on retourne 2 types de donnée différent en fonction de ce qu'on trouve (1 resource ou un array de resource) ou alors on retourne un array dans tt les cas mais on ne peut plus faire l'enchainement : $ticketCollection->getAccepted('ref3')->getId()

Ok pour la sémantique.

Copy link
Contributor

Choose a reason for hiding this comment

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

En effet.

Je propose que l'on remette tout ça à plus tard, le temps de trancher pour une API consistante.
On est un peu hors scope de toute manière pour le moment, donc on peu se contenter de la collection d'instances de ticket, sans accepteurs particuliers, et on blinde la suite dans une prochaine iteration.

ça te vas comme plan ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

J'ai passé le tout en full array du coup pour que ce soit consistant.
Mais je suis d'accord que la réflexion viendra avec l'API ticket surtout.

@@ -62,13 +62,35 @@ public function getPoolSize()
return $this->poolSize;
}

public function countOperation($groupedBy = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

J'aurais plutôt implémenté \Countable ici. Faut aussi penser au docblock

Copy link
Contributor Author

@ddattee ddattee Jun 4, 2018

Choose a reason for hiding this comment

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

Si je passe par \Countable je ne peux pas passer de filter (incompatible avec la signature de l'interface) je vais juste la renommer en count().
D'autant que l'interface est déjà implémenter au niveau du parent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah oui mal lu, désolé

Descends plutôt ça dans TicketCollection pour le moment, on a rien dans la classe abstraite qui décris une structuration des opérations (ex sur inventory). Quitte à le remonter plus tard si c'est pertinent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ronan-gloo le count() d'operation dans TicketCollection ? pas sur de comprendre la

*
* @return TicketNotFoundException
*/
public static function withOperation($operation)
Copy link
Contributor

Choose a reason for hiding this comment

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

Côté convention, with() sont plutôt méthodes qui clone les instances existantes (PSR http-message par exemple)
Se serait plutôt fromOperation() pour un constructeur nommé

ddattee added 2 commits June 4, 2018 13:16
…ce in constructor, setting $reference as optionnal, better count method, renaming exception method, updating ut
@ddattee ddattee merged commit 7655890 into shoppingflux:develop Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants