|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ColissimoLabel\Controller\Admin; |
| 4 | + |
| 5 | +use ColissimoLabel\Model\ColissimoLabelProductCustoms; |
| 6 | +use ColissimoLabel\Model\ColissimoLabelProductCustomsQuery; |
| 7 | +use Symfony\Component\HttpFoundation\RedirectResponse; |
| 8 | +use Symfony\Component\HttpFoundation\Response; |
| 9 | +use Symfony\Component\Routing\Annotation\Route; |
| 10 | +use Thelia\Controller\Admin\BaseAdminController; |
| 11 | +use Thelia\Core\HttpFoundation\Request; |
| 12 | +use Thelia\Core\Security\AccessManager; |
| 13 | +use Thelia\Core\Security\Resource\AdminResources; |
| 14 | +use Thelia\Tools\URL; |
| 15 | + |
| 16 | +#[Route('/admin/module/ColissimoLabel/product-customs', name: 'colissimo_label_product_customs_')] |
| 17 | +class ProductCustomsController extends BaseAdminController |
| 18 | +{ |
| 19 | + #[Route('/save', name: 'save', methods: ['POST'])] |
| 20 | + public function saveAction(Request $request): Response |
| 21 | + { |
| 22 | + if (null !== $response = $this->checkAuth([AdminResources::PRODUCT], ['ColissimoLabel'], AccessManager::UPDATE)) { |
| 23 | + return $response; |
| 24 | + } |
| 25 | + |
| 26 | + $productId = (int) $request->request->get('product_id'); |
| 27 | + $hsCode = trim((string) $request->request->get('hs_code', '')); |
| 28 | + |
| 29 | + if ($productId <= 0) { |
| 30 | + return $this->errorPage('Missing product_id', 400); |
| 31 | + } |
| 32 | + |
| 33 | + $customs = ColissimoLabelProductCustomsQuery::create()->findOneByProductId($productId) |
| 34 | + ?? (new ColissimoLabelProductCustoms())->setProductId($productId); |
| 35 | + |
| 36 | + $customs->setHsCode($hsCode)->save(); |
| 37 | + |
| 38 | + return new RedirectResponse( |
| 39 | + URL::getInstance()->absoluteUrl( |
| 40 | + '/admin/products/update', |
| 41 | + ['product_id' => $productId, 'current_tab' => 'colissimo_label_product_customs'] |
| 42 | + ) |
| 43 | + ); |
| 44 | + } |
| 45 | +} |
0 commit comments