-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/Adjustment.orm.xml
Outdated
Show resolved
Hide resolved
$adjustment->setDetails([ | ||
'shippingMethodCode' => $shippingMethod->getCode(), | ||
'shippingMethodName' => $shippingMethod->getName(), | ||
]); |
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.
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.
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 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.
[ | ||
'shippingMethodCode' => $shippingMethod->getCode(), | ||
'shippingMethodName' => $shippingMethod->getName(), | ||
'taxRateCode' => $taxRate->getCode(), | ||
'taxRateName' => $taxRate->getName(), | ||
'taxRateAmount' => $taxRate->getAmount(), | ||
] |
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.
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.
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.
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.
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 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 */ |
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'm wondering if this value cannot be empty due to migration chages
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.
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.
c6fd1d7
to
2e3835f
Compare
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? |
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 😃 |
2e3835f
to
d79fb74
Compare
16aed39
to
c040f27
Compare
c040f27
to
dc884e9
Compare
@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. |
src/Sylius/Bundle/CoreBundle/Migrations/Version20201208105207.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/CoreBundle/Migrations/Version20201208105207.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/CoreBundle/Migrations/Version20201208105207.php
Outdated
Show resolved
Hide resolved
3727236
to
42164bd
Compare
src/Sylius/Bundle/CoreBundle/Migrations/Version20201208105207.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/CoreBundle/Migrations/Version20201208105207.php
Outdated
Show resolved
Hide resolved
42164bd
to
522c88f
Compare
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, \'%\') |
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.
Thats the way to find tax_rate based on adjustment label
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.
Some additional review and manual QA with some data in database would be needed here as well
Co-authored-by: Grzegorz Sadowski <[email protected]>
Thank you, Grzegorz! 🥇 |
…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
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
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
…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
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
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:
TODO:
Add array of details on
Adjustment
entityMake
Shipment
entity adjustablePrepare 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