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 getTotalWeight Notice #10254

Merged
merged 2 commits into from Sep 4, 2018

Conversation

Projects
None yet
4 participants
@duGuillaume
Contributor

duGuillaume commented Sep 3, 2018

Questions Answers
Branch? develop
Type? bug fix
Category? FO
BC breaks? no
Deprecations? no
Fixed ticket?

getTotalWeight function (Cart.php) can return "Notice: Undefined index: " if $products is null and $this->id is null to

getTotalWeight call updateProductWeight with null

if (!isset(self::$_totalWeight[$this->id])) {
    $this->updateProductWeight($this->id);
 }

but updateProductWeight return self::$_totalWeight[$productId] with $productId = 0 ($productId = (int) $productId);

so we retrun self::$_totalWeight[0] but into getTotalWeight we return self::$_totalWeight[$this->id];
self::$_totalWeight[null] != self::$_totalWeight[0]

it's possible to solve this by changing return line


This change is Reviewable

@prestonBot

This comment has been minimized.

Show comment
Hide comment
@prestonBot

prestonBot Sep 3, 2018

Collaborator

Hi!

Your pull request description seems to be incomplete or malformed:

  • The description shouldn't be empty.

Would you mind completing the contribution table ? This would help us understand how interesting your contribution is.

Thank you!

(note: this is an automated message, but answering it will reach a real human )

Collaborator

prestonBot commented Sep 3, 2018

Hi!

Your pull request description seems to be incomplete or malformed:

  • The description shouldn't be empty.

Would you mind completing the contribution table ? This would help us understand how interesting your contribution is.

Thank you!

(note: this is an automated message, but answering it will reach a real human )

@Quetzacoalt91

Hi @GuillaumeKadolis,

As you said in your comment, self::$_totalWeight[$this->id] is always defined, here thanks to $this->updateProductWeight($this->id);.

I guess it would be better to see how to reproduce this error. If there is a place in the core where we call the method without ID or product list, this must be fixed.

Also, if the value is only stored in the key 0 because of the int cast, why don't you add the same action on the return line?

return self::$_totalWeight[(int) $this->id];

Let us know if it removes the notice.

@duGuillaume

This comment has been minimized.

Show comment
Hide comment
@duGuillaume

duGuillaume Sep 3, 2018

Contributor

oh it's a cleaner solution thx, i changed my PR

Contributor

duGuillaume commented Sep 3, 2018

oh it's a cleaner solution thx, i changed my PR

@marionf marionf added QA ✔️ and removed waiting for QA labels Sep 4, 2018

@Quetzacoalt91 Quetzacoalt91 added this to the 1.7.5.0 milestone Sep 4, 2018

@Quetzacoalt91 Quetzacoalt91 changed the title from FO: fix getTotalWeight Notice to Fix getTotalWeight Notice Sep 4, 2018

@Quetzacoalt91 Quetzacoalt91 merged commit 2966a80 into PrestaShop:develop Sep 4, 2018

2 checks passed

Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Quetzacoalt91

This comment has been minimized.

Show comment
Hide comment
@Quetzacoalt91

Quetzacoalt91 Sep 4, 2018

Member

Thank you @GuillaumeKadolis

Member

Quetzacoalt91 commented Sep 4, 2018

Thank you @GuillaumeKadolis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment