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

[Adjustment] Add more details to adjustment and make shipment adjustable #12116

Merged
merged 18 commits into from
Dec 11, 2020

Conversation

GSadee
Copy link
Member

@GSadee GSadee commented Dec 2, 2020

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no?
Deprecations? no
Related tickets
License MIT

This PR is the first step to solve the problem with too little information while generating documents on InvoicingPlugin and RefundPlugin.

I've added also information about shipment tax on order show page in admin panel:

  • example with tax excluded:

image

  • example with tax included:

image

TODO:

  • Add array of details on Adjustment entity

  • Make Shipment entity adjustable

  • Prepare a proper migration to fill details on existing adjustments

  • Prepare a proper migration to add related adjustments to existing shipments

  • Consider adding a note about above migrations in UPGRADE file

@GSadee GSadee added RFC Discussions about potential changes or new features. DX Issues and PRs aimed at improving Developer eXperience. labels Dec 2, 2020
@GSadee GSadee requested a review from a team as a code owner December 2, 2020 12:18
@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Dec 2, 2020
Comment on lines +61 to +64
$adjustment->setDetails([
'shippingMethodCode' => $shippingMethod->getCode(),
'shippingMethodName' => $shippingMethod->getName(),
]);
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought for improvement. What do you think about some factory service, that would be responsible for this array creation? Seems to provide a more easier way to customize its structure.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with the need to freeze data format for details, but external service to handle internal state of model is a bit of anti-pattern. (Something along the lines of anemic domain model)

Model should be able to handle format on it's own, for example like so

$adjustment->setShippingMethodDetails($shippingMethod->getCode(), $shippingMethod->getName());
// Adjustment

public function setShippingMethodDetails(string $shippingMethodCode, string $shippingMethodName): void
{
    $this->details['shippingMethodCode'] = $shippingMethodCode;
    $this->details['shippingMethodName'] = $shippingMethodName;
}

or alternatively as set of value objects.

Comment on lines +83 to +89
[
'shippingMethodCode' => $shippingMethod->getCode(),
'shippingMethodName' => $shippingMethod->getName(),
'taxRateCode' => $taxRate->getCode(),
'taxRateName' => $taxRate->getName(),
'taxRateAmount' => $taxRate->getAmount(),
]
Copy link
Member

Choose a reason for hiding this comment

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

If we would introduce detailed factories, this structure seems like the result of merging two previous factories.

In such aa situation, some recommendation for prefixes could be also a good idea.

Copy link
Member

@diimpp diimpp Feb 25, 2021

Choose a reason for hiding this comment

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

@lchrusciel

Alternative solution,

$adjustment->setDetailsFromValueObjects(
    new ShippingMethodVO($shippingMethod->getCode(), $shippingMethod->getName()),
    new TaxRateVO($taxRate->getCode(), $taxRate->getName(), $taxRate->getAmount())
);

Which will allow to specify new data more easily and offer extension point for developers.

For example, I've implemented payment method charges custom feature before and currently doing country of origin for Tax Rate, which will require new custom fields.

But regardless of this two examples, I'm sure there are whole CS patterns on how to store/retrieve complex data in array field.

Copy link
Member

Choose a reason for hiding this comment

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

for sure, what we've used is far from the ideal pattern, you are correct. We will think about alternatives. Hopefully, this details field will be good enough for now

@@ -49,6 +49,9 @@ class Adjustment implements AdjustmentInterface
/** @var string|null */
protected $originCode;

/** @var array */
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this value cannot be empty due to migration chages

Copy link
Member Author

Choose a reason for hiding this comment

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

As I wrote in the description, there should be probably prepared a proper migration to fill this array for existing adjustments, so it should resolve this problem.

@GSadee GSadee force-pushed the adjustments-details branch 2 times, most recently from c6fd1d7 to 2e3835f Compare December 4, 2020 10:25
@vvasiloi
Copy link
Contributor

vvasiloi commented Dec 4, 2020

Have you guys ever thought that maybe you ask too much from this adjustment and maybe it would be better to split it into separate entities?
Adding a free-form field to store random data isn't going to improve the DX and might even make it worse.
If you are interested I can elaborate more on the issues I see with this approach and suggest others.

@GSadee
Copy link
Member Author

GSadee commented Dec 4, 2020

Have you guys ever thought that maybe you ask too much from this adjustment and maybe it would be better to split it into separate entities?
Adding a free-form field to store random data isn't going to improve the DX and might even make it worse.
If you are interested I can elaborate more on the issues I see with this approach and suggest others.

Hey @vvasiloi! Thank you for sharing your doubts with us. I wanted to propose some simple and non-bc breaks solution for a known problem and I'm of course aware, that it is probably not the best approach in the end. So If you would like to share your suggestions with us, it would be really appreciated 😃

@probot-autolabeler probot-autolabeler bot added the Maintenance CI configurations, READMEs, releases, etc. label Dec 8, 2020
@SirDomin SirDomin changed the title [WIP][PoC][Adjustment] Add more details to adjustment and make shipment adjustable [PoC][Adjustment] Add more details to adjustment and make shipment adjustable Dec 8, 2020
@vvasiloi
Copy link
Contributor

vvasiloi commented Dec 8, 2020

@GSadee Thanks for the answer! Good to know that you also thought about it. I will open a new issue for it when I have the time. Hopefully we can do something about it in 2.0.

@SirDomin SirDomin force-pushed the adjustments-details branch 2 times, most recently from 3727236 to 42164bd Compare December 8, 2020 15:31
UPGRADE-1.9.md Outdated Show resolved Hide resolved
FROM sylius_adjustment adjustment
LEFT JOIN sylius_shipment shipment ON shipment.order_id = adjustment.order_id
LEFT JOIN sylius_shipping_method shipping_method on shipment.method_id = shipping_method.id
LEFT JOIN sylius_tax_rate tax_rate on adjustment.label LIKE CONCAT(tax_rate.name, \'%\')
Copy link
Contributor

Choose a reason for hiding this comment

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

Thats the way to find tax_rate based on adjustment label

Copy link
Member

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

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

Some additional review and manual QA with some data in database would be needed here as well

UPGRADE-1.9.md Outdated Show resolved Hide resolved
UPGRADE-1.9.md Outdated Show resolved Hide resolved
UPGRADE-1.9.md Outdated Show resolved Hide resolved
Co-authored-by: Grzegorz Sadowski <sadowskigp@gmail.com>
@lchrusciel lchrusciel changed the title [PoC][Adjustment] Add more details to adjustment and make shipment adjustable [Adjustment] Add more details to adjustment and make shipment adjustable Dec 11, 2020
@lchrusciel lchrusciel merged commit 62e869b into Sylius:master Dec 11, 2020
@lchrusciel
Copy link
Member

Thank you, Grzegorz! 🥇

lchrusciel added a commit that referenced this pull request Dec 17, 2020
…rti0090)

This PR was merged into the 1.9-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         |  master 
| Bug fix?        | no/yes
| Related tickets | This PR is related to failing build from sylius/standard Sylius/Sylius-Standard#459 and also #12116
| License         | MIT



Commits
-------

85f5b34 update upgrade file after changes with tax adjustment
9b0973a minor fix
lchrusciel added a commit to Sylius/Sylius-Standard that referenced this pull request Dec 17, 2020
This PR was merged into the 1.9-dev branch.

Discussion
----------

fix for changes related to Sylius/Sylius#12116

Commits
-------

2a9868b fix for new adjustment migration
@GSadee GSadee deleted the adjustments-details branch January 8, 2021 11:16
lchrusciel added a commit that referenced this pull request Jan 14, 2021
This PR was merged into the 1.9-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | after #12116 and associated with Sylius/RefundPlugin#242
| License         | MIT


Commits
-------

066364b [Behat] Reproduce error with dirty entity
c849cde [OrderProcessor] Fix clearing tax adjustments
2060b09 [Behat] Add different scenario to cover issue with clearing tax adjustments
lchrusciel added a commit that referenced this pull request Jan 19, 2021
…adee)

This PR was merged into the 1.9-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | yes?
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | after #12116
| License         | MIT

According to Sylius/RefundPlugin#242 (comment)

Commits
-------

60cc71d [Migrations] Use adding SQL instead of query execution
windragon0910 added a commit to windragon0910/symfony_ecom_framework that referenced this pull request Oct 25, 2023
This PR was merged into the 1.9-dev branch.

Discussion
----------

fix for changes related to Sylius/Sylius#12116

Commits
-------

2a9868bf93754fc1c653305e3194d30e338a40a9 fix for new adjustment migration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin AdminBundle related issues and PRs. DX Issues and PRs aimed at improving Developer eXperience. Maintenance CI configurations, READMEs, releases, etc. RFC Discussions about potential changes or new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants