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

Hook actionCartSave does not receive proper cart data when being triggered from Webservice. #20509

Closed
Tracked by #10069
elboletaire opened this issue Aug 8, 2020 · 8 comments
Labels
1.7.5.1 Affects versions 1.7.6.7 Affects versions 1.7.7.x Branch Bug Type: Bug Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Shopping carts Label: Which BO under menu is concerned WS Category: Web Service

Comments

@elboletaire
Copy link
Contributor

elboletaire commented Aug 8, 2020

Describe the bug

The actionCartSave hook triggered on Cart save & update is not properly being initialized when being triggered as a result of a cart update using the Webservice.

imatge

The problem seems to be related with the context being initialized later, but only when using the Webservice. By default, Hook::exec sets the cart if it's not previously set, getting it from the context. Neither in add nor in update the hook is being called with arguments, making it falling back to taking the cart from the context.

Manually adding the cart to the update/add method solves this issue:

imatge

I know this is NOT the way to fix it, I'm just trying to show my point, that the cart is not properly set in context in this specific case.

Expected behavior

To receive the proper cart information, as when being called without the webservice

imatge

Steps to Reproduce

Steps to reproduce the behavior:

  1. Register a hook to actionCartSave with a dump($params) on it, just for debugging.
  2. Install your module, or install the hook manually, whatever to ensure it's being called.
  3. Enable the Webservice and get and API key for it, ensure you have checked all the related permissions for the cart endpoint.
  4. With an HTTP tool like curl, postman or insomnia, make a request trying to create or update a cart object (see below for an xml based for the demo data).
  5. You'll see the debug returns the cart empty.
  6. Without touching anything, go to the home page of the website and add something to your cart.
  7. You'll see now how the debug shows the proper cart information.
Click here to see the full xml sent to the cart endpoint
<?xml version="1.0" encoding="UTF-8"?>
<prestashop
  xmlns:xlink="http://www.w3.org/1999/xlink">
    <cart>
      <id_address_delivery>2</id_address_delivery>
      <id_address_invoice>2</id_address_invoice>
      <id_currency>1</id_currency>
      <id_customer>2</id_customer>
      <id_guest>0</id_guest>
      <id_lang>1</id_lang>
      <id_shop_group>1</id_shop_group>
      <id_shop>1</id_shop>
      <id_carrier>1</id_carrier>
      <recyclable>0</recyclable>
      <gift>0</gift>
      <gift_message></gift_message>
      <mobile_theme>0</mobile_theme>
      <delivery_option></delivery_option>
      <secure_key>9685f90b1972bc2022ba23d8a380b2ba</secure_key>
      <allow_seperated_package>0</allow_seperated_package>
      <fecha_entrega></fecha_entrega>
      <hora_entrega></hora_entrega>
      <cambio></cambio>
      <date_add>2020-05-11 13:03:29</date_add>
      <date_upd>2020-05-12 11:19:22</date_upd>
      <associations>
        <cart_rows nodeType="cart_row" virtualEntity="true">
          <cart_row>
            <id_product>2</id_product>
            <id_customization>0</id_customization>
            <id_address_delivery>2</id_address_delivery>
            <quantity>1</quantity>
          </cart_row>
        </cart_rows>
      </associations>
    </cart>
</prestashop>

Additional information

  • PrestaShop version: >= 1.7.6
@prestashop-issue-bot
Copy link

Thanks for opening this issue! We will help you to keep its state consistent

@elboletaire elboletaire mentioned this issue Aug 8, 2020
72 tasks
@khouloudbelguith
Copy link
Contributor

Hi @elboletaire,

I did not manage to reproduce the issue with PS1.7.6.7.
I attached a screen record
https://drive.google.com/file/d/182o6YNJ3uWRA9JEmA2IN2ut3oyTwC7qH/view?usp=sharing

Thanks to check and feedback.

@khouloudbelguith khouloudbelguith added 1.7.6.7 Affects versions Bug Type: Bug NMI Status: issue needs more information Shopping carts Label: Which BO under menu is concerned WS Category: Web Service labels Aug 10, 2020
@elboletaire
Copy link
Contributor Author

Can you please explain me the exact steps you followed? I have reproduced this both in prestashop 1.7.6 and prestashop 1.7.7 (clean installs using docker), and both times got the same result.

Are you using a fresh install? Or maybe you have some setting that could affect this behavior?

@elboletaire
Copy link
Contributor Author

elboletaire commented Aug 10, 2020

Err... In you video I can clearly see (its quality could be better btw) how the "Cart" object has null records. Are you sure it worked for you? 🤔

imatge

@khouloudbelguith
Copy link
Contributor

@elboletaire, I have this
CRUD Tutorial - Create cart.pdf

Thanks!

@elboletaire
Copy link
Contributor Author

Your cart data is all set to null, as I stated in the issue

imatge

There should be no null value, but the information you sent via XML on request already set on the Cart object.

@khouloudbelguith
Copy link
Contributor

@elboletaire, thanks for your feedback.
I manage to reproduce the issue with PS1.7.5.1, PS1.7.6.7 and 1.7.7x branch.
I’ll add this to the debug roadmap so that it’s fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

@khouloudbelguith khouloudbelguith added 1.7.5.1 Affects versions 1.7.7.x Branch Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Ready Status: Issue is ready to be worked on and removed NMI Status: issue needs more information labels Aug 10, 2020
@elboletaire
Copy link
Contributor Author

#9972 (comment)

@prestashop-issue-bot prestashop-issue-bot bot removed the Ready Status: Issue is ready to be worked on label Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.5.1 Affects versions 1.7.6.7 Affects versions 1.7.7.x Branch Bug Type: Bug Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Shopping carts Label: Which BO under menu is concerned WS Category: Web Service
Projects
None yet
Development

No branches or pull requests

2 participants