Merge branch 'master' into tax

Conflicts:
	templates/default_save/product.html
This commit is contained in:
Etienne Roudeix
2013-09-10 19:15:15 +02:00
46 changed files with 1550 additions and 751 deletions

View File

@@ -172,7 +172,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
TheliaEvents::COUPON_DISABLE => array("disable", 128),
TheliaEvents::COUPON_ENABLE => array("enable", 128),
TheliaEvents::COUPON_CONSUME => array("consume", 128),
TheliaEvents::COUPON_RULE_CREATE => array("createRule", 128),
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128),
TheliaEvents::COUPON_RULE_DELETE => array("deleteRule", 128)
);

View File

@@ -95,6 +95,9 @@
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}">
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
</route>
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update/">
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
</route>
@@ -189,11 +192,11 @@
<!-- attribute and feature routes management -->
<route id="admin.configuration.attribute" path="/admin/configuration/product_attributes">
<route id="admin.configuration.product-attribute.default" path="/admin/configuration/product-attributes">
<default key="_controller">Thelia\Controller\Admin\AttributeController::defaultAction</default>
</route>
<route id="admin.configuration.attribute.edit" path="/admin/configuration/product_attributes/update">
<route id="admin.configuration.product-attribute.edit" path="/admin/configuration/product-attributes/update">
<default key="_controller">Thelia\Controller\Admin\AttributeController::updateAction</default>
</route>

View File

@@ -203,8 +203,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
$validator['availableOperators'] = $translatedOperators;
$translatedInputs[$key] = $validator;
}
$validators = array();
$validators['inputs'] = $translatedInputs;
$validators['setOperators'] = $this->operators;
$validators['setValues'] = $this->values;
return $translatedInputs;
return $validators;
}
/**

View File

@@ -184,8 +184,9 @@ class CouponController extends BaseAdminController
);
/** @var CouponRuleInterface $rule */
foreach ($rules as $rule) {
foreach ($rules->getRules() as $rule) {
$args['rulesObject'][] = array(
'serviceId' => $rule->getServiceId(),
'name' => $rule->getName(),
'tooltip' => $rule->getToolTip(),
'validators' => $rule->getValidators()
@@ -201,13 +202,18 @@ class CouponController extends BaseAdminController
$args['availableCoupons'] = $this->getAvailableCoupons();
$args['availableRules'] = $this->getAvailableRules();
$args['urlAjaxGetRuleInput'] = $this->getRouteFromRouter(
'router.admin',
$args['urlAjaxGetRuleInput'] = $this->getRoute(
'admin.coupon.rule.input',
array('ruleId' => 'ruleId'),
Router::ABSOLUTE_URL
);
$args['urlAjaxUpdateRules'] = $this->getRoute(
'admin.coupon.rule.update',
array('couponId' => $couponId),
Router::ABSOLUTE_URL
);
$args['formAction'] = 'admin/coupon/update/' . $couponId;
return $this->render(
@@ -288,6 +294,8 @@ class CouponController extends BaseAdminController
);
}
// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules());
// Setup the object form
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
@@ -338,14 +346,16 @@ class CouponController extends BaseAdminController
{
$this->checkAuth('ADMIN', 'admin.coupon.read');
if (!$this->getRequest()->isXmlHttpRequest()) {
$this->redirect(
$this->getRoute(
'admin',
array(),
Router::ABSOLUTE_URL
)
);
if ($this->isDebug()) {
if (!$this->getRequest()->isXmlHttpRequest()) {
$this->redirect(
$this->getRoute(
'admin',
array(),
Router::ABSOLUTE_URL
)
);
}
}
/** @var ConstraintFactory $constraintFactory */
@@ -365,6 +375,102 @@ class CouponController extends BaseAdminController
);
}
/**
* Manage Coupons read display
*
* @param int $couponId Coupon id
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function updateRulesAction($couponId)
{
$this->checkAuth('ADMIN', 'admin.coupon.read');
if ($this->isDebug()) {
if (!$this->getRequest()->isXmlHttpRequest()) {
$this->redirect(
$this->getRoute(
'admin',
array(),
Router::ABSOLUTE_URL
)
);
}
}
$search = CouponQuery::create();
/** @var Coupon $coupon */
$coupon = $search->findOneById($couponId);
if (!$coupon) {
return $this->pageNotFound();
}
$rules = new CouponRuleCollection();
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$rulesReceived = json_decode($this->getRequest()->get('rules'));
foreach ($rulesReceived as $ruleReceived) {
var_dump('building ', $ruleReceived->values);
$rule = $constraintFactory->build(
$ruleReceived->serviceId,
(array) $ruleReceived->operators,
(array) $ruleReceived->values
);
$rules->add(clone $rule);
}
$coupon->setSerializedRules(
$constraintFactory->serializeCouponRuleCollection($rules)
);
$couponEvent = new CouponCreateOrUpdateEvent(
$coupon->getCode(),
$coupon->getTitle(),
$coupon->getAmount(),
$coupon->getType(),
$coupon->getShortDescription(),
$coupon->getDescription(),
$coupon->getIsEnabled(),
$coupon->getExpirationDate(),
$coupon->getIsAvailableOnSpecialOffers(),
$coupon->getIsCumulative(),
$coupon->getIsRemovingPostage(),
$coupon->getMaxUsage(),
$rules,
$coupon->getLocale()
);
$eventToDispatch = TheliaEvents::COUPON_RULE_UPDATE;
// Dispatch Event to the Action
$this->dispatch(
$eventToDispatch,
$couponEvent
);
$this->adminLogAppend(
sprintf(
'Coupon %s (ID %s) rules updated',
$couponEvent->getTitle(),
$couponEvent->getCoupon()->getId()
)
);
$cleanedRules = $this->cleanRuleForTemplate($rules);
return $this->render(
'coupon/rules',
array(
'couponId' => $couponId,
'rules' => $cleanedRules,
'urlEdit' => $couponId,
'urlDelete' => $couponId
)
);
}
/**
* Build a Coupon from its form
*
@@ -554,6 +660,21 @@ class CouponController extends BaseAdminController
return $cleanedRules;
}
/**
* @param $rules
* @return array
*/
protected function cleanRuleForTemplate($rules)
{
$cleanedRules = array();
/** @var $rule CouponRuleInterface */
foreach ($rules->getRules() as $rule) {
$cleanedRules[] = $rule->getToolTip();
}
return $cleanedRules;
}
// /**
// * Validation Rule creation
// *

View File

@@ -258,4 +258,14 @@ class BaseController extends ContainerAware
{
throw new NotFoundHttpException();
}
/**
* Check if environment is in debug mode
*
* @return bool
*/
protected function isDebug()
{
return $this->container->getParameter('kernel.debug');
}
}

View File

@@ -281,22 +281,6 @@ final class TheliaEvents
*/
const AFTER_CONSUME_COUPON = "action.after_consume_coupon";
/**
* Sent when attempting to create Coupon Rule
*/
const COUPON_RULE_CREATE = "action.create_coupon_rule";
/**
* Sent just before an attempt to create a Coupon Rule
*/
const BEFORE_COUPON_RULE_CREATE = "action.before_create_coupon_rule";
/**
* Sent just after an attempt to create a Coupon Rule
*/
const AFTER_COUPON_RULE_CREATE = "action.after_create_coupon_rule";
/**
* Sent when attempting to update Coupon Rule
*/

View File

@@ -24,6 +24,9 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -84,10 +87,27 @@ class Coupon extends BaseI18nLoop
$coupons = $this->search($search, $pagination);
$loopResult = new LoopResult();
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
/** @var Request $request */
$request = $this->container->get('request');
/** @var Lang $lang */
$lang = $request->getSession()->getLang();
/** @var MCoupon $coupon */
foreach ($coupons as $coupon) {
$loopResultRow = new LoopResultRow();
$rules = $constraintFactory->unserializeCouponRuleCollection(
$coupon->getSerializedRules()
);
$cleanedRules = array();
/** @var CouponRuleInterface $rule */
foreach ($rules->getRules() as $key => $rule) {
$cleanedRules[] = $rule->getToolTip();
}
$loopResultRow->set("ID", $coupon->getId())
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE", $locale)
@@ -95,13 +115,13 @@ class Coupon extends BaseI18nLoop
->set("TITLE", $coupon->getVirtualColumn('i18n_TITLE'))
->set("SHORT_DESCRIPTION", $coupon->getVirtualColumn('i18n_SHORT_DESCRIPTION'))
->set("DESCRIPTION", $coupon->getVirtualColumn('i18n_DESCRIPTION'))
->set("EXPIRATION_DATE", $coupon->getExpirationDate())
->set("EXPIRATION_DATE", $coupon->getExpirationDate($lang->getDateFormat()))
->set("USAGE_LEFT", $coupon->getMaxUsage())
->set("IS_CUMULATIVE", $coupon->getIsCumulative())
->set("IS_REMOVING_POSTAGE", $coupon->getIsRemovingPostage())
->set("IS_ENABLED", $coupon->getIsEnabled())
->set("AMOUNT", $coupon->getAmount())
->set("APPLICATION_CONDITIONS", $coupon->getRules());
->set("APPLICATION_CONDITIONS", $cleanedRules);
$loopResult->addRow($loopResultRow);
}

View File

@@ -82,19 +82,10 @@ class SmartyParser extends Smarty implements ParserInterface
// The default HTTP status
$this->status = 200;
$this->registerFilter('pre', array($this, "preThelia"));
$this->registerFilter('output', array($this, "removeBlankLines"));
$this->registerFilter('variable', array(__CLASS__, "theliaEscape"));
}
public function preThelia($tpl_source, \Smarty_Internal_Template $template)
{
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9_]*)(.*)}`', '{\$$1$2}', $tpl_source);
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
return $new_source;
}
public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
@@ -102,7 +93,7 @@ class SmartyParser extends Smarty implements ParserInterface
public static function theliaEscape($content, $smarty)
{
if(!is_object($content)) {
if(is_scalar($content)) {
return htmlspecialchars($content ,ENT_QUOTES, Smarty::$_CHARSET);
} else {
return $content;

View File

@@ -26,6 +26,7 @@ use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator;
/**
* Class CustomerCreation
@@ -43,55 +44,94 @@ class CustomerCreation extends BaseForm
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "firstname"
"label" => Translator::getInstance()->trans("First Name"),
"label_attr" => array(
"for" => "firstname"
)
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "lastname"
"label" => Translator::getInstance()->trans("Last Name"),
"label_attr" => array(
"for" => "lastname"
)
))
->add("address1", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "address"
"label_attr" => array(
"for" => "address"
),
"label" => Translator::getInstance()->trans("Street Address")
))
->add("address2", "text", array(
"label" => "Address Line 2"
"label" => Translator::getInstance()->trans("Address Line 2"),
"label_attr" => array(
"for" => "address2"
)
))
->add("address3", "text", array(
"label" => "Address Line 3"
"label" => Translator::getInstance()->trans("Address Line 3"),
"label_attr" => array(
"for" => "address3"
)
))
->add("company", "text", array(
"label" => Translator::getInstance()->trans("Company name"),
"label_attr" => array(
"for" => "company"
)
))
->add("phone", "text", array(
"label" => "phone"
"label" => Translator::getInstance()->trans("Phone"),
"label_attr" => array(
"for" => "phone"
)
))
->add("cellphone", "text", array(
"label" => "cellphone"
"label" => Translator::getInstance()->trans("Cellphone"),
"label_attr" => array(
"for" => "cellphone"
)
))
->add("zipcode", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "zipcode"
"label" => Translator::getInstance()->trans("Zip code"),
"label_attr" => array(
"for" => "zipcode"
)
))
->add("city", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "city"
"label" => Translator::getInstance()->trans("City"),
"label_attr" => array(
"for" => "city"
)
))
->add("country", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "country"
"label" => Translator::getInstance()->trans("Country"),
"label_attr" => array(
"for" => "country"
)
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "title"
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
"for" => "title"
)
))
->add("email", "email", array(
"constraints" => array(
@@ -104,9 +144,12 @@ class CustomerCreation extends BaseForm
)
))
),
"label" => "email"
"label" => Translator::getInstance()->trans("Email Address"),
"label_attr" => array(
"for" => "email"
)
))
->add("email_confirm", "email", array(
/* ->add("email_confirm", "email", array(
"constraints" => array(
new Constraints\Callback(array(
"methods" => array(
@@ -116,13 +159,16 @@ class CustomerCreation extends BaseForm
))
),
"label" => "email confirmation"
))
))*/
->add("password", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4)))
),
"label" => "password"
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array(
"for" => "password"
)
))
->add("password_confirm", "password", array(
"constraints" => array(
@@ -132,7 +178,10 @@ class CustomerCreation extends BaseForm
array($this, "verifyPasswordField")
)))
),
"label" => "password confirmation"
"label" => "Password confirmation",
"label_attr" => array(
"for" => "password_confirmation"
)
))
;