Exporting one to many relationship on sonata admin

怎甘沉沦 提交于 2019-12-05 10:42:16

There is another work around you can add a property in your entity which will get all entry listing related to that and in getter function return __toString() of related ones, I had the same scenario for orders and also need the list if products associated with order so i have done it this way by creating exportProducts in orders entity

protected $exportProducts;

public function getExportProducts()
{
    $exportProducts = array();
    $i = 1;
    foreach ($this->getItems() as $key => $val) {
        $exportProducts[] = $i . 
           ') Name:' . $val->getProduct()->__toString()() . 
           ' Size:' . $val->getProductsize() .
           .../** Other properties */;
        $i++;
    }
    return $this->exportProducts = join(' , ', $exportProducts);
}

And in order admin class i defined exportProducts property in getExportFields() as

public  function getExportFields(){
    return array(
        'Products'=>'exportProducts',
         ....// Other properties
        );
}

In downloaded csv each order contains the list of products under Products cell as comma separated list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!