renaud2263 Posted October 27, 2016 Share Posted October 27, 2016 Bonjour à Tous, J'ai overridé le CustomerAdminController car j'avais besoin d'ajouter un champ supplémentaire dans le formulaire de création (un code parrainage). J'ai donc réécrit la fonction processAdd et ajouté mes lignes de code de traitement, notamment créer une règle de panier avec un code promo bienvenue. Jusqu'à là tout va bien. Là où je sèche c'est comment afficher ce code promo ? J'aurais bien voulu l'afficher à la suite du message succès "Création réussie"....Du genre: "Création réussie. Ce client bénéficie d'un code promo 5% qui est : XXXXX". Mais je ne vois pas comment interférer sur le template, ni même de quel template il s'agit. Merci de vos conseils. La fonction processAdd réécrite : public function processAdd() { if (Tools::getValue('submitFormAjax')) { $this->redirect_after = false; } // Check that the new email is not already in use $customer_email = strval(Tools::getValue('email')); $customer = new Customer(); if (Validate::isEmail($customer_email)) { $customer->getByEmail($customer_email); } if ($customer->id) { $this->errors[] = Tools::displayError('An account already exists for this email address:').' '.$customer_email; $this->display = 'edit'; return $customer; } elseif (trim(Tools::getValue('passwd')) == '') { $this->validateRules(); $this->errors[] = Tools::displayError('Password can not be empty.'); $this->display = 'edit'; } elseif ($customer = parent::processAdd()) { if (Tools::getValue('sponsorship')){ $sponsorship = Tools::getValue('sponsorship'); $id_sponsor = $this->decodeSponsorshipLink($sponsorship); $id_template = (int)MyConf::getIdTemplate('sponsorship', $id_sponsor); $id_cart_rule = (int)CartRule::getIdByCode(MyConf::get('RSPONSORSHIP_REAL_CODE_GC', null, $id_template)); $cart_rule = new CartRule((int)$id_cart_rule); $id_currency = (int)$this->context->currency->id; $code = NULL; do $code = MyConf::get('RSPONSORSHIP_VOUCHER_PREFIX_GC', null, $id_template).Tools::passwdGen(6); while (CartRule::cartRuleExists($code)); /* Voucher creation and affectation to the customer */ $cartRule = new CartRule(); $cartRule->code = $code; $cartRule->active = 1; $cartRule->id_customer = (int)$customer->id; $cartRule->date_from = date('Y-m-d H:i:s', time()); $cartRule->date_to = date('Y-m-d H:i:s', time() + (int)MyConf::get('RSPONSORSHIP_VOUCHER_DURATION_GC', null, $id_template)*24*60*60); $cartRule->description = 'Parrainage Vivrenaturellement'; $cartRule->quantity = (int)MyConf::get('RSPONSORSHIP_QUANTITY_GC', null, $id_template); $cartRule->quantity_per_user = (int)MyConf::get('RSPONSORSHIP_QUANTITY_GC', null, $id_template); $cartRule->highlight = 1; if ((int)MyConf::get('RSPONSORSHIP_DISCOUNT_TYPE_GC', null, $id_template) == 2) $cartRule->partial_use = (int)MyConf::get('RSPONSORSHIP_VOUCHER_BEHAVIOR', null, $id_template); else $cartRule->partial_use = 0; $cartRule->minimum_amount = (float)MyConf::get('RSPONSORSHIP_MINIMUM_VALUE_GC_'.$id_currency, null, $id_template); $cartRule->minimum_amount_tax = (int)MyConf::get('RSPONSORSHIP_MINIMAL_TAX_GC', null, $id_template); $cartRule->minimum_amount_currency = $id_currency; $cartRule->minimum_amount_shipping = 0; $cartRule->cart_rule_restriction = (int)(!(bool)MyConf::get('RSPONSORSHIP_CUMUL_GC', null, $id_template)); if ((int)MyConf::get('RSPONSORSHIP_DISCOUNT_TYPE_GC', null, $id_template) == 1) { $cartRule->reduction_percent = (float)MyConf::get('RSPONSORSHIP_VOUCHER_VALUE_GC_'.$id_currency, null, $id_template); } else if ((int)MyConf::get('RSPONSORSHIP_DISCOUNT_TYPE_GC', null, $id_template) == 2) { $cartRule->reduction_amount = (float)MyConf::get('RSPONSORSHIP_VOUCHER_VALUE_GC_'.$id_currency, null, $id_template); $cartRule->reduction_currency = $id_currency; $cartRule->reduction_tax = 1; } if ((int)MyConf::get('RSPONSORSHIP_FREESHIPPING_GC', null, $id_template) == 1) { $cartRule->free_shipping = 1; } $languages = Language::getLanguages(true); $default_text = MyConf::get('RSPONSORSHIP_VOUCHER_DETAILS', (int)Configuration::get('PS_LANG_DEFAULT'), $id_template); foreach ($languages AS $language) { $text = MyConf::get('RSPONSORSHIP_VOUCHER_DETAILS', (int)$language['id_lang'], $id_template); $cartRule->name[(int)$language['id_lang']] = $text ? $text : $default_text; } $cartRule->add(); } $this->context->smarty->assign('new_customer', $customer); return $customer; } return false; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now