create controller adding delivery module in session

This commit is contained in:
Manuel Raynaud
2013-09-06 19:29:19 +02:00
parent b067ef7dcc
commit 0aad4baf26
4 changed files with 21 additions and 11 deletions

View File

@@ -63,6 +63,7 @@
<!-- order management process --> <!-- order management process -->
<route id="order.delivery.add" path="/delivery/choose/{delivery_id}"> <route id="order.delivery.add" path="/delivery/choose/{delivery_id}">
<default key="_controller">Thelia\Controller\Front\DeliveryController::select</default> <default key="_controller">Thelia\Controller\Front\DeliveryController::select</default>
<requirement key="delivery_id">\d+</requirement>
</route> </route>
<!-- end order management process --> <!-- end order management process -->

View File

@@ -33,7 +33,7 @@ use Thelia\Tools\URL;
*/ */
class DeliveryController extends BaseFrontController class DeliveryController extends BaseFrontController
{ {
public function select() public function select($delivery_id)
{ {
if ($this->getSecurityContext()->hasCustomerUser() === false) { if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getInstance()->getIndexPage()); $this->redirect(URL::getInstance()->getIndexPage());
@@ -41,15 +41,16 @@ class DeliveryController extends BaseFrontController
$request = $this->getRequest(); $request = $this->getRequest();
$deliveryId = $request->query->get("delivery_id"); $deliveryModule = ModuleQuery::create()
->filterById($delivery_id)
->filterByActivate(1)
->findOne()
;
if($deliveryId) if ($deliveryModule) {
{ $request->getSession()->setDelivery($delivery_id);
$deliveryModule = ModuleQuery::create()->findPk($deliveryId); } else {
$this->pageNotFound();
if ($deliveryModule) {
$request->getSession()->setDelivery($deliveryId);
}
} }
} }
} }

View File

@@ -60,6 +60,9 @@ class Delivery extends BaseSpecificModule
$loopResultRow = new LoopResultRow($loopResult, $deliveryModule, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($loopResult, $deliveryModule, $this->versionable, $this->timestampable, $this->countable);
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace()); $moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
if($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
}
$moduleInstance = $moduleReflection->newInstance(); $moduleInstance = $moduleReflection->newInstance();
$moduleInstance->setRequest($this->request); $moduleInstance->setRequest($this->request);

View File

@@ -2,8 +2,13 @@
<ul> <ul>
{loop type="delivery" name="delivery.list"} {loop type="delivery" name="delivery.list"}
<li>id : #ID</li> <li>
<li>prix : #PRICE</li> <ul>
<li>id : {#ID}</li>
<li>prix : {#PRICE}</li>
<li>Choisir : <a href="{url path="/delivery/choose/{#ID}"}">Choisir</a></li>
</ul>
</li>
{/loop} {/loop}
</ul> </ul>