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

Add a redirection function 301 or 302 on Category page #35608

Merged
merged 15 commits into from
Mar 27, 2024

Conversation

M0rgan01
Copy link
Contributor

@M0rgan01 M0rgan01 commented Mar 11, 2024

Questions Answers
Branch? develop
Description? Add a redirection function 301 or 302 on Category page
Type? improvement
Category? BO
BC breaks? yes
Deprecations? no
How to test? see #35500
UI Tests https://github.com/M0rgan01/ga.tests.ui.pr/actions/runs/8293387271 https://github.com/florine2623/testing_pr/actions/runs/8449640186
Fixed issue or discussion? Fixes #35500
Related PRs autoupgrade
Sponsor company -

BC breaks:

  • Move PrestaShop\PrestaShop\Adapter\Product\Options\RedirectTargetProvider -> PrestaShop\PrestaShop\Adapter\SEO\RedirectTargetProvider
  • Move PrestaShop\PrestaShop\Core\Domain\Product\QueryResult\ProductRedirectTarget -> PrestaShop\PrestaShop\Core\Domain\QueryResult\RedirectTargetInformation

@prestonBot prestonBot added develop Branch Improvement Type: Improvement labels Mar 11, 2024
@M0rgan01 M0rgan01 added this to the 9.0.0 milestone Mar 11, 2024
@M0rgan01 M0rgan01 force-pushed the 35500 branch 8 times, most recently from fd82ad9 to ae3a68c Compare March 13, 2024 08:25
@PrestaShop PrestaShop deleted a comment from prestonBot Mar 14, 2024
@M0rgan01 M0rgan01 force-pushed the 35500 branch 6 times, most recently from c9428df to 6bbabbe Compare March 15, 2024 08:29
@M0rgan01 M0rgan01 marked this pull request as ready for review March 15, 2024 08:39
@M0rgan01 M0rgan01 requested a review from a team as a code owner March 15, 2024 08:39
@M0rgan01 M0rgan01 force-pushed the 35500 branch 5 times, most recently from e2e07be to 15130a0 Compare March 15, 2024 14:31
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

Thanks @M0rgan01

just a few comments, 7 for 46 files is a decent score 😅

// Target only inputs present in the redirect target row
this.$redirectTargetRow = this.$redirectTargetInput.closest(CategoryMap.redirectOption.groupSelector);

if (this.$redirectTypeInput.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (this.$redirectTypeInput.length) {
if (this.$redirectTargetInput.length) {

It's the target that needs to be checked no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch :)

Copy link
Contributor

Choose a reason for hiding this comment

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

If the purpose is to make this service more generic to work for both product and category (and maybe some other domain later), then it should be moved into a common namespace, although I'm not sure which one Maybe PrestaShop\PrestaShop\Adapter\SEO

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change though, it's ok but you should update the PR description

$this->notFound = true;
if (!$this->category->id_type_redirected) {
if (in_array($this->category->redirect_type, [RedirectType::TYPE_CATEGORY_PERMANENT, RedirectType::TYPE_CATEGORY_TEMPORARY])) {
$this->category->id_type_redirected = $this->category->id_category_default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful I wouldn't trust this field, it is never written/read It has not link to the DB and no domain logic behind (no default category is assigned to a category) I don't know its purpose but I'm not sure it is what you are looking for

In the form we stated that empty value is equivalent to the root category, so I think you need to fetch the root category another way, I don't know if it's in a configuration or if you need to do an SQL request to fetch it though

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can use Category::getRootCategory()->id

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative I just though about would be to redirect to the parent when the value is left empty, but that's a product decision

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The parent category could be disabled as well. Is it going to redirect to the parent until a parent category is available ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the getRootCategory, which works.

For $this->category->id_type_redirected = $this->category->id_category_default;, this is code taken from the Product controller, so the remark also applies to the product side

@M0rgan01 M0rgan01 removed the Waiting for author Status: action required, waiting for author feedback label Mar 20, 2024
@Hlavtox
Copy link
Contributor

Hlavtox commented Mar 20, 2024

@MatShir Yeah, I just wanted to add the different word... You are on a category edit screen, sounds a bit better.

@M0rgan01
Copy link
Contributor Author

I corrected it, thank you @florine2623. For point 6, it is the HTTP code of the console which will show you the difference, and for me it is good.

jolelievre
jolelievre previously approved these changes Mar 21, 2024
tleon
tleon previously approved these changes Mar 25, 2024
@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Mar 25, 2024
boherm
boherm previously approved these changes Mar 25, 2024
@florine2623 florine2623 self-assigned this Mar 27, 2024
@M0rgan01 M0rgan01 closed this Mar 27, 2024
@M0rgan01 M0rgan01 reopened this Mar 27, 2024
Copy link
Contributor

@florine2623 florine2623 left a comment

Choose a reason for hiding this comment

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

Hello @M0rgan01 ,

Some comments on this PR :)

BUG 1 ✅
BUG 2 ✅
BUG 3 ✅

BUG 3 bis ❌

For default category edition, the value is "- No redirection (410)"

We have 404 instead of 410.

BUG 3 ter ❌

The default value is “Permanent redirection to a category (301)”

When I create a new category, the Redirection when offline should be 301 by default, but it is 302.

BUG 4 ✅
BUG 5 ✅

BUG 6 ✅

For 404 & 410
Screenshot 2024-03-27 at 12 05 36

BUG 7 ✅

Waiting for your feedback :)
Thanks!

@florine2623 florine2623 removed the Waiting for QA Status: action required, waiting for test feedback label Mar 27, 2024
@M0rgan01 M0rgan01 dismissed stale reviews from boherm, tleon, and jolelievre via 0a3d00b March 27, 2024 13:48
@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Mar 27, 2024
Copy link
Contributor

@florine2623 florine2623 left a comment

Choose a reason for hiding this comment

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

All bugs are now fixed :)

LGTM @M0rgan01 !

It is QA ✅

@florine2623 florine2623 added QA ✔️ Status: check done, code approved and removed Waiting for QA Status: action required, waiting for test feedback labels Mar 27, 2024
@M0rgan01 M0rgan01 merged commit 5c1e6f6 into PrestaShop:develop Mar 27, 2024
35 checks passed
@kpodemski kpodemski added the Key feature Notable feature to be highlighted label Mar 27, 2024
@kpodemski kpodemski added Documentation ✔️ Developer documentation is up-to-date and removed Needs autoupgrade PR labels Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC break Type: Introduces a backwards-incompatible break develop Branch Documentation ✔️ Developer documentation is up-to-date Improvement Type: Improvement Key feature Notable feature to be highlighted QA ✔️ Status: check done, code approved
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add a redirection function 301 or 302 on Category page