Search code examples
phppimcore

Export objects from class issue


I have a product export and I try to export all objects using my custom plugins. I'm using below method to load all objects

        $list = new Pimcore_Model_Object_Bodproduct();
        $list->setOrder ( "ASC" );
        $list->setOrderKey ( "o_id" );

        // Load all filtered objects - products
        $list->load ();

Then i'm using foreach loop to access the objects.

It's working fine. But the problem is it's taking lot of time to export. Is there any other solutions for this .. I mean instead of load() function, is there any other method is available?


Solution

  • You can use $list->loadIdList() to fetch only object IDs - which should be faster. Then you can call Object::getById($id) within loop to provide progress bar (assuming your script is launched in console).

    In fact this is what load() is doing internally, please see Object\Listing\Resource class

    Another option is to split load to many "pages" by calling $list->getItems($offset, $itemCountPerPage).