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

Undefined array key "optGroup0" #698

Closed mdius closed 2 years ago

mdius commented 2 years ago

Now I am getting a "Undefined array key "optGroup0"" /packages/community_store/src/CommunityStore/Product/ProductOption/ProductOption.php

if ($option) {
    //add option items
    $itemsInGroup = is_array($data['optGroup' . $i]) ? count($data['optGroup' . $i]) : 0;   <- Error Line 315

    if ($itemsInGroup > 0) {
        for ($gi = 0; $gi < $itemsInGroup; $gi++, $ii++) {
        if ($data['poiID'][$ii] > 0) {
              $optionItem = ProductOptionItem::getByID($data['poiID'][$ii]);

I fixed it by changing the line to: "$itemsInGroup = isset($data['optGroup' . $i]) && is_array($data['optGroup' . $i]) ? count($data['optGroup' . $i]) : 0;" I don't know if that is the proper way, but it is seeming to work.

Mesuva commented 2 years ago

I'd say that's the best way to address this for now, I've pushed that up to the master branch.

Why it's undefined in the first place is perhaps a better question to ask, but if it's all saving and working as expected there might not anything to fix as such.