Notice: Undefined offset

Created on 15 December 2020, over 3 years ago
Updated 14 January 2024, 6 months ago

Hi, thank you for creating this much needed feature. I installed through composer and followed the instructions:

Installation and Usage:
Download Commerce Url Hash module
Enable the Commerce Url Hash module.
Now you can go to checkout Urls you will see Order ID is converted to hash value.
Note:- In this module for encypt/decrypt service is available. So in custom module if you want to convert Order ID to hash or hash to Order ID you can use service (commerce_url.encrypt_decrypt) available in services.yml

but when I go to the checkout Urls, the Order is not converted to a hash value. I am on latest Drupal 8 and Commerce 2 install. Log message:

Notice: Undefined offset: 2 in Drupal\commerce_url\PathProcessor\CommercePathProcessor->commerceUrlProcess() (line 58 of /home/######/public_html/#############.com/web/modules/contrib/commerce_url/src/PathProcessor/CommercePathProcessor.php)

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States djween

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India Manikandan Era

    The error "Undefined array key 2" typically occurs when you're trying to access an array element using a key that doesn't exist. In your case, it seems like the $arg array doesn't have a key with index 2, and you're trying to access it.

    Here's a safer way to check if the key exists before accessing it:

    if (isset($arg[1]) && $arg[1] == "checkout" && isset($arg[2]) && !(is_numeric($arg[2]))) {
    $path = $this->commerceUrlProcess($path, $arg, EncryptDecrypt::DECRYPT);
    }

    This code uses the isset() function to check if the keys $arg[1] and $arg[2] exist before comparing or using their values. This should help prevent the "Undefined array key" error.

    Make sure to adapt this to your specific needs and context. If $arg is expected to have certain keys under different conditions, you may need to adjust the conditions accordingly.

Production build 0.69.0 2024