-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Create gtin and replace ean13 usages #35697
Conversation
6f556ad
to
243236b
Compare
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 see too many BC breaks here. You should / must not rename any method nor arguments.
* | ||
* @return bool | ||
*/ | ||
public static function isGtin($gtin): bool |
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 should construct the value object and the value object should do the validation.
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 don't think I should change the way this value object is made. It is supposed to be a copy of the Ean13 Value Object but validated on a 14 lenght.
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 is legacy code, we never introduced the VO in this Validation class I don't see why this should change now
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 is legacy code,
It maybe is a legacy class, but it is new code, a new method and since you introduced value objects for this, you better use them to avoid copy pasting.
Also, there's one golden rule, the legacy can call the new code, but not the opposite., so it is fine here. You already do this in the email validation
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.
The email is kind of an exception compared to all other validations because it's not a simple regexp But I get your argument, although I don't think we should construct the VO here because it doesn't have the same signature at all (it throws an exception not return a boolean)
But to factorize the regexp at least I guess here we can rely on the one from the VO
@@ -66,22 +66,22 @@ class CombinationDetails | |||
private $impactOnWeight; | |||
|
|||
/** | |||
* @param string $ean13 | |||
* @param string $gtin comment here explain rename |
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.
👀
*/ | ||
public function getEan13(): ?Ean13 | ||
public function getEan13(): ?Gtin |
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.
changing return type is a bc break
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.
Well this contains BC breaks I guess.
* @param string $isbn | ||
* @param string $mpn | ||
* @param string $reference | ||
* @param string $upc | ||
* @param DecimalNumber $impactOnWeight | ||
*/ | ||
public function __construct( | ||
string $ean13, | ||
string $gtin, |
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 is also a BC break, with PHP8 you can have named arguments, therefore renaming arguments is a BC.
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 is not part of our backward compatibility promise so far https://github.com/PrestaShop/ADR/blob/master/0017-backward-compatibility-promise.md
But you're right we should probably update the ADR for the V9
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.
The BC is acceptable here in favor of the consistency, but it should be detailed in the PR description for future doc update
f218c17
to
93ae1a4
Compare
@@ -1340,7 +1340,7 @@ CREATE TABLE `PREFIX_order_detail` ( | |||
`reduction_amount_tax_excl` DECIMAL(20, 6) NOT NULL DEFAULT '0.000000', | |||
`group_reduction` DECIMAL(5, 2) NOT NULL DEFAULT '0.00', | |||
`product_quantity_discount` decimal(20, 6) NOT NULL DEFAULT '0.000000', | |||
`product_ean13` varchar(13) DEFAULT NULL, | |||
`product_ean13` varchar(20) DEFAULT NULL, |
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.
@tleon why 20 and not 14?
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.
That's a good question we choose to use 20 because even the Gtin is evolving length wise. It use to be 13 now is 14 and could be bigger in the future. I guess the Gtin gets longer as time passes and the uniq combination of barcodes are reached.
93ae1a4
to
bd1509e
Compare
Renaming parameter is ok, it's not part of our backward compatibility promise And even if it was this is a major so we're allowed to introduce breaking changes, the consistency prevails in this case
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 @tleon
Just two little comment (one optional)
* | ||
* @return bool | ||
*/ | ||
public static function isGtin($gtin): bool |
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.
The email is kind of an exception compared to all other validations because it's not a simple regexp But I get your argument, although I don't think we should construct the VO here because it doesn't have the same signature at all (it throws an exception not return a boolean)
But to factorize the regexp at least I guess here we can rely on the one from the VO
* @param string $isbn | ||
* @param string $mpn | ||
* @param string $reference | ||
* @param string $upc | ||
* @param DecimalNumber $impactOnWeight | ||
*/ | ||
public function __construct( | ||
string $ean13, | ||
string $gtin, |
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.
The BC is acceptable here in favor of the consistency, but it should be detailed in the PR description for future doc update
@@ -138,7 +138,7 @@ private function fillCommand(UpdateCombinationCommand $command, array $dataRows) | |||
} | |||
// References | |||
if (isset($dataRows['ean13'])) { | |||
$command->setEan13($dataRows['ean13']); | |||
$command->setGtin($dataRows['ean13']); |
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.
Not blocking, but it would have been nice if e update the behat feature scenarios to update this column name If you don't think it's relevant it's fine as well
bd1509e
to
83157f5
Compare
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.
Hello @tleon ,
Saving 14 characters in the field GTIN (EAN, JA, ITF or UCC code) doesn't work :/
13 char OK = 1234567890123
14 char NOK : 12345678901234
Screen.Recording.2024-04-02.at.11.38.54.mov
Could you check ?
Thanks
I checked on my side and it is working. Did you reinstall your shop before testing ? ( since the db field for ean has been modified from 13 to 20 length ). You need a fresh install |
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.
Hello @tleon ,
My mistake. Tested again.
The field allows me to save up to 14 characters.
There's the right error message is my field surpasses the max number of characters.
LGTM ✅
Thanks!
@florine2623 @tleon Why is the error sentence doubled? |
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.
Quick question above
@Hlavtox We've seen this problem before in 2020 -> #28877 It was a nightmare problem where we had to try multiple implementations before finding the right problem. See PRs #29584 and #29959 and #31666 and #31900 I'm quite sure that this plural string bug is unrelated to the code written by @tleon 😉 so I prefer we merge this PR (whose content is valid) and we create another issue for this plural string issue. What I am saying is: the problem you noticed has been spotted while working on that PR but it does not mark this PR as invalid. I'm sure of that because I worked on that bug in 2020 😄 . Issue to be created soon after the merge 😉 stay tuned |
Issue created #35813 |
BC breaks :