Initial Commit
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace DigressivePrice\Controller;
|
||||
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use DigressivePrice\Event\DigressivePriceEvent;
|
||||
use DigressivePrice\Event\DigressivePriceFullEvent;
|
||||
use DigressivePrice\Event\DigressivePriceIdEvent;
|
||||
use DigressivePrice\Form\CreateDigressivePriceForm;
|
||||
use DigressivePrice\Form\UpdateDigressivePriceForm;
|
||||
use DigressivePrice\Form\DeleteDigressivePriceForm;
|
||||
|
||||
/**
|
||||
* Class DigressivePriceController
|
||||
* Manage actions of DigressivePrice module
|
||||
*
|
||||
* @package DigressivePrice\Controller
|
||||
* @author Etienne PERRIERE <eperriere@openstudio.fr> - Nexxpix - OpenStudio
|
||||
*/
|
||||
class DigressivePriceController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DigressivePrice', AccessManager::CREATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Initialize vars
|
||||
$request = $this->getRequest();
|
||||
$cdpf = new CreateDigressivePriceForm($request);
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($cdpf);
|
||||
|
||||
// Dispatch create
|
||||
$event = new DigressivePriceEvent(
|
||||
$form->get('productId')->getData(),
|
||||
$form->get('discount')->getData(),
|
||||
$form->get('quantityFrom')->getData(),
|
||||
$form->get('quantityTo')->getData()
|
||||
);
|
||||
$this->dispatch('action.createDigressivePrice', $event);
|
||||
} catch (\Exception $e) {
|
||||
$this->setupFormErrorContext(
|
||||
"Add digressive price",
|
||||
$e instanceof FormValidationException ? $this->createStandardFormValidationErrorMessage($e) : $e->getMessage(),
|
||||
$cdpf,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generateRedirectFromRoute(
|
||||
'admin.products.update',
|
||||
array(
|
||||
'product_id' => $this->getRequest()->get('product_id'),
|
||||
'current_tab' => 'product_digressive_price'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DigressivePrice', AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Initialize vars
|
||||
$request = $this->getRequest();
|
||||
$udpf = new UpdateDigressivePriceForm($request);
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($udpf);
|
||||
|
||||
// Dispatch update
|
||||
$event = new DigressivePriceFullEvent(
|
||||
$form->get('id')->getData(),
|
||||
$form->get('productId')->getData(),
|
||||
$form->get('discount')->getData(),
|
||||
$form->get('quantityFrom')->getData(),
|
||||
$form->get('quantityTo')->getData()
|
||||
);
|
||||
$this->dispatch('action.updateDigressivePrice', $event);
|
||||
} catch (FormValidationException $e) {
|
||||
$this->setupFormErrorContext(
|
||||
"Add digressive price",
|
||||
$e instanceof FormValidationException ? $this->createStandardFormValidationErrorMessage($e) : $e->getMessage(),
|
||||
$udpf,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generateRedirectFromRoute(
|
||||
'admin.products.update',
|
||||
array(
|
||||
'product_id' => $this->getRequest()->get('product_id'),
|
||||
'current_tab' => 'product_digressive_price'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DigressivePrice', AccessManager::DELETE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Initialize vars
|
||||
$request = $this->getRequest();
|
||||
$ddpf = new DeleteDigressivePriceForm($request);
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($ddpf);
|
||||
|
||||
// Dispatch delete
|
||||
$event = new DigressivePriceIdEvent($form->get('id')->getData());
|
||||
$this->dispatch('action.deleteDigressivePrice', $event);
|
||||
} catch (FormValidationException $e) {
|
||||
$this->setupFormErrorContext(
|
||||
"Add digressive price",
|
||||
$e instanceof FormValidationException ? $this->createStandardFormValidationErrorMessage($e) : $e->getMessage(),
|
||||
$ddpf,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generateRedirectFromRoute(
|
||||
'admin.products.update',
|
||||
array(
|
||||
'product_id' => $this->getRequest()->get('product_id'),
|
||||
'current_tab' => 'product_digressive_price'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace DigressivePrice\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Controller\Front\BaseFrontController;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
|
||||
/**
|
||||
* Class DigressivePriceFrontController
|
||||
* @package DigressivePrice\Controller
|
||||
*/
|
||||
class DigressivePriceFrontController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateTableAction($pseId)
|
||||
{
|
||||
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($pseId)) {
|
||||
|
||||
return $this->render(
|
||||
'digressive-price/product-details-bottom',
|
||||
[
|
||||
'pse_id' => $pse->getId(),
|
||||
'product_id' => $pse->getProductId()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return new Response('');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user