alma / alma-monthlypayments-magento2

Magento 2 Payment Gateway integration for Alma
Other
6 stars 9 forks source link

Checkout : SQL Error if one product of cart has no category IDs #77

Closed vncnt-mb closed 1 year ago

vncnt-mb commented 1 year ago

Hello,

When we place an order for an item (Simple product without category, or a configurable product with a child product without an assigned category), the form refuses to go to the Alma platform and displays an SQL error in customer view (even by disabling debug mode).

Capture d’écran 2022-12-08 à 12 42 19

I found a simple workaround, just check if the product has categories before starting the search via the repository:

https://github.com/alma/alma-monthlypayments-magento2/blob/638fda1b69512d478dacba25d1d53f4cb4f40f24/Model/Data/Quote.php#L158

private function getProductCategories(Product $product): array
{
  $categoryIds = $product->getCategoryIds();

  if(empty($categoryIds)) return []; # add this

  try {
    $categoryCollection = $this->getCategoryCollection($categoryIds);
  } catch (LocalizedException $e) {
    $this->logger->info(
        'Impossible to create category collection for product',
        [
            'product ID '=> $product->getId(),
            'Exception Message' => $e->getMessage()
        ]
    );
    return [];
  }
...

If you find anything better than my light workaround, go for it. And, if you have more questions, don't hesitate to reply me :)

Have a nice day !

Francois-Gomis commented 1 year ago

Hi, thanks for your report. I fixed this issue in the next version. I am waiting for review. Thanks