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

[ECP-8915] AbstractPaymentMethodHandler NullPointer Exception for Products without Category/Categories #450

Closed
thomaswiener opened this issue Jan 18, 2024 · 1 comment · Fixed by #452
Assignees
Labels
Bug report Indicates that issue has been marked as a possible bug

Comments

@thomaswiener
Copy link

Error Report for
store.shopware.com/adyenpaymentshopware6:^3.13
file: store.shopware.com/adyenpaymentshopware6/src/Handlers/AbstractPaymentMethodHandler.php:663
Is:

if (isset($product) && !is_null($product->getCategories())) {
    $productCategory = $product->getCategories()->first()->getName();
} else {
    $productCategory = null;
}

Should:

if (isset($product) && !is_null($product->getCategories()) && $product->getCategories()->count() > 0) {
    $productCategory = $product->getCategories()->first()->getName();
} else {
    $productCategory = null;
}

Why:
product->getCategories() is a collection but might have no items. Unlike an empty array which is consider null, a collection without items is not null. This leads to an error on the next line, when the first item of an empty collection is taken (in this case null) and throws an php exception when trying to get getName() on null. (

@hossam-adyen hossam-adyen self-assigned this Jan 19, 2024
@hossam-adyen hossam-adyen added the Bug report Indicates that issue has been marked as a possible bug label Jan 19, 2024
@hossam-adyen hossam-adyen changed the title AbstractPaymentMethodHandler NullPointer Exception for Products without Category/Categories [ECP-8915] AbstractPaymentMethodHandler NullPointer Exception for Products without Category/Categories Jan 19, 2024
@hossam-adyen
Copy link
Contributor

Hi @thomaswiener , thanks for your valuable report, I've opened a PR for that fix and once it's reviewed and merged it will be included in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug report Indicates that issue has been marked as a possible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants