Création du module CadeauBienvenue
This commit is contained in:
55
local/modules/CadeauBienvenue/CadeauBienvenue.php
Normal file
55
local/modules/CadeauBienvenue/CadeauBienvenue.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace CadeauBienvenue;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Module\BaseModule;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\Message;
|
||||
use Thelia\Model\MessageQuery;
|
||||
|
||||
|
||||
class CadeauBienvenue extends BaseModule
|
||||
{
|
||||
/** @var string */
|
||||
const DOMAIN_NAME = 'cadeaubienvenue';
|
||||
/** @var string */
|
||||
const VARIABLE_MONTANT_CODE_PROMO = 'cadeau_bienvenue.montant_coupon';
|
||||
/** @var string */
|
||||
const MESSAGE_MAIL_CLIENT = 'code_promo_nouveau_client';
|
||||
|
||||
|
||||
public function postActivation(ConnectionInterface $con = null)
|
||||
{
|
||||
if (null === MessageQuery::create()->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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
local/modules/CadeauBienvenue/Config/config.xml
Normal file
16
local/modules/CadeauBienvenue/Config/config.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<config xmlns="http://thelia.net/schema/dic/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<services>
|
||||
<service id="customer.creation.event" class="CadeauBienvenue\EventListeners\NewCustomerListener" scope="request">
|
||||
<argument type="service" id="request"/>
|
||||
<argument type="service" id="mailer"/>
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</config>
|
||||
28
local/modules/CadeauBienvenue/Config/module.xml
Normal file
28
local/modules/CadeauBienvenue/Config/module.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
|
||||
<fullnamespace>CadeauBienvenue\CadeauBienvenue</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Generate a personal coupon for every new customer</title>
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>Généré un code promotion personnel pour chaque nouveau client</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>1.0</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>Laurent LE CORRE</name>
|
||||
<email>laurent@thecoredev.fr</email>
|
||||
</author>
|
||||
</authors>
|
||||
<type>classic</type>
|
||||
<thelia>2.4.3</thelia>
|
||||
<stability>other</stability>
|
||||
<mandatory>0</mandatory>
|
||||
<hidden>0</hidden>
|
||||
</module>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace CadeauBienvenue\EventListeners;
|
||||
|
||||
use CadeauBienvenue\CadeauBienvenue;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
|
||||
class NewCustomerListener implements EventSubscriberInterface
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/** @var MailerFactory */
|
||||
protected $mailer;
|
||||
|
||||
/** @var EventDispatcherInterface */
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(Request $request, MailerFactory $mailer, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->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
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
4
local/modules/CadeauBienvenue/I18n/en_US.php
Normal file
4
local/modules/CadeauBienvenue/I18n/en_US.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return array(
|
||||
// 'an english string' => 'The displayed english string',
|
||||
);
|
||||
4
local/modules/CadeauBienvenue/I18n/fr_FR.php
Normal file
4
local/modules/CadeauBienvenue/I18n/fr_FR.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return array(
|
||||
// 'an english string' => 'La traduction française de la chaine',
|
||||
);
|
||||
55
local/modules/CadeauBienvenue/Readme.md
Normal file
55
local/modules/CadeauBienvenue/Readme.md
Normal file
@@ -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 ```<thelia_root>/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.
|
||||
12
local/modules/CadeauBienvenue/composer.json
Normal file
12
local/modules/CadeauBienvenue/composer.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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}<p>Bonjour {$FIRSTNAME} {$LASTNAME},</p>{/loop}
|
||||
|
||||
<p>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"}.</p>
|
||||
<p>Rendez-vous très bientôt sur <a href="{url path='/'}">{url path="/"}</a></p>
|
||||
<p>Très cordialement,</p>
|
||||
<p>{config key="store_name"}.</p>
|
||||
{/block}
|
||||
@@ -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"}.
|
||||
@@ -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"}}.
|
||||
|
||||
@@ -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"}}.
|
||||
|
||||
@@ -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"}}.
|
||||
|
||||
@@ -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"}}
|
||||
<br>
|
||||
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
@@ -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"}"}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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,"}
|
||||
|
||||
|
||||
@@ -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"}
|
||||
|
||||
|
||||
@@ -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"}}.
|
||||
|
||||
@@ -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"}
|
||||
|
||||
|
||||
@@ -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"}}
|
||||
<div class="clearfix">
|
||||
<table>
|
||||
|
||||
@@ -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'}
|
||||
|
||||
@@ -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}
|
||||
<style>
|
||||
h1, h2, h3, h4 {
|
||||
|
||||
@@ -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}
|
||||
<style>
|
||||
h1, h2, h3, h4 {
|
||||
|
||||
Reference in New Issue
Block a user