• Magento
  • 2 MINUTES READ

Migrating Magento Websites to PHP7

  • POSTED ON
  • April 15, 2016
  • POSTED BY
  • Aayan Arif
  • POSTED ON April 15, 2016
  • POSTED BY Aayan Arif

Magento is one of the biggest and most popular e-commerce platforms written in PHP. However, migrating Magento sites to PHP 7 can prove to be a tedious task. While most of the Magento code is still valid in PHP 7, a few situations can arise where there are incompatibilities. This article will take you through these incompatibilities step by step....

Magento is one of the biggest and most popular e-commerce platforms written in PHP. However, migrating Magento sites to PHP 7 can prove to be a tedious task. While most of the Magento code is still valid in PHP 7, a few situations can arise where there are incompatibilities. This article will take you through these incompatibilities step by step to ensure a hassle free Magento to PHP 7 migration.

Following are the three main issues and their solutions:

1- Uniform Variable Syntax Errors

The following files cause variable syntax errors that need to be resolved with the help of steps mentioned below:

a) app/code/core/Mage/Core/Model/Layout.php:555

A fatal error is caused by this file which crashes Magento. To override this file, go to line#555 and replace $out .= $this->getBlock($callback[0])->$callback[1](); with $out .= $this->getBlock($callback[0])->{$callback[1]}();.

b) appcodecoreMageImportExportModelImport:135

Magento CSV importer is affected by this file and you need to nullify it first. After that override _validateFile() function and go to line#135 and replace $params[‘object’]->$params[‘method’]($filePath); with $params[‘object’]->{$params[‘method’]}($filePath);.

c) appcodecoreMageImportExportModelExportEntityProductTypeAbstract.php:99

The abstract class issue has an impact on Magento‘s export functionality. Magento extends the following three classes from this abstract class:

  • Mage_ImportExport_Model_Export_Entity_Product_Type_Configurable
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Grouped
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Simple
    .

The root cause of this error inside the above mentioned classes is actually in line#99, so you need to override these three classes in your local code pool. To override the Attribute() function, go to line#99 and replace $data[‘filter_options’] = $this->$data[‘options_method’](); with $data[‘filter_options’] = $this->{$data[‘options_method’]}();.

d) appcodecoreMageImportExportModelExportEntityCustomer.php:250

This file affects export customers’ functionality. To override the above mentioned file, go to line#250 and replace $data[‘filter_options’] = $this->$data[‘options_method’](); with $data[‘filter_options’] = $this->{$data[‘options_method’]}();.

e) libVarienFileUploader.php:259

An issue may emerge here that file uploading won’t work. As Magento extends Mage_Core_Model_File_Uploader from the above class, so you need to override it and rewrite _validateFile() function. Now, go to line#259 and replace $params[‘object’]->$params[‘method’]($this->_file[‘tmp_name’]); with $params[‘object’]->{$params[‘method’]}($this->_file[‘tmp_name’]);.

2- Type Casting Issue

appcodecoreMageCoreModelResourceSession.php:218

User login won’t work in light of the fact that Magento Sessions don’t deal with PHP 7. read($sessId) function should return a string, so typecast the return variable by replacing return $data; with return (string)$data;.

3- Incorrect Grand Total

This issue can arise due to wrong sort order of subtotal, discount, and shipping etc. You need to correct the sort order by creating an extension. For this, put the following code in config.xml of the created extension:

<global>
    <sales>
        <quote>
            <totals>
                <msrp>
                     <before>grand_total</before>
                </msrp>
                <shipping>
                     <after>subtotal,freeshipping,tax_subtotal,msrp</after>
                </shipping>
            </totals>
        </quote>
    </sales>
</global>

ABOUT THE AUTHOR

Aayan Arif

Content Strategist at vteams - Aayan has over 8 years of experience of working with multiple industries.

0 Comments

Leave a Reply

More Related Article
We provide tips and advice on delivering excellent customer service, engaging your customers, and building a customer-centric business.