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

Fix bug with all shops context in WebService #28537

Merged
merged 1 commit into from Oct 19, 2022

Conversation

Prestaworks
Copy link
Contributor

@Prestaworks Prestaworks commented May 19, 2022

Questions Answers
Branch? develop
Description? In this PR I introduce a new constant _PS_API_IN_USE_ to allow PrestaShop to detect calls to webservice in multistore and avoid redirecting them.
Type? bug fix
Category? WS
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #12412
Related PRs
How to test? Follow instructions in issue report
Possible impacts?

@Prestaworks Prestaworks requested a review from a team as a code owner May 19, 2022 13:49
@prestonBot prestonBot added develop Branch Bug fix Type: Bug fix labels May 19, 2022
@@ -396,7 +396,7 @@ public static function initialize()
Configuration::getMultiShopValues('PS_MEDIA_SERVER_3')
);

if ((!$id_shop && defined('_PS_ADMIN_DIR_')) || Tools::isPHPCLI() || in_array($http_host, $all_media)) {
if ((!$id_shop && defined('_PS_ADMIN_DIR_')) || ('all' === $id_shop && defined('_PS_API_IN_USE_') && _PS_API_IN_USE_) || Tools::isPHPCLI() || in_array($http_host, $all_media)) {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use vars to improve the code readability
Something like :

$isAllShop = 'all' === $id_shop;
$isApiInUse = defined('_PS_API_IN_USE_') && _PS_API_IN_USE_;

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 updated the commit with your suggestions.

make sure value only defined once

Update Shop.php

suggestions from pululuk

Fix for issue 12412
@Progi1984 Progi1984 changed the title Fix for issue 12412 Fix bug with all shops context in WebService May 23, 2022
Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

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

Hello @Prestaworks and thank you for the PR! Apologies for the late review; these last weeks we have been focused on PrestaShop 8 freeze so we're very late in processing contributions.

I improved a bit the PR description 😉

For me the code is valid. But I have one question: because of the bug, today nobody can use the webservice in multistore, right? Then if we merge your PR we remove the bug. But do we know if webservices work with multistore ? 😄 I wonder if we have opened a door but behind the door the stuff is broken

@Prestaworks
Copy link
Contributor Author

it's possible to use in multistore, but when creating a size like "Large" for instance, you can't create it for all shops, only for one specific shop at a time. and that will create multiple entries with different IDs.

Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

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

Thank you for your answer @Prestaworks and my apologies for late answer. I add 'waiting for QA' label so that QA tests this contribution.

@matks matks added Waiting for QA Status: action required, waiting for test feedback and removed Waiting for QA Status: action required, waiting for test feedback labels Sep 29, 2022
@matks
Copy link
Contributor

matks commented Sep 29, 2022

Woups I thought this was the PSWebservice repo (1 approval is enough).

Ping @PrestaShop/committers this PR needs a 2nd approval to move forward :)

@matks matks added the Waiting for QA Status: action required, waiting for test feedback label Sep 29, 2022
@florine2623 florine2623 self-assigned this Oct 18, 2022
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 @Prestaworks ,

Tested the following:

  • Single store & multistore (with 2 groups)
  • Enabling of webservice
  • Creation of webservice for a specific store
  • Creation of webservice for all store
  • Creation of specific product for a specific store
  • Switched from single to multistore a few times
  • Tested only the GET method.

My shop architecture:

  • group default
    • shop1
    • shop2
  • second group
    • shop3

Created webservices for all of the shops, no more redirection to myshop.com/api/products?url=products when accessing myshop.com/api/products&id_shop=all
Each webservice created for each shop has its products.

Screen.Recording.2022-10-19.at.10.27.58.mov

Well noted for what you said in the comment :

you can't create it for all shops, only for one specific shop at a time

For instance, 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 Oct 19, 2022
@prestonBot
Copy link
Collaborator

QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge.

@atomiix atomiix added this to the 8.1.0 milestone Oct 19, 2022
@atomiix atomiix merged commit 31bdccd into PrestaShop:develop Oct 19, 2022
@atomiix
Copy link
Contributor

atomiix commented Oct 19, 2022

Thanks @Prestaworks & @florine2623

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug fix Type: Bug fix develop Branch QA ✔️ Status: check done, code approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With Multistore enabled, API calls are redirected to homepage
7 participants