@@ -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}
0 commit comments