facebookarchive / facebook-for-magento2

* Pixel on all pages, which trigger events link, PageView, ViewContent, AddToCart, Initiatecheckout and Purchase.* In the background, Syncs the products from the merchants product catalog to Facebook Catalog.* Stores all the data, like pixel id, catalog id, business maanger id, on to the local database on the instance.
Other
46 stars 36 forks source link

[Bug]: Magento 2.4.x and PHP8.x Compatibiliy #131

Closed ecrocombe closed 1 year ago

ecrocombe commented 1 year ago

Contact Details

ecrocombe@outlook.com

What happened?

It appears the devs have done the hard work to address compatibility with Magento 2.4.x and PHP8.x, however they have not pushed a stable release (expected 1.4.6) for us to install.

Until a new version is released, we can install the development version dev-main by:

  1. Adding this github repo to composer Edit the composer.json in the magento root directory, find and replace this:

    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],

    WITH

    "repositories": [
        {
            "type": "github",
            "url": "https://github.com/facebookincubator/facebook-for-magento2"
        },
        {
            "type": "composer",
            "url": "https://repo.magento.com/",
            "exclude": ["facebook/facebook-for-magento2"]
        }
    ],
  2. Install with composer Install the dev-main release with the command composer require facebook/facebook-for-magento2:dev-main.

  3. Upgrade The usual commands we love and enjoy:

    bin/magento maint:en
    bin/magento setup:upgrade
    bin/magento setup:di:compile
    bin/magento setup:static-content:deploy
    bin/magento maint:dis

This change will most likely need to be reverted once a stable version has been released as the dev-main may create issues in the future. This will most likely be in the form of:

  1. composer remove facebook/facebook-for-magento2:dev-main
  2. Remove the above changes to the composer file.
  3. composer require facebook/facebook-for-magento2

I hope this helps you.

Magento Version

2.4.x

Plugin Version

1.4.5

Relevant log output

No response

Code of Conduct

pratikvs commented 1 year ago

Hi ecrocombe,

I tried the above given solution with the 2.4.5-p1 EE version and PHP8.1. The solution works fine for the nonl-ogged in user but when the user is logged in it gives the below error. Please check and let us know.

`1 exception(s): Exception #0 (Exception): Deprecated Functionality: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/magento/vendor/facebook/facebook-for-magento2/Helper/MagentoDataHelper.php on line 481

Exception #0 (Exception): Deprecated Functionality: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/magento/vendor/facebook/facebook-for-magento2/Helper/MagentoDataHelper.php on line 481`

mihaimatei commented 1 year ago

@pratikvs , what I've found is that in the dev-main branch, the update from 2 weeks ago just updated the facebook/php-business-sdk 9.0.3 to >=15.0.0, so the sdk is now compatible with php8.1, but they haven't fixed the strtolower bug. I've opened a PR for this issue: https://github.com/facebookincubator/facebook-for-magento2/pull/132

Until it will be merged into, here is a patch that you can use to fix that: Create a file like patches/composer/facebook-m2-php8fix/facebook-m2-1.4.5-1.4.6-php8.1--1.patch

--- Helper/MagentoDataHelper.php    2022-03-15 15:40:14.000000000 +0000
+++ Helper/MagentoDataHelper.php    2023-01-05 18:16:03.949331672 +0000
@@ -478,7 +478,7 @@
     }

     private function hashValue($string){
-        return hash('sha256', strtolower($string));
+        return hash('sha256', strtolower((string)$string));
     }

     // TODO Remaining user/custom data methods that can be obtained using Magento.

then also add it into composer.json like:

"patches": {
            "facebook/facebook-for-magento2": {
                "facebook-m2-php81--1": "patches/composer/facebook-m2-php8fix/facebook-m2-1.4.5-1.4.6-php8.1--1.patch"
            }
...