Skip to content

Commit

Permalink
Suggest unloçgged users to login instead of showing form
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalamon committed Mar 13, 2024
1 parent cca4336 commit 2644b6d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
config.xml
views/img/quotation.jpg
*.xml
views/quotation.jpg
10 changes: 8 additions & 2 deletions controllers/front/quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ private function triggerGtmTag($quoteId)
(int) $quote->id_currency
);
$dataForGTM = [
'quoteEvent' => $this->l('quotation'),
'quoteEvent' => 'requestForQuote',
'quoteId' => (int) $quote->id,
'quoteIdCustomer' => (int) $quote->id_customer,
'quoteProducts' => $quoteDetails,
'quoteCustomer' => $quoteCustomer,
'quoteCurrency' => $quoteCurrency,
'quoteCurrency' => $quoteCurrency->name,
'quoteShopName' => Configuration::get('PS_SHOP_NAME'),
];
return $dataForGTM;
Expand Down Expand Up @@ -535,6 +535,12 @@ private function setCartAsQuote(): int

private function renderModal()
{
$suggestLogIn = Configuration::get('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED');
if ((bool) $suggestLogIn === true) {
$this->context->smarty->assign(array(
'suggestLogIn' => $suggestLogIn,
));
}
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/front/modal.tpl');
}
}
44 changes: 42 additions & 2 deletions everpsquotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
{
$this->name = 'everpsquotation';
$this->tab = 'payments_gateways';
$this->version = '5.0.3';
$this->version = '5.1.0';
$this->author = 'Team Ever';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -483,6 +483,26 @@ protected function getConfigForm()
],
],
],
[
'type' => 'switch',
'label' => $this->l('Suggest unlogged users to log in ?'),
'desc' => $this->l('Suggests people who are not logged in to log in or create an account'),
'hint' => $this->l('Else a custom modal will be shown'),
'name' => 'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'categories',
'name' => 'EVERPSQUOTATION_CATEGORIES',
Expand Down Expand Up @@ -559,6 +579,11 @@ private function postValidation()
) {
$this->postErrors[] = $this->l('Error: render PDF on validation is not valid');
}
if (Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED')
&& !Validate::isBool(Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED'))
) {
$this->postErrors[] = $this->l('Error: render PDF on validation is not valid');
}

// Multilingual validation
foreach (Language::getLanguages(false) as $lang) {
Expand Down Expand Up @@ -706,6 +731,11 @@ protected function postProcess()
Tools::getValue('EVERPSQUOTATION_RENDER_ON_VALIDATION')
);

Configuration::updateValue(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED')
);

Configuration::updateValue(
'EVERPSQUOTATION_TRANSACTION_ID',
Tools::getValue('EVERPSQUOTATION_TRANSACTION_ID')
Expand Down Expand Up @@ -820,7 +850,13 @@ protected function getConfigFormValues()
Configuration::get(
'EVERPSQUOTATION_RENDER_ON_VALIDATION'
)
),
),
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED' => Tools::getValue(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
Configuration::get(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED'
)
),
'EVERPSQUOTATION_MAIL_SUBJECT' => self::getConfigInMultipleLangs(
'EVERPSQUOTATION_MAIL_SUBJECT'
),
Expand Down Expand Up @@ -967,6 +1003,10 @@ public function hookDisplayAdminEndContent($params)

public function hookDisplayShoppingCartFooter()
{
$suggestLogIn = Configuration::get('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED');
if ((bool) $suggestLogIn === true && !$this->context->customer->isLogged()) {
return;
}
return $this->display(__FILE__, 'views/templates/hook/form.tpl');
}

Expand Down
3 changes: 2 additions & 1 deletion translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
$_MODULE['<{everpsquotation}prestashop>mail_93cba07454f06a4a960172bbd6e2a435'] = 'Oui';
$_MODULE['<{everpsquotation}prestashop>mail_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Non';
$_MODULE['<{everpsquotation}prestashop>quotations_b423cfa40750b96c794447f27fa4cf87'] = 'Mes devis';
$_MODULE['<{everpsquotation}prestashop>quote_217a1c88b65aad1909d7f005e65a742e'] = 'devis';
$_MODULE['<{everpsquotation}prestashop>validation_8471f68e6bc1c67e47b143e72760c837'] = 'Devis enregistré';
$_MODULE['<{everpsquotation}prestashop>configure_6045227ab0f0f2dd7f2c072f958e20f3'] = 'Comment autoriser la création de devis sur votre boutique ?';
$_MODULE['<{everpsquotation}prestashop>configure_455e1ea883e0372022d4c65878fa9560'] = 'En premier, vos produits doivent être actifs, disponibles à la vente, avec le prix affiché.';
Expand Down Expand Up @@ -128,6 +127,8 @@
$_MODULE['<{everpsquotation}prestashop>everquotation_content_7bf753e0cbb2d38818ba2a3ee3b36f4d'] = 'Total taxes';
$_MODULE['<{everpsquotation}prestashop>everquotation_content_f617c53a5521d2c3be8cd30653e76ee3'] = 'Total TTC';
$_MODULE['<{everpsquotation}prestashop>modal_87e7af63c3cd88c47cb5df286692df1f'] = 'Demander un devis';
$_MODULE['<{everpsquotation}prestashop>modal_30942e7e0ab0da405ac4a965ac25e149'] = 'Vous devez être connecté avec une adresse enregistrée afin de pouvoir télécharger un devis.';
$_MODULE['<{everpsquotation}prestashop>modal_9e7d26d3a67f5fc2e4a59bd036856041'] = 'Connexion';
$_MODULE['<{everpsquotation}prestashop>modal_04176f095283bc729f1e3926967e7034'] = 'Prénom';
$_MODULE['<{everpsquotation}prestashop>modal_dff4bf10409100d989495c6d5486035e'] = 'Nom';
$_MODULE['<{everpsquotation}prestashop>modal_ce8ae9da5b7cd6c3df2929543a9af92d'] = 'Email';
Expand Down
28 changes: 16 additions & 12 deletions views/js/everpsquotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ $(document).ready(function() {
data: formData,
dataType: 'json',
success: function(response) {
$('#everpsquotationform').remove();
// Insérer le tag GTM dans le DOM
if (response.gtm) {
// Vérification et traitement des données pour GTM
Expand All @@ -18,7 +17,7 @@ $(document).ready(function() {
'productId': product.product_id,
'productAttributeId': product.product_attribute_id,
'productCustomizationId': product.id_customization,
'productName': product.product_name,
'productName': product.product_name + ' ' + product.name,
'productReference': product.product_reference,
'productEan13': product.product_ean13,
'productQuantity': product.product_quantity,
Expand All @@ -34,7 +33,6 @@ $(document).ready(function() {
'productReductionAmountTaxExcluded': product.reduction_amount_tax_excl
};
});

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': response.gtm.quoteEvent,
Expand Down Expand Up @@ -63,17 +61,23 @@ $(document).ready(function() {
type: 'POST',
dataType: 'json',
success: function(response) {
$('#everpscartquotation').remove();
// Insérer le tag GTM dans le DOM
console.log(response);
if (response.gtm) {
// Vérification et traitement des données pour GTM
if (response.quoteEvent && response.quoteId && response.quoteCustomer && response.quoteCurrency && response.quoteShopName && response.quoteProducts) {
var quoteProductsArray = response.quoteProducts.map(function(product) {
if (response.gtm.quoteEvent
&& response.gtm.quoteId
&& response.gtm.quoteCustomer
&& response.gtm.quoteCurrency
&& response.gtm.quoteShopName
&& response.gtm.quoteProducts
) {
var quoteProductsArray = response.gtm.quoteProducts.map(function(product) {
return {
'productId': product.product_id,
'productAttributeId': product.product_attribute_id,
'productCustomizationId': product.id_customization,
'productName': product.name,
'productName': product.product_name + ' ' + product.name,
'productReference': product.product_reference,
'productEan13': product.product_ean13,
'productQuantity': product.quantity,
Expand All @@ -92,11 +96,11 @@ $(document).ready(function() {

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': response.quoteEvent,
'quoteId': response.quoteId,
'customer_email': response.quoteCustomer.email,
'currency': response.quoteCurrency.name,
'quoteShopName': response.quoteShopName,
'event': response.gtm.quoteEvent,
'quoteId': response.gtm.quoteId,
'customer_email': response.gtm.quoteCustomer.email,
'currency': response.gtm.quoteCurrency.name,
'quoteShopName': response.gtm.quoteShopName,
'quoteProducts': quoteProductsArray
});
}
Expand Down
7 changes: 7 additions & 0 deletions views/templates/front/modal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</div>
<!-- Contenu de la modale (Votre formulaire) -->
<div class="modal-body">
{if isset($suggestLogIn) && $suggestLogIn}
<div class="alert alert-warning">
<p>{l s='You must be logged in with a registered address in order to download a quote.' mod='everpsquotation'}</p>
<a href="{$urls.pages.authentication}" class="btn btn-primary">{l s='Login to my account' mod='everpsquotation'}</a>
</div>
{else}
<form id="everquotationAskForQuote">
<!-- Champ prénom -->
<div class="form-group">
Expand Down Expand Up @@ -79,6 +85,7 @@
</div>
<button type="submit" class="btn btn-primary">{l s='Submit' mod='everpsquotation'}</button>
</form>
{/if}
</div>
</div>
</div>
Expand Down

0 comments on commit 2644b6d

Please sign in to comment.