I want to implement a CSV export from Shopware 6 admin. I have a button, want to open a new window and get a CSV file.
I implemented a controller:
/**
* @Route(
* "/api/winkelwagen/export/csv/{id}",
* methods={"GET"},
* defaults={"auth_required"=true, "_routeScope"={"api"}}
* )
*/
public function export(string $id, Context $context, Request $request): Response
{
/** @var PromotionEntity $promo */
$response->setContent('csv file');
return $response;
}
But to call this controller, you need to be logged in which totally make sense.
My button in the administration currently opens a new window and opens the page:
window.open('http://www.fabian-blechschmidt.de', '_blank');
Which of course doesn't work with the api url, because you needs to be authenticated.
So my question is: How do I implement this authentication and get a CSV file in the backend? :-)
Maybe my approach is totally broken - happy to get a better idea!