Notable changes in PrestaShop 1.7.5

LazyArrays

Starting with PrestaShop 1.7.5, the business objects (Product, Order…) available on the front-office are LazyArray instances. If your module relies on data available in the hook parameters or in the template, you may be concerned by this update.

They used to be arrays with all the data available. This change has been introduced to load the needed properties of an object only when requested, and globally improve the performance of the front-office.

Getting properties from the object should not change between first versions of PS 1.7 and 1.7.5.

However it appeared that some modules, especially the ones with a high compatibility range like PrestaShop 1.6 & 1.7, apply an array cast when the variable in not an array. Casting these variables as arrays on PS 1.7.5+ will throw notices when getting their properties.

1.6 1.7.0+ 1.7.5+
Variable type / class ObjectModel array PrestaShop\PrestaShop\Adapter\Presenter\AbstractLazyArray
Getting a property {(array)$var}['id'] or $var->id $var['id'] $var['id'] or $var->id

Applying an (array) cast is valid only when you have a ObjectModel instance, for instance Product. Otherwise, you already have an array-compliant variable.

public function hookdisplayFooterProduct($params)
{
    /*
    * Depending on the PrestaShop you run, the $product type won't be the same.
    * On PrestaShop 1.7, it can be directly used as an array.
    * 
    * However, if the module is also compatible with PrestaShop 1.6, 1.5...
    * an ObjectModel class will be returned.
    * Casting it as an array *in this specific situation* will allow to cover all cases.
    */
    $product = $params['product'];
    if ($product instanceof Product /* or ObjectModel */) {
        $product = (array) $product;
    }

    // Getting product details.
    echo $product['id'];
}

Links: