eCommerce for php7

The long term future of concrete5.6 is now ensured through an update to make it php7 compatible. The update is currently on GitHub and not officially released. However, many sites are now running this c5.6 core version and with php7 compatibility comes an approximate 30% update is speed.

Having updated Zone Based Shipping to be fully compatible, the next hurdle was to get the core eCommerce addon running as smoothly as possible under php7 and the prospective c5.6.4 on github.

For anyone else doing similar, here is a summary of the code changes I have found necessary. Line numbers may not be precise because the cumulative effect of changes can shift them down a bit.

core_commerce/libraries/discount/controller.php [controller.php at line 34, column 50]

public function setupAndRun($method=null) // php7, make optional

core_commerce/libraries/payment/controller.php [controller.php at line 19, column 50]

public function setupAndRun($method=null) // php7, make optional

core_commerce/libraries/shipping/controller.php [controller.php at line 25, column 50]

public function setupAndRun($method=null) // php7, make optional

core_commerce/models/attribute/categories/core_commerce_order.php [core_commerce_order.php at line 15, column 54]

public function load($akID, $loadBy = 'akID') // php7, match parameters

core_commerce/models/attribute/categories/core_commerce_product.php [core_commerce_product.php at line 55, column 54]

public function load($akID, $loadBy = 'akID') // php7, match parameters

core_commerce/models/attribute/categories/core_commerce_product_option.php [core_commerce_product_option.php at line 95, column 62]

public static function sortListByDisplayOrder($a, $b) // php7

[core_commerce_product_option.php at line 156, column 54]

public function load($akID, $loadBy = 'akID') // php7, match parameters

[core_commerce_product_option.php at line 166, column 55]

public function duplicate($product = array())  // php7 =array(). This is actually be a product object, the array() is misdirection to be compatible with the parent class.

core_commerce/models/attribute/types/product_price_adjustment_select/controller.php [controller.php at line 432, column 51]

public function validateKey($args = false) // php7, match parameters

[controller.php at line 523, column 79]

public function getSelectAttributeOptionDisplayValue($format = 'html') // php7, match parameters

[controller.php at line 584, column 63]

public static function getByValue($value, $ak = false) // php7, match parameters

This resolves everything in a benign way, except for one really bad parameter mismatch in core_commerce/models/attribute/types/product_price_adjustment_select/controller.php,

CoreCommerceProductAdjustmentSelectAttributeTypeOption::add

The solution to that is a bit more hacky, to suppress the warning. I found and adapted a trick on stack overflow. Rather than suppress all warnings, or all declaration warnings, I adapted this to catch the specific warning.

if (PHP_MAJOR_VERSION >= 7) {
    set_error_handler(function ($errno, $errstr) {
        if(strpos($errstr, 'Declaration of CoreCommerceProductAdjustmentSelectAttributeTypeOption::add') === 0){
            return true;
        }
    }, E_WARNING);
}

For convenience I currently have this code at the bottom of /config/site.php.

The snippet could be adapted to target other specific warnings, though it is always better to resolve the source of the problem.

I now have eCommerce running under php7 with Zone Based Shipping.