From 968c372a5f153b0b347653d270af2bbda2971918 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 28 Oct 2013 12:36:07 +0100 Subject: [PATCH 1/6] add some info in addresses list --- templates/admin/default/customer-edit.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 71c6b8695..f8c3ebae7 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -161,6 +161,10 @@ {$ADDRESS1}
{$ADDRESS2}
{$ADDRESS3}
+ {$ZIPCODE} {$CITY}
+ {loop name="address.country" type="country" id=$COUNTRY} + {$TITLE}
+ {/loop} {if $PHONE} P: {$PHONE}
{/if} From c1e792d5b1f848405941f8f2cf31d56e2a36f189 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 28 Oct 2013 15:39:59 +0100 Subject: [PATCH 2/6] format customer address list --- templates/admin/default/customer-edit.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 71c6b8695..eba0139c0 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -158,14 +158,14 @@
{loop name="address.title" type="title" id=$TITLE}{$SHORT}{/loop} {$FIRSTNAME} {$LASTNAME}
- {$ADDRESS1}
- {$ADDRESS2}
- {$ADDRESS3}
+ {$ADDRESS1} + {if $ADDRESS2}
{$ADDRESS2}{/if} + {if $ADDRESS3}
{$ADDRESS3}{/if} {if $PHONE} - P: {$PHONE}
+
P:{$PHONE} {/if} {if $CELLPHONE} - P: {$CELLPHONE} +
P:{$CELLPHONE} {/if}
From 1c3aeb969d05149e25c2647704a6b88e9dc7b25e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 28 Oct 2013 15:42:34 +0100 Subject: [PATCH 3/6] select correct country in selectbox on customer edit page --- templates/admin/default/customer-edit.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 0507e18f7..370fe11f3 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -124,7 +124,7 @@ From 1e65ad8cf39b63aab717ea265e0b8afad42935dc Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 28 Oct 2013 16:10:06 +0100 Subject: [PATCH 4/6] add shim and respond in backoffice --- templates/admin/default/admin-layout.tpl | 8 ++++++++ templates/admin/default/assets/js/libs/respond.min.js | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100755 templates/admin/default/assets/js/libs/respond.min.js diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index 559395159..d2081d829 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -39,6 +39,14 @@ {* Modules css are included here *} {module_include location='head_css'} + + {* HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries *} + diff --git a/templates/admin/default/assets/js/libs/respond.min.js b/templates/admin/default/assets/js/libs/respond.min.js new file mode 100755 index 000000000..e3dc2c0d6 --- /dev/null +++ b/templates/admin/default/assets/js/libs/respond.min.js @@ -0,0 +1,6 @@ +/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ +/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ +window.matchMedia=window.matchMedia||function(a){"use strict";var c,d=a.documentElement,e=d.firstElementChild||d.firstChild,f=a.createElement("body"),g=a.createElement("div");return g.id="mq-test-1",g.style.cssText="position:absolute;top:-100em",f.style.background="none",f.appendChild(g),function(a){return g.innerHTML='­',d.insertBefore(f,e),c=42===g.offsetWidth,d.removeChild(f),{matches:c,media:a}}}(document); + +/*! Respond.js v1.3.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ +(function(a){"use strict";function x(){u(!0)}var b={};if(a.respond=b,b.update=function(){},b.mediaQueriesSupported=a.matchMedia&&a.matchMedia("only all").matches,!b.mediaQueriesSupported){var q,r,t,c=a.document,d=c.documentElement,e=[],f=[],g=[],h={},i=30,j=c.getElementsByTagName("head")[0]||d,k=c.getElementsByTagName("base")[0],l=j.getElementsByTagName("link"),m=[],n=function(){for(var b=0;l.length>b;b++){var c=l[b],d=c.href,e=c.media,f=c.rel&&"stylesheet"===c.rel.toLowerCase();d&&f&&!h[d]&&(c.styleSheet&&c.styleSheet.rawCssText?(p(c.styleSheet.rawCssText,d,e),h[d]=!0):(!/^([a-zA-Z:]*\/\/)/.test(d)&&!k||d.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&m.push({href:d,media:e}))}o()},o=function(){if(m.length){var b=m.shift();v(b.href,function(c){p(c,b.href,b.media),h[b.href]=!0,a.setTimeout(function(){o()},0)})}},p=function(a,b,c){var d=a.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),g=d&&d.length||0;b=b.substring(0,b.lastIndexOf("/"));var h=function(a){return a.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+b+"$2$3")},i=!g&&c;b.length&&(b+="/"),i&&(g=1);for(var j=0;g>j;j++){var k,l,m,n;i?(k=c,f.push(h(a))):(k=d[j].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1,f.push(RegExp.$2&&h(RegExp.$2))),m=k.split(","),n=m.length;for(var o=0;n>o;o++)l=m[o],e.push({media:l.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/)&&RegExp.$2||"all",rules:f.length-1,hasquery:l.indexOf("(")>-1,minw:l.match(/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:l.match(/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},s=function(){var a,b=c.createElement("div"),e=c.body,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",e||(e=f=c.createElement("body"),e.style.background="none"),e.appendChild(b),d.insertBefore(e,d.firstChild),a=b.offsetWidth,f?d.removeChild(e):e.removeChild(b),a=t=parseFloat(a)},u=function(b){var h="clientWidth",k=d[h],m="CSS1Compat"===c.compatMode&&k||c.body[h]||k,n={},o=l[l.length-1],p=(new Date).getTime();if(b&&q&&i>p-q)return a.clearTimeout(r),r=a.setTimeout(u,i),void 0;q=p;for(var v in e)if(e.hasOwnProperty(v)){var w=e[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?t||s():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?t||s():1)),w.hasquery&&(z&&A||!(z||m>=x)||!(A||y>=m))||(n[w.media]||(n[w.media]=[]),n[w.media].push(f[w.rules]))}for(var C in g)g.hasOwnProperty(C)&&g[C]&&g[C].parentNode===j&&j.removeChild(g[C]);for(var D in n)if(n.hasOwnProperty(D)){var E=c.createElement("style"),F=n[D].join("\n");E.type="text/css",E.media=D,j.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(c.createTextNode(F)),g.push(E)}},v=function(a,b){var c=w();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))},w=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}();n(),b.update=n,a.addEventListener?a.addEventListener("resize",x,!1):a.attachEvent&&a.attachEvent("onresize",x)}})(this); From 7a2469cdc868fcbb1e966adb2a018322dcda85ea Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 28 Oct 2013 16:55:07 +0100 Subject: [PATCH 5/6] allow to create a customer in bakcoffice --- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ .../Controller/Admin/CustomerController.php | 54 ++++++++++++++++++- core/lib/Thelia/Model/Customer.php | 1 + core/lib/Thelia/Tools/Password.php | 54 +++++++++++++++++++ templates/admin/default/customers.html | 12 +++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 core/lib/Thelia/Tools/Password.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 259c0f54a..dc5a2c522 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -114,6 +114,10 @@ Thelia\Controller\Admin\CustomerController::deleteAction + + Thelia\Controller\Admin\CustomerController::createAction + + diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index df75333c8..814008b7a 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -29,10 +29,12 @@ use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\AccessManager; +use Thelia\Form\CustomerCreateForm; use Thelia\Form\CustomerUpdateForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Model\CustomerQuery; use Thelia\Core\Translation\Translator; +use Thelia\Tools\Password; /** * Class CustomerController @@ -102,7 +104,7 @@ class CustomerController extends BaseAdminController } if ($message !== false) { - \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message)); + \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer update process : %s.", $message)); $customerUpdateForm->setErrorMessage($message); @@ -117,6 +119,56 @@ class CustomerController extends BaseAdminController )); } + public function createAction() + { + if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::CREATE)) return $response; + + $message = null; + + $customerCreateForm = new CustomerCreateForm($this->getRequest()); + + try { + + $form = $this->validateForm($customerCreateForm); + + $data = $form->getData(); + $data["password"] = Password::generateRandom(); + + $event = $this->createEventInstance($form->getData()); + + + + $this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $event); + + $successUrl = $customerCreateForm->getSuccessUrl(); + + $successUrl = str_replace('_ID_', $event->getCustomer()->getId(), $successUrl); + + $this->redirect($successUrl); + + + }catch (FormValidationException $e) { + $message = sprintf("Please check your input: %s", $e->getMessage()); + } catch (PropelException $e) { + $message = $e->getMessage(); + } catch (\Exception $e) { + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile()); + } + + if ($message !== false) { + \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer creation process : %s.", $message)); + + $customerCreateForm->setErrorMessage($message); + + $this->getParserContext() + ->addForm($customerCreateForm) + ->setGeneralError($message) + ; + } + + return $this->render("customers", array("display_customer" => 20)); + } + public function deleteAction() { if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::DELETE)) return $response; diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index 230023410..ffdc316de 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -79,6 +79,7 @@ class Customer extends BaseCustomer implements UserInterface $address = new Address(); $address + ->setLabel("default") ->setCompany($company) ->setTitleId($titleId) ->setFirstname($firstname) diff --git a/core/lib/Thelia/Tools/Password.php b/core/lib/Thelia/Tools/Password.php new file mode 100644 index 000000000..dbb4cf8cb --- /dev/null +++ b/core/lib/Thelia/Tools/Password.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tools; + + +/** + * Class Password + * @package Thelia\Tools + * @author Manuel Raynaud + */ +class Password +{ + + private static function randgen($letter, $length) { + + return substr(str_shuffle($letter), 0, $length); + } + + /** + * generate a Random password with defined length + * + * @param int $length + * @return mixed + */ + public static function generateRandom($length = 8){ + + $letter = "abcdefghijklmnopqrstuvwxyz"; + $letter .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $letter .= "0123456789"; + + return self::randgen($letter, $length); + } +} \ No newline at end of file diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index 81a60fdf3..6ae0caa0c 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -166,6 +166,18 @@ {/form_field} + {form_field form=$form field="password"} + + {/form_field} + + {form_field form=$form field="password_confirm"} + + {/form_field} + + {form_field form=$form field="agreed"} + + {/form_field} + {form_field form=$form field='company'}
From c74422f5dc446c7097a9828181dcd0eef5b4f076 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 29 Oct 2013 15:56:03 +0100 Subject: [PATCH 6/6] implement module inclusion --- .../lib/Thelia/Command/BaseModuleGenerate.php | 9 ++++---- .../Core/Template/Smarty/Plugins/Module.php | 23 +++++++++++++++---- core/lib/Thelia/Model/Module.php | 5 ++++ core/lib/Thelia/Model/ModuleQuery.php | 19 ++++++++++++--- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Command/BaseModuleGenerate.php b/core/lib/Thelia/Command/BaseModuleGenerate.php index b26db435b..1a27d9e4c 100755 --- a/core/lib/Thelia/Command/BaseModuleGenerate.php +++ b/core/lib/Thelia/Command/BaseModuleGenerate.php @@ -35,13 +35,14 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand protected $moduleDirectory; protected $reservedKeyWords = array( - "thelia" + 'thelia' ); protected $neededDirectories = array( - "Config", - "Model", - "Loop" + 'Config', + 'Model', + 'Loop', + 'AdminModule' ); protected function verifyExistingModule() diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php index 52feae096..1c6ab4fd1 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php @@ -25,6 +25,7 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Model\ModuleQuery; class Module extends AbstractSmartyPlugin { @@ -32,13 +33,27 @@ class Module extends AbstractSmartyPlugin * Process theliaModule template inclusion function * * @param unknown $params - * @param unknown $smarty + * @param \Smarty_Internal_Template $template + * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty + * * @return string */ - public function theliaModule($params, &$smarty) + public function theliaModule($params, \Smarty_Internal_Template $template) { - // TODO - return ""; + $content = null; + if (array_key_exists('location', $params)) { + $location = $params['location']; + $modules = ModuleQuery::getActivated(); + + foreach ($modules as $module) { + + $file = THELIA_MODULE_DIR . "/". ucfirst($module->getCode()) . "/ModuleAdmin/".$location.".html"; + if(file_exists($file)) { + $content .= file_get_contents($file); + } + } + } + return $template->fetch(sprintf("string:%s", $content)); } /** diff --git a/core/lib/Thelia/Model/Module.php b/core/lib/Thelia/Model/Module.php index b7fb2a443..c9ccd5f8d 100755 --- a/core/lib/Thelia/Model/Module.php +++ b/core/lib/Thelia/Model/Module.php @@ -2,8 +2,13 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\Module as BaseModule; class Module extends BaseModule { + public function postSave(ConnectionInterface $con = null) + { + ModuleQuery::resetActivated(); + } } diff --git a/core/lib/Thelia/Model/ModuleQuery.php b/core/lib/Thelia/Model/ModuleQuery.php index fdfe502a4..aaf2092e6 100755 --- a/core/lib/Thelia/Model/ModuleQuery.php +++ b/core/lib/Thelia/Model/ModuleQuery.php @@ -16,13 +16,26 @@ use Thelia\Model\Base\ModuleQuery as BaseModuleQuery; * */ class ModuleQuery extends BaseModuleQuery { + + protected static $activated = null; /** * @return array|mixed|\PropelObjectCollection */ public static function getActivated() { - return self::create() - ->filterByActivate(1) - ->find(); + if(null === self::$activated) { + self::$activated = self::create() + ->filterByActivate(1) + ->find(); + } + + return self::$activated; } + + public static function resetActivated() + { + self::$activated = null; + } + + } // ModuleQuery