- Coupon : add rule input ajax controller
This commit is contained in:
gmorel
2013-09-09 10:03:00 +02:00
parent 447488f063
commit 2d6787e588
5 changed files with 59 additions and 1 deletions

View File

@@ -221,7 +221,7 @@
<service id="thelia.coupon.manager" class="Thelia\Coupon\CouponManager">
<argument type="service" id="thelia.adapter" />
</service>
<service id="thelia.constraint.manager" class="Thelia\Constraint\ConstraintManager">
<service id="thelia.constraint.factory" class="Thelia\Constraint\ConstraintFactory">
<argument type="service" id="service_container" />
</service>
<service id="thelia.constraint.rule.available_for_x_articles" class="Thelia\Constraint\Rule\AvailableForXArticlesManager">

View File

@@ -84,6 +84,9 @@
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
</route>
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}">
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
</route>

View File

@@ -140,4 +140,23 @@ class ConstraintFactory
return $rule;
}
/**
* Get Coupon Rule inputs from serviceId
*
* @param string $ruleServiceId Rule class name
*
* @return array Ready to be drawn rule inputs
*/
public function getInputs($ruleServiceId)
{
if (!$this->container->has($ruleServiceId)) {
return false;
}
/** @var CouponRuleInterface $rule */
$rule = $this->container->get($ruleServiceId);
return $rule->getValidators();
}
}

View File

@@ -24,6 +24,8 @@
namespace Thelia\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\ConstraintFactoryTest;
use Thelia\Constraint\Rule\AvailableForTotalAmount;
use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Constraint\Validator\PriceParam;
@@ -311,6 +313,39 @@ class CouponController extends BaseAdminController
return $this->render('coupon-read', array('couponId' => $couponId));
}
/**
* Manage Coupons read display
*
* @param int $couponId Coupon Id
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getRuleInputAction($ruleId)
{
$this->checkAuth('ADMIN', 'admin.coupon.read');
// @todo uncomment
// if (!$this->getRequest()->isXmlHttpRequest()) {
// $this->redirect('index');
// }
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$inputs = $constraintFactory->getInputs($ruleId);
if (!$inputs) {
return $this->pageNotFound();
}
return $this->render(
'coupon/rule-input-ajax',
array(
'ruleId' => $ruleId,
'inputs' => $inputs
)
);
}
/**
* Build a Coupon from its form
*

View File

@@ -0,0 +1 @@
test