Skip to content

Commit be7f36b

Browse files
author
Marc Bernabeu
committed
notifications on front & on email for customers
1 parent 36822e3 commit be7f36b

4 files changed

Lines changed: 104 additions & 8 deletions

File tree

app/code/community/Devopensource/Redsys/Helper/Data.php

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,78 @@ public function stateInTpv($_order){
117117
$status = Mage::getStoreConfig('payment/redsys/redirect_status', Mage::app()->getStore());
118118
$state = 'new';
119119
$comment = $this->__('enters TPV');
120-
$isCustomerNotified = true;
121-
$_order->setState($state, $status, $comment, $isCustomerNotified);
120+
121+
$isCustomerNotified = false;
122+
$isVisibleOnFront = false;
123+
124+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_email', Mage::app()->getStore())){
125+
$isCustomerNotified = true;
126+
}
127+
128+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_frontend', Mage::app()->getStore())){
129+
$isVisibleOnFront = true;
130+
}
131+
132+
$this->setCustomState($_order,$state, $status, $comment, $isCustomerNotified,$isVisibleOnFront);
122133
$_order->save();
134+
135+
if($isCustomerNotified){
136+
$_order->sendOrderUpdateEmail($isCustomerNotified, $comment);
137+
}
123138
}
124139

125140
public function stateConfirmTpv($_order,$comment){
126141
$this->fixCreditCustomer();
127142
$status = Mage::getStoreConfig('payment/redsys/confirm_status', Mage::app()->getStore());
128143
$state = 'processing';
129-
$isCustomerNotified = true;
130-
$_order->setState($state, $status, $comment, $isCustomerNotified);
144+
145+
$isCustomerNotified = false;
146+
$isVisibleOnFront = false;
147+
148+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_email', Mage::app()->getStore())){
149+
$isCustomerNotified = true;
150+
}
151+
152+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_frontend', Mage::app()->getStore())){
153+
$isVisibleOnFront = true;
154+
}
155+
156+
$this->setCustomState($_order,$state, $status, $comment, $isCustomerNotified,$isVisibleOnFront);
131157
$_order->save();
158+
159+
if($isCustomerNotified){
160+
$_order->sendOrderUpdateEmail($isCustomerNotified, $comment);
161+
}
132162
}
133163

134164
public function stateErrorTpv($_order,$errorMessage=null){
135165
$this->fixCreditCustomer();
136166
$status = Mage::getStoreConfig('payment/redsys/error_status', Mage::app()->getStore());
137167
$state = 'canceled';
138168
$comment = $this->__('Error in TPV order canceled.');
139-
$isCustomerNotified = true;
169+
170+
$isCustomerNotified = false;
171+
$isVisibleOnFront = false;
172+
173+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_email', Mage::app()->getStore())){
174+
$isCustomerNotified = true;
175+
}
176+
177+
if(Mage::getStoreConfig('payment/redsys/notify_clients_states', Mage::app()->getStore()) && Mage::getStoreConfig('payment/redsys/notify_by_frontend', Mage::app()->getStore())){
178+
$isVisibleOnFront = true;
179+
}
140180

141181
if($errorMessage){
142182
$comment = $this->__('Failed: %s',$errorMessage);
143183
}
144184

145-
$_order->setState($state, $status, $comment, $isCustomerNotified);
185+
$this->setCustomState($_order,$state, $status, $comment, $isCustomerNotified,$isVisibleOnFront);
146186
$_order->registerCancellation("")->save();
147187
$_order->save();
188+
189+
if($isCustomerNotified){
190+
$_order->sendOrderUpdateEmail($isCustomerNotified, $comment);
191+
}
148192
}
149193

150194

@@ -386,4 +430,21 @@ public function isCurrentVersionLatest(){
386430

387431
return true;
388432
}
433+
434+
public function setCustomState($order ,$state, $status = false, $comment = '', $isCustomerNotified = null, $isVisibleOnFront=false){
435+
$order->setData('state', $state);
436+
437+
// add status history
438+
if ($status) {
439+
if ($status === true) {
440+
$status = $order->getConfig()->getStateDefaultStatus($state);
441+
}
442+
$order->setStatus($status);
443+
$history = $order->addStatusHistoryComment($comment, false); // no sense to set $status again
444+
$history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
445+
$history->setIsVisibleOnFront($isVisibleOnFront);
446+
}
447+
448+
return $this;
449+
}
389450
}

app/code/community/Devopensource/Redsys/etc/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<error_status>canceled</error_status>
7373
<title>Card Payment</title>
7474
<message_credit_card>payment by credit card or debit 100% safe</message_credit_card>
75+
<notify_clients_states>0</notify_clients_states>
76+
<notify_by_email>0</notify_by_email>
77+
<notify_by_frontend>0</notify_by_frontend>
7578
<display_error_clients>0</display_error_clients>
7679
<recover_cart>1</recover_cart>
7780
<transaction>0</transaction>

app/code/community/Devopensource/Redsys/etc/system.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,40 @@
169169
<show_in_website>1</show_in_website>
170170
<show_in_store>1</show_in_store>
171171
</message_credit_card>
172+
<notify_clients_states translate="label">
173+
<label>Notify clients states</label>
174+
<frontend_type>select</frontend_type>
175+
<source_model>adminhtml/system_config_source_yesno</source_model>
176+
<sort_order>171</sort_order>
177+
<show_in_default>1</show_in_default>
178+
<show_in_website>1</show_in_website>
179+
<show_in_store>1</show_in_store>
180+
</notify_clients_states>
181+
<notify_by_email translate="label">
182+
<label>Notify by email</label>
183+
<frontend_type>select</frontend_type>
184+
<source_model>adminhtml/system_config_source_yesno</source_model>
185+
<sort_order>172</sort_order>
186+
<show_in_default>1</show_in_default>
187+
<show_in_website>1</show_in_website>
188+
<show_in_store>1</show_in_store>
189+
<depends><notify_clients_states>1</notify_clients_states></depends>
190+
</notify_by_email>
191+
<notify_by_frontend translate="label">
192+
<label>Notify by frontend</label>
193+
<frontend_type>select</frontend_type>
194+
<source_model>adminhtml/system_config_source_yesno</source_model>
195+
<sort_order>173</sort_order>
196+
<show_in_default>1</show_in_default>
197+
<show_in_website>1</show_in_website>
198+
<show_in_store>1</show_in_store>
199+
<depends><notify_clients_states>1</notify_clients_states></depends>
200+
</notify_by_frontend>
172201
<display_error_clients translate="label">
173202
<label>Display Error Messages Clients</label>
174203
<frontend_type>select</frontend_type>
175204
<source_model>adminhtml/system_config_source_yesno</source_model>
176-
<sort_order>170</sort_order>
205+
<sort_order>175</sort_order>
177206
<show_in_default>1</show_in_default>
178207
<show_in_website>1</show_in_website>
179208
<show_in_store>1</show_in_store>

app/locale/es_ES/Devopensource_Redsys.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
"(response:%s)","(respuesta:%s)"
4141
"Display Error Messages Clients","Mostrar mensajes de error redsys a los clientes"
4242
"Your version:","Tu versión:"
43-
"Latest version stable:","Última versión estable:"
43+
"Latest version stable:","Última versión estable:"
44+
"Notify clients states","Notificar estados de pedido al cliente"
45+
"Notify by email","Notificar por email"
46+
"Notify by frontend","Notificar por frontend"

0 commit comments

Comments
 (0)