concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Fix accessing undef variable $variationLookup in product_modal #783

Closed mlocati closed 1 year ago

mlocati commented 1 year ago

I don't know when this occurs, but I have the following error in the logs:

Exception Occurred:
packages/community_store/elements/product_modal.php:123]:
Undefined variable $variationLookup

The easy fix is cffdfbd7e55bc4b3ede8023e9ab76d1a39ba7dd7 (included in this PR), but I'm wondering if instead we should move the definition of $variationLookup currently at line 205 before line 123

mlocati commented 1 year ago

I managed to replicate the issue: it occurs when we have a Product List block with the "Display Quickview Link (Modal Window)" option turned on:

immagine

In this case, when users click on the product image, we have the error above.

I tried to fix it by adding this line rather top in the elements/product_modal.php file:

$variationLookup = $product->getVariationLookup();

and then the error changed to:

Undefined array key 2 at line
$variation = $variationLookup[$optionItem->getID()];

So I changed that line to

$variation = isset($variationLookup[$optionItem->getID()]) ? $variationLookup[$optionItem->getID()] : null;

Then the error became

Undefined variable $availableOptionsids

So, rather on top, I added these lines:

$variationData = $product->getVariationData();
$availableOptionsids = isset($variationData['availableOptionsids']) ? $variationData['availableOptionsids'] : null;

Then the error became

Undefined variable $btnText

So, I changed code

<?=  ($btnText ? h($btnText) : t("Add to Cart")); ?>

to

<?=  empty($btnText) ? t('Add to Cart') : h($btnText) ?>

And finally the modal appeared withour errors

but

Whereas in the product list I can choose the quantity and the variations, in the modal I see the Out of Stock message (so, I can't add it to the cart).

...and my knowledge of Community Store stops here...

Mesuva commented 1 year ago

I'll take a look and see what I can find.

I've personally never used the quick look feature, I'm just not a fan of it. So it's something I've neglected to be honest. I was even tempted to remove it, but I just don't know if people are using it.

mlocati commented 1 year ago

...and my knowledge of Community Store stops here...

Here's the point I can't solve:

$product->isSellable()

It returns false here:

immagine

And I don't know how to proceed.

mlocati commented 1 year ago

I've personally never used the quick look feature, I'm just not a fan of it.

I've disabled it for now (I also find it rather ugly, but ya now, it's not a website for me :wink:)

I'll take a look and see what I can find.

Thanks ❤️!

mlocati commented 1 year ago

I created the issue #792 that replaces this pull request.