OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
870 stars 436 forks source link

Exception: Warning: Trying to access array offset on value of type null #4256

Open r-martins opened 1 month ago

r-martins commented 1 month ago

Preconditions (*)

  1. Trying to place an order as a new customer
  2. OpenMage 20.10

Steps to reproduce (*)

  1. Add product to cart and proceed to checkout
  2. Create a new customer (instead of login)
  3. Place order

Expected result (*)

  1. Order to be placed with no issues

Actual result (*)

  1. Alert saying something went wrong. The following is logged:

Exception: Warning: Trying to access array offset on value of type null in /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php on line 733 in /var/www/html/app/code/core/Mage/Core/functions.php:207 Stack trace:

0 /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php(733): mageCoreErrorHandler(2, 'Trying to acces...', '/var/www/html/a...', 733)

1 /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php(811): Mage_Checkout_Model_Type_Onepage->_prepareNewCustomerQuote()

2 /var/www/html/app/code/core/Mage/Checkout/controllers/OnepageController.php(605): Mage_Checkout_Model_Type_Onepage->saveOrder()

3 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Mage_Checkout_OnepageController->saveOrderAction()

4 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('saveOrder')

5 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))

6 /var/www/html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()

7 /var/www/html/app/Mage.php(763): Mage_Core_Model_App->run(Array)

8 /var/www/html/index.php(93): Mage::run('', 'store')

Additional config that may be relevant:

378|default|0|admin/security/session_cookie_lifetime|50400|
758|default|0|web/default/cms_no_cookies|enable-cookies|
761|default|0|web/cookie/cookie_lifetime|50400|
762|default|0|web/cookie/cookie_path||
763|default|0|web/cookie/cookie_domain||
764|default|0|web/cookie/cookie_httponly|0|
765|default|0|web/cookie/cookie_samesite|None|
766|default|0|web/cookie/cookie_restriction|0|
772|default|0|web/browser_capabilities/cookies|1|

default|0|customer/address/street_lines|4
default|0|shipping/origin/street_line1|Rua Angelo Guerra
default|0|shipping/origin/street_line2|1
kiatng commented 1 month ago

https://github.com/OpenMage/magento-lts/blob/df37dba44808847ccbb90a4ec8a53cb6065e832c/app/code/core/Mage/Checkout/Model/Type/Onepage.php#L733-L733

As you can see,, line 733 has no var of type array. I also search "[" on the file, I cannot find anything that could cause the error Trying to access array offset on value of type null. Can you copy paste the function that has line 733?

sreichel commented 1 month ago

Tried to reproduce ... w/o success.

r-martins commented 1 month ago
        Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
        $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
        $passwordCreatedTime = $this->_checkoutSession->getData('_session_validator_data')['session_expire_timestamp']
            - Mage::getSingleton('core/cookie')->getLifetime();
        $customer->setPasswordCreatedAt($passwordCreatedTime);
        $quote->setCustomer($customer)
            ->setCustomerId(true);
        $quote->setPasswordHash('');

Line 733 here is the $passwordCreatedTime = ...

sreichel commented 1 month ago

This should not be there.

It was changed in #2916 (https://github.com/OpenMage/magento-lts/releases/tag/v20.1.0-rc4)

Have you any rewrites in app/code/local?

File from 20.10 release ... https://github.com/OpenMage/magento-lts/blob/v20.10.0/app/code/core/Mage/Checkout/Model/Type/Onepage.php

r-martins commented 1 month ago

Probably I failed to update it to the latest version. I'm using openMage with composer, but despite the fact that my composer.lock shows I'm using v20.10.2, app/code/core remains with the old 20.5.0.

What is the correct way to update OpenMage? Sorry about that.

sreichel commented 1 month ago

If you composer.lock says "20.10.2" re-run "composer install". (maybe remove vendor dir before)

r-martins commented 1 month ago

I tried this in many different ways, but it only says my "/var/www/html/app/Mage.php was already patched" and don't update any of the app/code/core or Mage.php.

https://github.com/user-attachments/assets/4918cd52-ccca-4a74-9230-f996ab99d154

https://www.dropbox.com/scl/fi/ietx5dxqz6r4pemfqjylo/openmage-update.mp4?rlkey=k4s9v8a32q31w3ej2y9accgp9&dl=0

r-martins commented 1 month ago

Replaced app/code/core, Mage.php and lib folders for the ones in the latest version of vendor/openmage/magento-lts. Still got some other deprecated errros. The only way I found to to get rid of them in the development environment was to disable developerMode (Mage::setIsDeveloperMode(false) in index.php).

kiatng commented 1 month ago

Replaced app/code/core, Mage.php and lib folders for the ones in the latest version of vendor/openmage/magento-lts. Still got some other deprecated errros. The only way I found to to get rid of them in the development environment was to disable developerMode (Mage::setIsDeveloperMode(false) in index.php).

Alternatively, if you can list the deprecated errors here, we can try and fix it.

r-martins commented 1 month ago

Sure. This happened when placing an order with OSC.

==> src/htdocs/var/log/exception.log <==
2024-10-15T22:55:13+00:00 ERR (3): 
Exception: Deprecated functionality: Function mcrypt_module_open() is deprecated  in /var/www/html/lib/Varien/Crypt/Mcrypt.php on line 61 in /var/www/html/app/code/core/Mage/Core/functions.php:184
Stack trace:
#0 /var/www/html/lib/Varien/Crypt/Mcrypt.php(61): mageCoreErrorHandler(8192, 'Function mcrypt...', '/var/www/html/l...', 61)
#1 /var/www/html/app/code/core/Mage/Core/Model/Encryption.php(172): Varien_Crypt_Mcrypt->init('670c202bafcedd3...')
#2 /var/www/html/app/code/core/Mage/Core/Model/Encryption.php(185): Mage_Core_Model_Encryption->_getCrypt()
#3 /var/www/html/app/code/core/Mage/Core/Helper/Data.php(221): Mage_Core_Model_Encryption->encrypt('teste2024101685...')
#4 /var/www/html/app/code/core/Mage/Customer/Model/Customer.php(568): Mage_Core_Helper_Data->encrypt('teste2024101685...')
#5 /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php(441): Mage_Customer_Model_Customer->encryptPassword('teste2024101685...')
#6 /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php(311): Mage_Checkout_Model_Type_Onepage->_validateCustomerData(Array)
#7 /var/www/html/.modman/oscbrasil6/app/code/community/Inovarti/Onestepcheckout/controllers/AjaxController.php(353): Mage_Checkout_Model_Type_Onepage->saveBilling(Array, false)
#8 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Action.php(424): Inovarti_Onestepcheckout_AjaxController->placeOrderAction()
#9 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(255): Mage_Core_Controller_Varien_Action->dispatch('placeOrder')
#10 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Front.php(181): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#11 /var/www/html/app/code/core/Mage/Core/Model/App.php(358): Mage_Core_Controller_Varien_Front->dispatch()
#12 /var/www/html/app/Mage.php(761): Mage_Core_Model_App->run(Array)
#13 /var/www/html/index.php(93): Mage::run(4, 'website')
kiatng commented 1 month ago

@r-martins You need to install "phpseclib/mcrypt_compat": "^2.0.3" for the deprecated function mcrypt_module_open(). See https://github.com/OpenMage/magento-lts/blob/211164038aa17b629545992195f2883358982448/composer.json#L32-L32

r-martins commented 1 month ago

it is there..

root@b21df065f3a7:/var/www/html# ./composer.phar info phpseclib/mcrypt_compat
you may want to add the packages.firegento.com repository to composer.
add it with: composer.phar config -g repositories.firegento composer https://packages.firegento.com
name     : phpseclib/mcrypt_compat
descrip. : PHP 5.x-8.x polyfill for mcrypt extension
keywords : cryptograpy, encryption, mcrypt, polyfill
versions : * 2.0.6
released : 2024-02-26, 7 months ago
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : 
source   : [git] https://github.com/phpseclib/mcrypt_compat.git e5924504997b4f90772034cefd89dc2f4ec189dc
dist     : [zip] https://api.github.com/repos/phpseclib/mcrypt_compat/zipball/e5924504997b4f90772034cefd89dc2f4ec189dc e5924504997b4f90772034cefd89dc2f4ec189dc
path     : /var/www/html/vendor/phpseclib/mcrypt_compat
names    : phpseclib/mcrypt_compat, ext-mcrypt

support
email : terrafrost@php.net
issues : https://github.com/phpseclib/mcrypt_compat/issues
source : https://github.com/phpseclib/mcrypt_compat

autoload
files

requires
php >=5.6.1
phpseclib/phpseclib >=3.0.36 <4.0.0

requires (dev)
phpunit/phpunit ^5.7|^6.0|^9.4

suggests
ext-openssl Will enable faster cryptographic operations

provides
ext-mcrypt 5.6.40
root@b21df065f3a7:/var/www/html# 
sreichel commented 1 month ago

Do you have a vendor dir outside openmages?

Install clearly says it installs 20.10.2 .... so it loads files from anywhere else (?)