From 1a4eb8f45e287f59c0d5b2bfffe85a025bc4c8dc Mon Sep 17 00:00:00 2001 From: TheCoreDev Date: Tue, 26 Jan 2021 21:15:26 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20du=20module=20CadeauBienvenue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CadeauBienvenue/CadeauBienvenue.php | 55 +++++++++++ .../modules/CadeauBienvenue/Config/config.xml | 16 ++++ .../modules/CadeauBienvenue/Config/module.xml | 28 ++++++ .../EventListeners/NewCustomerListener.php | 93 +++++++++++++++++++ local/modules/CadeauBienvenue/I18n/en_US.php | 4 + local/modules/CadeauBienvenue/I18n/fr_FR.php | 4 + local/modules/CadeauBienvenue/Readme.md | 55 +++++++++++ local/modules/CadeauBienvenue/composer.json | 12 +++ .../email/default/code-promo-bienvenue.html | 23 +++++ .../email/default/code-promo-bienvenue.txt | 13 +++ .../email/custom/account_changed_by_admin.txt | 2 +- .../email/custom/account_created_by_admin.txt | 2 +- templates/email/custom/admin_password.txt | 2 +- .../email/custom/customer_confirmation.txt | 2 +- .../email/custom/default-html-layout.tpl | 2 +- .../email/custom/default-text-layout.tpl | 2 +- templates/email/custom/email-layout.tpl | 2 +- .../newsletter_subscription_confirmation.txt | 2 +- templates/email/custom/order_confirmation.txt | 2 +- templates/email/custom/order_notification.txt | 2 +- templates/email/custom/password.txt | 2 +- .../ajax/order-delivery-module-list.html | 2 +- .../custom/includes/addedToCart.html | 2 +- templates/frontOffice/custom/layout.tpl | 2 +- templates/pdf/custom/delivery.html | 2 +- templates/pdf/custom/invoice.html | 2 +- 26 files changed, 319 insertions(+), 16 deletions(-) create mode 100644 local/modules/CadeauBienvenue/CadeauBienvenue.php create mode 100644 local/modules/CadeauBienvenue/Config/config.xml create mode 100644 local/modules/CadeauBienvenue/Config/module.xml create mode 100644 local/modules/CadeauBienvenue/EventListeners/NewCustomerListener.php create mode 100644 local/modules/CadeauBienvenue/I18n/en_US.php create mode 100644 local/modules/CadeauBienvenue/I18n/fr_FR.php create mode 100644 local/modules/CadeauBienvenue/Readme.md create mode 100644 local/modules/CadeauBienvenue/composer.json create mode 100644 local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.html create mode 100644 local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.txt diff --git a/local/modules/CadeauBienvenue/CadeauBienvenue.php b/local/modules/CadeauBienvenue/CadeauBienvenue.php new file mode 100644 index 00000000..a82f1629 --- /dev/null +++ b/local/modules/CadeauBienvenue/CadeauBienvenue.php @@ -0,0 +1,55 @@ +findOneByName(self::MESSAGE_MAIL_CLIENT)) { + $message = new Message(); + + try { + $message + ->setName(self::MESSAGE_MAIL_CLIENT) + ->setHtmlTemplateFileName('code-promo-bienvenue.html') + ->setTextTemplateFileName('code-promo-bienvenue.txt') + ->setHtmlLayoutFileName('') + ->setTextLayoutFileName('') + ->setSecured(0) + ->setLocale('fr_FR') + ->setTitle('Mail envoyé à tout nouveau client, avec un code promo') + ->setSubject('Bienvenue chez AuxBieauxLegumes.fr - Code promo') + ->save(); + } catch (PropelException $e) { + Tlog::getInstance()->error($e->getMessage()); + } + } + } +} diff --git a/local/modules/CadeauBienvenue/Config/config.xml b/local/modules/CadeauBienvenue/Config/config.xml new file mode 100644 index 00000000..6da19621 --- /dev/null +++ b/local/modules/CadeauBienvenue/Config/config.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/local/modules/CadeauBienvenue/Config/module.xml b/local/modules/CadeauBienvenue/Config/module.xml new file mode 100644 index 00000000..70fc1add --- /dev/null +++ b/local/modules/CadeauBienvenue/Config/module.xml @@ -0,0 +1,28 @@ + + + CadeauBienvenue\CadeauBienvenue + + Generate a personal coupon for every new customer + + + Généré un code promotion personnel pour chaque nouveau client + + + en_US + fr_FR + + 1.0 + + + Laurent LE CORRE + laurent@thecoredev.fr + + + classic + 2.4.3 + other + 0 + 0 + diff --git a/local/modules/CadeauBienvenue/EventListeners/NewCustomerListener.php b/local/modules/CadeauBienvenue/EventListeners/NewCustomerListener.php new file mode 100644 index 00000000..cae495b5 --- /dev/null +++ b/local/modules/CadeauBienvenue/EventListeners/NewCustomerListener.php @@ -0,0 +1,93 @@ +request = $request; + $this->mailer = $mailer; + $this->dispatcher = $dispatcher; + } + + public static function getSubscribedEvents() + { + return array( + TheliaEvents::CUSTOMER_CREATEACCOUNT => array( + 'createAccount', 128 + ), + ); + } + + /** + * @param CustomerCreateOrUpdateEvent $event + * @param $eventName + * @param EventDispatcherInterface $dispatcher + */ + public function createAccount(CustomerCreateOrUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher) + { + $customer = $event->getCustomer(); + + $couponCode = substr(str_shuffle(md5(time())), 0, 12); + $discountAmount = ConfigQuery::create()->filterByName(CadeauBienvenue::VARIABLE_MONTANT_CODE_PROMO)->findOne()->getValue(); + $couponServiceId = 'thelia.coupon.type.remove_x_amount'; + $effects = [ 'amount' => $discountAmount]; + $dateExpiration = (new \DateTime())->add(new \DateInterval('P1Y')); // Expiration dans 1 an + + $couponEvent = new CouponCreateOrUpdateEvent( + $couponCode, // Code + $couponServiceId, // $serviceId + 'Offre de bienvenue', // $title + $effects, // $effects + '', // $shortDescription + sprintf('Offre de bienvenue pour %s %s',$customer->getFirstname(), $customer->getLastname()), // $description + true, // $isEnabled + $dateExpiration, // $expirationDate + false, // $isAvailableOnSpecialOffers + false, // $isCumulative + false, // $isRemovingPostage, + 1, // $maxUsage, + $customer->getLocale(), // $locale, + [], // $freeShippingForCountries, + [], // $freeShippingForMethods, + 1 // $perCustomerUsageCount, + ); + $this->dispatcher->dispatch(TheliaEvents::COUPON_CREATE, $couponEvent); + + // Envoyer le mail au client + $this->mailer->sendEmailToCustomer( + CadeauBienvenue::MESSAGE_MAIL_CLIENT, + $customer, + [ + 'customer_id' => $customer->getId(), + 'montant' => $discountAmount, + 'date_validite' => $dateExpiration, + 'code_promo' => $couponCode + ] + ); + + } + +} diff --git a/local/modules/CadeauBienvenue/I18n/en_US.php b/local/modules/CadeauBienvenue/I18n/en_US.php new file mode 100644 index 00000000..0b4fa142 --- /dev/null +++ b/local/modules/CadeauBienvenue/I18n/en_US.php @@ -0,0 +1,4 @@ + 'The displayed english string', +); diff --git a/local/modules/CadeauBienvenue/I18n/fr_FR.php b/local/modules/CadeauBienvenue/I18n/fr_FR.php new file mode 100644 index 00000000..37086245 --- /dev/null +++ b/local/modules/CadeauBienvenue/I18n/fr_FR.php @@ -0,0 +1,4 @@ + 'La traduction française de la chaine', +); diff --git a/local/modules/CadeauBienvenue/Readme.md b/local/modules/CadeauBienvenue/Readme.md new file mode 100644 index 00000000..2b5f9fff --- /dev/null +++ b/local/modules/CadeauBienvenue/Readme.md @@ -0,0 +1,55 @@ +# Cadeau Bienvenue + +Add a short description here. You can also add a screenshot if needed. + +## Installation + +### Manually + +* Copy the module into ```/local/modules/``` directory and be sure that the name of the module is CadeauBienvenue. +* Activate it in your thelia administration panel + +### Composer + +Add it in your main thelia composer.json file + +``` +composer require your-vendor/cadeau-bienvenue-module:~1.0 +``` + +## Usage + +Explain here how to use your module, how to configure it, etc. + +## Hook + +If your module use one or more hook, fill this part. Explain which hooks are used. + + +## Loop + +If your module declare one or more loop, describe them here like this : + +[loop name] + +### Input arguments + +|Argument |Description | +|--- |--- | +|**arg1** | describe arg1 with an exemple. | +|**arg2** | describe arg2 with an exemple. | + +### Output arguments + +|Variable |Description | +|--- |--- | +|$VAR1 | describe $VAR1 variable | +|$VAR2 | describe $VAR2 variable | + +### Exemple + +Add a complete exemple of your loop + +## Other ? + +If you have other think to put, feel free to complete your readme as you want. diff --git a/local/modules/CadeauBienvenue/composer.json b/local/modules/CadeauBienvenue/composer.json new file mode 100644 index 00000000..60bd3870 --- /dev/null +++ b/local/modules/CadeauBienvenue/composer.json @@ -0,0 +1,12 @@ +{ + "name": "your-vendor/cadeau-bienvenue-module", + "description": "CadeauBienvenue module for Thelia", + "license": "LGPL-3.0-or-later", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1" + }, + "extra": { + "installer-name": "CadeauBienvenue" + } +} \ No newline at end of file diff --git a/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.html b/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.html new file mode 100644 index 00000000..301d0f8d --- /dev/null +++ b/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.html @@ -0,0 +1,23 @@ +{extends file="email-layout.tpl"} + +{* Do not provide a "Open in browser" link *} +{block name="browser"}{/block} +{* No pre-header *} +{block name="pre-header"}{/block} + +{* Subject *} +{block name="email-subject"}Bienvenue chez AuxBieauxLegumes.fr - Code promo{/block} + +{* Title *} +{block name="email-title"}Bienvenue chez AuxBieauxLegumes.fr - Code promo{/block} + +{* Content *} +{block name="email-content"} +{loop type="customer" name="client" current="false" id=$customer_id}

Bonjour {$FIRSTNAME} {$LASTNAME},

{/loop} + +

Pour fêter votre arrivée sur notre site {$nom_site}, nous vous offrons un bon de réduction d'une valeur de {$montant}€, utilisable dès votre prochain achat ! +Ce bon est valable jusqu'au {format_date date={$date_validite} output="date"}.

+

Rendez-vous très bientôt sur {url path="/"}

+

Très cordialement,

+

{config key="store_name"}.

+{/block} diff --git a/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.txt b/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.txt new file mode 100644 index 00000000..36a19801 --- /dev/null +++ b/local/modules/CadeauBienvenue/templates/email/default/code-promo-bienvenue.txt @@ -0,0 +1,13 @@ +{loop type="customer" name="client" current="false" id=$customer_id}Bonjour {$FIRSTNAME} {$LASTNAME},{/loop} + +Pour fêter votre arrivée sur notre site {$nom_site}, nous vous offrons un bon de réduction d'une valeur de {$montant}€, utilisable dès votre prochain achat ! + +Votre avantage parrainage est une remise de {$label_promo} sur votre prochaine commande. +Profitez-en vite en indiquant lors de votre prochaine commande le code promotion {$code_promo}. +Ce bon est valable jusqu'au {format_date date=$date_validite format="d/m/Y"}. + +Rendez-vous très bientôt sur {url path="/"}. + +Très cordialement, + +{config key="store_name"}. diff --git a/templates/email/custom/account_changed_by_admin.txt b/templates/email/custom/account_changed_by_admin.txt index 9eb1ad8d..f3273c88 100644 --- a/templates/email/custom/account_changed_by_admin.txt +++ b/templates/email/custom/account_changed_by_admin.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {intl l="Hello,"} {intl l="Your account at %store_name has been changed by one of our managers." store_name={config key="store_name"}}. diff --git a/templates/email/custom/account_created_by_admin.txt b/templates/email/custom/account_created_by_admin.txt index cb8edd41..4bec08a6 100644 --- a/templates/email/custom/account_created_by_admin.txt +++ b/templates/email/custom/account_created_by_admin.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {intl l="Hello,"} {intl l="An account at %store_name has been created by one of our managers." store_name={config key="store_name"}}. diff --git a/templates/email/custom/admin_password.txt b/templates/email/custom/admin_password.txt index 7b40444d..63e0f573 100644 --- a/templates/email/custom/admin_password.txt +++ b/templates/email/custom/admin_password.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {intl l="Hello,"} {intl l="You have requested a new password for your administrator account at %store_name" store_name={config key="store_name"}}. diff --git a/templates/email/custom/customer_confirmation.txt b/templates/email/custom/customer_confirmation.txt index 91f2ac9a..3e9fe847 100644 --- a/templates/email/custom/customer_confirmation.txt +++ b/templates/email/custom/customer_confirmation.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {loop type="customer" name="confirmation" current=false id=$customer_id} {intl l="Welcome to %store," store={config key="store_name"}}
diff --git a/templates/email/custom/default-html-layout.tpl b/templates/email/custom/default-html-layout.tpl index 2e686044..ec72b3af 100644 --- a/templates/email/custom/default-html-layout.tpl +++ b/templates/email/custom/default-html-layout.tpl @@ -20,7 +20,7 @@ DO NOT DELETE THIS FILE, some plugins may use it. *} {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {default_locale locale={$locale}} {block name='message-body'}{$message_body nofilter}{/block} \ No newline at end of file diff --git a/templates/email/custom/default-text-layout.tpl b/templates/email/custom/default-text-layout.tpl index 715f1a8e..e6c5169d 100644 --- a/templates/email/custom/default-text-layout.tpl +++ b/templates/email/custom/default-text-layout.tpl @@ -20,7 +20,7 @@ DO NOT DELETE THIS FILE, some plugins may use it. *} {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {default_locale locale={$locale}} {block name='message-body'}{$message_body nofilter}{/block} \ No newline at end of file diff --git a/templates/email/custom/email-layout.tpl b/templates/email/custom/email-layout.tpl index 6677e3df..3863f917 100644 --- a/templates/email/custom/email-layout.tpl +++ b/templates/email/custom/email-layout.tpl @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {default_locale locale={$locale}} {declare_assets directory='assets'} {assign var="url_site" value="{config key="url_site"}"} diff --git a/templates/email/custom/newsletter_subscription_confirmation.txt b/templates/email/custom/newsletter_subscription_confirmation.txt index 58055837..8fdbe9d0 100644 --- a/templates/email/custom/newsletter_subscription_confirmation.txt +++ b/templates/email/custom/newsletter_subscription_confirmation.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {if $firstname || $lastname} {intl l="Dear %firstname %lastname," firstname=$firstname lastname=$lastname} {else} diff --git a/templates/email/custom/order_confirmation.txt b/templates/email/custom/order_confirmation.txt index 3d82c70e..c1a8f744 100644 --- a/templates/email/custom/order_confirmation.txt +++ b/templates/email/custom/order_confirmation.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {loop name="order.invoice" type="order" id=$order_id customer="*"} {intl l="Hello,"} diff --git a/templates/email/custom/order_notification.txt b/templates/email/custom/order_notification.txt index 95398070..3c5d1111 100644 --- a/templates/email/custom/order_notification.txt +++ b/templates/email/custom/order_notification.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {loop name="order.invoice" type="order" id=$order_id customer="*"} {intl l="Hello"} diff --git a/templates/email/custom/password.txt b/templates/email/custom/password.txt index 37ae8e87..e8e7916e 100644 --- a/templates/email/custom/password.txt +++ b/templates/email/custom/password.txt @@ -1,4 +1,4 @@ -{default_translation_domain domain='email.default'} +{default_translation_domain domain='email.custom'} {intl l="Hello,"} {intl l="You have requested a new password for your account at %store_name" store_name={config key="store_name"}}. diff --git a/templates/frontOffice/custom/ajax/order-delivery-module-list.html b/templates/frontOffice/custom/ajax/order-delivery-module-list.html index 7b5056ad..b8ffa438 100644 --- a/templates/frontOffice/custom/ajax/order-delivery-module-list.html +++ b/templates/frontOffice/custom/ajax/order-delivery-module-list.html @@ -1,5 +1,5 @@ {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain='fo.default'} +{default_translation_domain domain='fo.custom'} {form name="thelia.order.delivery"} diff --git a/templates/frontOffice/custom/includes/addedToCart.html b/templates/frontOffice/custom/includes/addedToCart.html index d677ec1d..0f57233f 100644 --- a/templates/frontOffice/custom/includes/addedToCart.html +++ b/templates/frontOffice/custom/includes/addedToCart.html @@ -1,7 +1,7 @@ {* This page should not replace the current previous URL *} {set_previous_url ignore_current="1"} -{default_translation_domain domain='fo.default'} +{default_translation_domain domain='fo.custom'} {loop type="product" name="add_product_to_cart" id={product attr="id"}}
diff --git a/templates/frontOffice/custom/layout.tpl b/templates/frontOffice/custom/layout.tpl index 730819e1..ec123cae 100644 --- a/templates/frontOffice/custom/layout.tpl +++ b/templates/frontOffice/custom/layout.tpl @@ -20,7 +20,7 @@ GNU General Public License : http://www.gnu.org/licenses/ {* Declare assets directory, relative to template base directory *} {declare_assets directory='assets/dist'} {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain='fo.default'} +{default_translation_domain domain='fo.custom'} {* -- Define some stuff for Smarty ------------------------------------------ *} {config_load file='variables.conf'} diff --git a/templates/pdf/custom/delivery.html b/templates/pdf/custom/delivery.html index bc5c0c73..9183aa79 100644 --- a/templates/pdf/custom/delivery.html +++ b/templates/pdf/custom/delivery.html @@ -10,7 +10,7 @@ /*************************************************************************************} {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain='pdf.default'} +{default_translation_domain domain='pdf.custom'} {literal}