paypal plugin error

  • Posts: 25
  • Thank you received: 1
  • Hikashop Business
6 months 4 weeks ago #360498

-- HikaShop version -- : 5.0.4
-- Joomla version -- : 4.4.4
-- PHP version -- : 8.1.28
-- Browser(s) name and version -- : Any browser
-- Error-message(debug-mod must be tuned on) -- : 0 array_search(): Argument #2 ($haystack) must be of type array, string given
Call stack
# Function Location
1 () JROOT/plugins/hikashoppayment/paypalcheckout/paypalcheckout.php:1371
2 array_search() JROOT/plugins/hikashoppayment/paypalcheckout/paypalcheckout.php:1371
3 plgHikashoppaymentPaypalcheckout->loadJS() JROOT/plugins/hikashoppayment/paypalcheckout/paypalcheckout.php:410
4 plgHikashoppaymentPaypalcheckout->onAfterOrderConfirm() JROOT/administrator/components/com_hikashop/classes/order.php:969
5 hikashopOrderClass->createFromCart() JROOT/components/com_hikashop/controllers/checkout.php:699
6 checkoutController->confirm() JROOT/libraries/src/MVC/Controller/BaseController.php:693
7 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/administrator/components/com_hikashop/helpers/helper.php:2555
8 hikashopController->execute() JROOT/components/com_hikashop/hikashop.php:88
9 require_once() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:71
10 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:73
11 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:361
12 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/SiteApplication.php:208
13 Joomla\CMS\Application\SiteApplication->dispatch() JROOT/libraries/src/Application/SiteApplication.php:249
14 Joomla\CMS\Application\SiteApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:293
15 Joomla\CMS\Application\CMSApplication->execute() JROOT/includes/app.php:61
16 require_once() JROOT/index.php:32

Hello,

The Hikashop paypal plugin (HikaShop Paypal Checkout plugin) on my site doesn't work anymore.

It used to work without any problems. I updated Joomla from 4.4.2 to 4.4.4 a couple of weeks ago, and also Hikashop. The PHP version hasn't changed.

I now get an "array_search(): Argument #2 ($haystack) must be of type array, string given " error when clicking on the "Finish: button on my website (before being transferred to Paypal).

Any ideas?

Alain


This is what I get if I out the full debug output in ChatGPT

The error message you're encountering, `0 array_search(): Argument #2 ($haystack) must be of type array, string given`, indicates a type mismatch issue in the PHP code of the PayPal plugin for Hikashop in Joomla. This error occurs because the `array_search()` function expects its second argument (`$haystack`) to be an array, but instead, it received a string.

Here's a breakdown of the issue based on the call stack you provided:

- **Location of the Error**: The problem originates from the `paypalcheckout.php` file in the PayPal plugin for Hikashop at line 1371.
- **Function Call Sequence**: The error is triggered during a sequence of method calls leading up to `array_search()`. The `onAfterOrderConfirm()` function from `paypalcheckout.php` (line 410) calls `loadJS()`, which at line 1371 attempts to use `array_search()`.
- **Description of the Problem**: The `loadJS()` function seems to be looking for a specific value in an array, but instead of an array, a string is provided, which causes PHP to throw a type error.

### How to Resolve This Issue:

1. **Examine the Code**: Open the file `JROOT/plugins/hikashoppayment/paypalcheckout/paypalcheckout.php` and go to line 1371 to see what is being passed to `array_search()`. You need to understand whether the variable that should be an array is being incorrectly set as a string somewhere in the code.

2. **Debug the Variables**: Add debugging statements before line 1371 to print out the variable that should be an array. This can help determine why it's a string. For instance:
```php
var_dump($variable); // Replace `$variable` with the actual variable name used in `array_search()`
die(); // to stop further execution and observe the variable's content
```

3. **Check Data Sources**: If the variable is set based on some data fetched from elsewhere (like a database or an API response), ensure that the data fetching and handling logic correctly interprets and formats the data as an array.

4. **Update the Plugin/Contact Support**: If this is a plugin you downloaded or purchased, check for any updates that might fix this issue, or contact the support for the plugin. It's possible that this is a known issue with a solution already available.

5. **Patch the Code Temporarily**: If you're comfortable with PHP, you can attempt to modify the code to ensure the variable is an array. For example:
```php
if (!is_array($variable)) {
$variable = explode(',', $variable); // Convert string to array if it's a comma-separated string
}
```
This is just an example and may need to be adapted based on the actual content and purpose of the variable.

Remember to back up any files before modifying them, and if you're unsure about making changes, consider consulting with a developer familiar with PHP and Joomla.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 4 weeks ago #360503

Hi,

I've made a patch for this.
Download again the install package of the 5.0.4 on our website and install it on yours in order to get the patch.
It should then work properly.

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 1
  • Hikashop Business
6 months 4 weeks ago #360504

Thanks..that works.

Alain

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum