-
Notifications
You must be signed in to change notification settings - Fork 82
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
added the export for orders #107
added the export for orders #107
Conversation
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.
Thanks for this PR, seems to be very useful. I added some comments about minor changes, that would be cool.
- "@sylius.exporters_transformer_pool" | ||
tags: | ||
- { name: sylius.exporter, type: sylius.order, format: csv } | ||
|
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.
Here is a blank line missing at the end of the file
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.
For me at row 30 I have a blank line?
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.
- "@sylius.exporters_transformer_pool" | ||
tags: | ||
- { name: sylius.exporter, type: sylius.order, format: xlsx } | ||
|
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.
same here.
parent::init($idsToExport); | ||
|
||
/** @var OrderInterface $resource */ | ||
foreach ($this->resources as $resource) { |
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.
could you refactor this foreach a bit, so it gets a bit smaller? I would recommend to move the contents of the different if-conditionals to private methods, that would make the code of this init-method a bit clearer to understand.
$items = []; | ||
|
||
/** @var OrderItemInterface $orderItem */ | ||
foreach ($resource->getItems() as $orderItem) { |
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.
Also the following both foreach-loops could be relatively easy extracted to a private-method like 'addOrderItemInformation' or something like that, I think.
* @param PropertyAccessorInterface $propertyAccessor | ||
* @param EntityManagerInterface $entityManager | ||
*/ | ||
public function __construct( |
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.
this looks redundant and covered by the parent constructor
Thanks for the reviews and help, I did the requested changes.. its open for review again :) |
/** | ||
* @param OrderInterface $resource | ||
*/ | ||
private function addCustomerData(OrderInterface $resource) |
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.
bit nitpicking, but can you add a TypeHint for the retrun-value of all added private Methods?
e.g. private function addCustomerData(OrderInterface $resource): void
We should typeHint as much as we can... :-)
$items[$product->getName()] = 0; | ||
} | ||
|
||
$items[$product->getName()] += $orderItem->getQuantity(); |
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.
How does this with products with the same name but not the same product ID? Basically different product, but the count on the name gets upped.
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.
yeah .. this is risky .. should use something unique for the key
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.
Since I already merged this, I think we should open an issue for that. I have totally overseen this..
if (null !== $shippingAddress) { | ||
$this->addDataForResource($resource, 'Shipping_address', sprintf( | ||
'%s, %s, %s, %s, %s', | ||
$shippingAddress->getFullName() ? $shippingAddress->getFullName() : '', |
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.
Can't we use ??
here?
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.
I am not sure if anything is even needed here .. I assume the return value is either a string or null and then it will just silently get cast to an empty string.
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.
@enesaktay is this something we can make easier to read/use?
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.
@stefandoorn could potentially remove the ternary operators since with row 58 we are already checking if shippingadress exists
other than that i could also put sprintf inside another method since it is used 2 times in this class
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.
Indeed, might be worth trying if we need the operator at all as the methods probably return useful information anyway..
private function addShippingAddressData(OrderInterface $resource): void | ||
{ | ||
$shippingAddress = $resource->getShippingAddress(); | ||
if (null !== $shippingAddress) { |
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.
What about early returns? if (null !== $shippingAddress) { return; }
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.
+1 for return early
I moved some comments to separate issues with cc to @enesaktay. |
#103 had unwanted commits in it so this is the same PR without the unwanted commits