WIP
- Coupon : add rule input ajax controller
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*
|
||||
|
||||
1
templates/admin/default/coupon/rule-input-ajax.html
Normal file
1
templates/admin/default/coupon/rule-input-ajax.html
Normal file
@@ -0,0 +1 @@
|
||||
test
|
||||
Reference in New Issue
Block a user