Skip to content

Commit

Permalink
Fix last issues + implement export
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Rolland authored and Matthieu Rolland committed Sep 14, 2023
1 parent bd3f85c commit d6be6ab
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
use AttributeGroup;
use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Adapter\Domain\AbstractObjectModelHandler;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\AddAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\CommandHandler\AddAttributeGroupHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupId;

/**
* Handles adding of attribute groups using legacy logic.
*/
#[AsCommandHandler]
final class AddAttributeGroupHandler extends AbstractObjectModelHandler implements AddAttributeGroupHandlerInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Adapter\Domain\AbstractObjectModelHandler;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\CommandHandler\EditAttributeGroupHandlerInterface;

/**
* Handles editing of attribute groups using legacy logic.
*/
#[AsCommandHandler]
final class EditAttributeGroupHandler extends AbstractObjectModelHandler implements EditAttributeGroupHandlerInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
namespace PrestaShop\PrestaShop\Adapter\AttributeGroup\QueryHandler;

use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsQueryHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Query\GetAttributeGroupForEditing;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryHandler\GetAttributeGroupForEditingHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryResult\EditableAttributeGroup;

/**
* Handles query which gets attribute group for editing
*/
#[AsQueryHandler]
final class GetAttributeGroupForEditingHandler implements GetAttributeGroupForEditingHandlerInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ protected function getGridActions()
],
])
)
->add(
(new LinkGridAction('export'))
->setName($this->trans('Export', [], 'Admin.Actions'))
->setIcon('cloud_download')
->setOptions([
'route' => 'admin_attribute_groups_export',
])
)
->add((new SimpleGridAction('common_refresh_list'))
->setName($this->trans('Refresh list', [], 'Admin.Advparameters.Feature'))
->setIcon('refresh')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdaterInterface;
use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactoryInterface;
use PrestaShop\PrestaShop\Core\Search\Filters\AttributeGroupFilters;
use PrestaShopBundle\Component\CsvResponse;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -131,6 +132,7 @@ public function editAction(Request $request, int $attributeGroupId): Response
$attributeFormHandler = $this->get('PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Handler\AttributeGroupFormHandler');

$attributeGroupForm = $attributeGroupFormBuilder->getFormFor($attributeGroupId);

$attributeGroupForm->handleRequest($request);

try {
Expand Down Expand Up @@ -169,14 +171,36 @@ public function editAction(Request $request, int $attributeGroupId): Response
* )
*
* @param int $attributeGroupId
* @param AttributeGroupFilters $filters
*
* @return RedirectResponse
* @return CsvResponse
*/
public function exportAction(int $attributeGroupId)
public function exportAction(AttributeGroupFilters $filters): CsvResponse
{
//@todo: implement in antoher pr
return $this->redirectToRoute('admin_attribute_groups_index');
$filters = new AttributeGroupFilters(['limit' => null] + $filters->all());
$attributeGroupGridFactory = $this->get('prestashop.core.grid.factory.attribute_group');
$attributeGroupGrid = $attributeGroupGridFactory->getGrid($filters);

$headers = [
'id_attribute_group' => $this->trans('ID', 'Admin.Global'),
'name' => $this->trans('Name', 'Admin.Global'),
'position' => $this->trans('Position', 'Admin.Global'),
];

$data = [];

foreach ($attributeGroupGrid->getData()->getRecords()->all() as $record) {
$data[] = [
'id_attribute_group' => $record['id_attribute_group'],
'name' => $record['name'],
'position' => $record['position'],
];
}

return (new CsvResponse())
->setData($data)
->setHeadersData($headers)
->setFileName('attribute_group_' . date('Y-m-d_His') . '.csv');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ services:

PrestaShop\PrestaShop\Adapter\AttributeGroup\CommandHandler\AddAttributeGroupHandler:
autowire: true
tags:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\AddAttributeGroupCommand
autoconfigure: true

PrestaShop\PrestaShop\Adapter\AttributeGroup\CommandHandler\EditAttributeGroupHandler:
autowire: true
tags:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand
autoconfigure: true

PrestaShop\PrestaShop\Adapter\AttributeGroup\QueryHandler\GetAttributeGroupForEditingHandler:
autowire: true
tags:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Query\GetAttributeGroupForEditing
autoconfigure: true

PrestaShop\PrestaShop\Adapter\AttributeGroup\AttributeGroupViewDataProvider:
arguments:
Expand Down

0 comments on commit d6be6ab

Please sign in to comment.