Vérifier le formulaire'; } else { $sale = Sale::getSaleFromCategory((int) $id_category); $category = new Category($id_category, $cookie->id_lang); $orders_single = $sale->getOrdersFromSale(NULL, TRUE); $orders_multiple = $sale->getOrdersFromSale(NULL, FALSE); if($type_envoi == 0) { $orders = array_merge($orders_multiple, $orders_single); } else if($type_envoi == 1) { $orders = $orders_multiple; } else if($type_envoi == 2) { $orders = $orders_single; } $orders = array_unique($orders); if(Tools::isSubmit('submitEnvoi')) { $this->displayConfirmationForm($category, $type_envoi, $contenu_mail, count($orders), $sale, $objet_mail, $envoi_remise, $montant_remise, $prefix_remise); } else if(Tools::isSubmit('confirmationEnvoi')) { $contenu_mail = str_replace("%marque%", $category->name , $contenu_mail); $mail = 0; $mails_errors = array(); foreach ($orders as $key => $order) { $data = new Order($order); if($envoi_remise == 1){ $params = array( 'id_customer' => $data->id_customer, 'currency' => 1, 'description' => Configuration::get('MAIL_PS_DESC'), 'value' => (int) $montant_remise, 'prefix' => $prefix_remise ); $discount = $this->_register_discount($params); $contenu_mail = str_replace("%montant%", (int)$montant_remise , $contenu_mail); $contenu_mail = str_replace("%discount%", $discount->name , $contenu_mail); } $customer = new Customer($discount->id_customer); $send = Mail::Send( $cookie->id_lang, 'ps_delay', $objet_mail, array( '{message}' => $contenu_mail ), $customer->email, $customer->firstname.' '.$customer->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/' ); $send = true; if(!$send){ $mails_errors[] = $order->id; } $mail++; } if( count($mails_errors) > 0) { echo '
Soucis sur les commandes ' . implode(',', $mails_errors) .'
'; } echo '
Envoi réussi : '. $mail.' mails(s) envoyés
'; } } } } private function _register_discount($params) { $discount = new Discount(); $discount->id_customer = $params['id_customer']; $discount->id_discount_type = 2; $discount->cumulable = 1; $discount->cumulable_reduction = 1; $discount->minimal = 0; $discount->include_tax = 0; $discount->cart_display = 1; $discount->active = 1; $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = date('Y-m-d H:i:s'); $discount->date_to = date('Y-m-d H:i:s', time() + 365 * 86400); $name = $params['prefix'] . '-' . Tools::passwdGen(8); if(Discount::discountExists($name)) { // It should not happen, but who knows... $name = $params['prefix'] . '-' . Tools::passwdGen(8); } $discount->name = $name; $title[2] = $params['description']; $discount->description = $title; if(isset($params['value']) && isset($params['currency'])) { $discount->id_currency = $params['currency']; $discount->value = $params['value']; } $discount->add(true, false, array(1)); // assoc only accueil catégorie return $discount; } public function displayConfirmationForm($category, $type_envoi, $contenu_mail, $nb_envoi, $sale, $objet_mail, $envoi_remise, $montant_remise = 0, $prefix_remise) { if($type_envoi == 0) { $type_envoi_text = "Toutes"; } else if($type_envoi == 1) { $type_envoi_text = "Multi"; } else if($type_envoi == 2) { $type_envoi_text = "Simple"; } $output .= '
Confirmation envoi'; $output.= ''; $output.= ''; $output.= ''; $output.= ''; $output.= ''; $output.= ''; $output.= ''; $output .= '

Vous allez envoyer '. $nb_envoi .' mails pour un retard concernant la vente '. $category->name .'
Segmentation des commandes : '. $type_envoi_text .'



'; echo $output; } public function display(){ global $cookie; $mail_delay_sql = 'SELECT value FROM ps_configuration WHERE name = "MAIL_PS_DELAY"'; $mail_delay = DB::getInstance()->getValue($mail_delay_sql); $montant = Configuration::get('REMISE_PS_DELAY'); $output .= '
'.$this->l('Alerte mail').'
'; $output .= '

Si vous cochez non, la variable %montant% et %value% ne doit pas être présente dans le mail ci-dessous

Exemple : TEST pour avoir un bon sous la forme TEST-AAAAA


Les données suivantes seront remplacés avant l\'envoi du mail :

  1. %montant% : Montant de la remise
  2. %discount% : Code de réduction
  3. %marque% : Nom de la vente


Nb : Un récapitulatif de l\'envoi sera disponible avant le définitif

'; // TinyMCE global $cookie; $iso = Language::getIsoById((int)($cookie->id_lang)); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $ad = dirname($_SERVER["PHP_SELF"]); $output.= ' '; $output.= ''; $output.= ''; $output.= ''; echo $output; } }