Prestashop: Allow dynamic lazy arrays properties

Created on 21 Dec 2018  路  3Comments  路  Source: PrestaShop/PrestaShop

@123monsite-regis has the following usecase: he receives aProductLazyArray from hook hookFilterSupplierContent and wishes to add a property to it, making it lazy as well

So this does not work:

public function hookFilterSupplierContent($params) {
        $params['object']->appendArray(array('MymoduleVars' => array('MyVAriable' => 'MyVAriable'));
}

Added data is not lazy

A solution would be to create a LazyArray able to use closures.

$myLazyArray = new AdvancedClosureLazyArray();
$myLazyArray->appendArray(array(
    'get_my_url' => function () use ($link) {
        return getPageLink('foo', true, null);
    }
));

And when calling $myLazyArray['get_my_url'] it would execute the closure then return the result

What do you think @jocel1 ? 馃槃

Bug CO

Most helpful comment

@123monsite-regis this feature will be available in 1.7.8 馃槉and you can use it in your shop now by using the code I built in https://github.com/PrestaShop/PrestaShop/pull/17419

All 3 comments

@123monsite-regis this feature will be available in 1.7.8 馃槉and you can use it in your shop now by using the code I built in https://github.com/PrestaShop/PrestaShop/pull/17419

thank you :)

Was this page helpful?
0 / 5 - 0 ratings