Arkadia Posted November 29, 2012 Share Posted November 29, 2012 (edited) Hi everyone, I was wondering if anyone could help or give me a push in the right direction... I need to add a "Receive our newsletters" checkbox (opt in for newsletters) somewhere in the 5 step checkout process. It should be unchecked by default...and then if the user checks it, it should subscribe them to the newsletter as they checkout. I have no idea where to begin with this yet. Any ideas? Thank you! Edited December 6, 2012 by Arkadia (see edit history) Link to comment Share on other sites More sharing options...
portal7 Posted November 29, 2012 Share Posted November 29, 2012 Version??? Link to comment Share on other sites More sharing options...
Arkadia Posted December 4, 2012 Author Share Posted December 4, 2012 Hi Portal... Sorry. It's prestashop 1.4.5.1 and I'm using Newsletter block v1.4 by PrestaShop Thanks! Link to comment Share on other sites More sharing options...
Arkadia Posted December 4, 2012 Author Share Posted December 4, 2012 (edited) Okay I resolved this! For anyone else that may be interested... Edit controllers/OrderController.php Find the following function under /*payment step*/ and add this code... /* Payment step */ protected function _assignPayment() { //Start php to add a newsletter opt-in $emailkd = self::$cookie->email; if (isset($_POST['newsletterkd'])){ $newssub = 'checked'; } else { $newssub = 'not checked'; } if ($newssub == 'checked'){ if (Db::getInstance()->getRow('SELECT `email` FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($emailkd).'\'')){ //user is in the ps_newletter db - so do nothing... $checkdb = 'in database'; } else { //add customer to ps_newletter $checkdb = 'not in db'; if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'newsletter (email, newsletter_date_add, ip_registration_newsletter, http_referer) VALUES (\''.$emailkd.'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\', NULL )')){ return $this->error = $this->l('Error during subscription'); } } } //END newsletter optin edit global $orderTotal; // Redirect instead of displaying payment modules if any module are grefted on Hook::backBeforePayment('order.php?step=3'); /* We may need to display an order summary */ self::$smarty->assign(self::$cart->getSummaryDetails()); self::$smarty->assign(array( 'total_price' => (float)($orderTotal), 'taxes_enabled' => (int)(Configuration::get('PS_TAX')) )); self::$cookie->checkedTOS = '1'; parent::_assignPayment(); } Then in your tpl file where you'd like to show the checkbox in the checkout area...add the following code: (In my case I chose to use theme/order-carrier.tpl) <!-- Added this to add Newsletter Subscription checkbox in checkout--> <br /> <h3 class="carrier_title">{l s='Would you like to sign up for our Newsletter?'}</h3> <p class="checkbox"> <input type="checkbox" name="newsletterkd" id="newsletterkd" value="1" /> <label for="newsletterkd">{l s='Yes, sign me up!'}</label> </p> <!--END Newsletter Subscription checkbox--> Note: I am using prestashop 1.4.5.1 with Newsletter block v1.4 by PrestaShop This should work in similar way in the newer prestashop versions but I've not tested it with any other prestashop version...so adjust accordingly...it's simply writing the customers email address and other details required (namely: the date stamp, ip address, and http referrer) to the ps_newsletter table in the database. It also checks if the user was already registered or not so you don't get double entries. Feel free to improve my code! Well hope that's useful to someone out there. Edited December 6, 2012 by Arkadia (see edit history) Link to comment Share on other sites More sharing options...
kenkomuri Posted October 5, 2013 Share Posted October 5, 2013 Okay I resolved this! For anyone else that may be interested... Edit controllers/OrderController.php Find the following function under /*payment step*/ and add this code... /* Payment step */ protected function _assignPayment() { //Start php to add a newsletter opt-in $emailkd = self::$cookie->email; if (isset($_POST['newsletterkd'])){ $newssub = 'checked'; } else { $newssub = 'not checked'; } if ($newssub == 'checked'){ if (Db::getInstance()->getRow('SELECT `email` FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($emailkd).'\'')){ //user is in the ps_newletter db - so do nothing... $checkdb = 'in database'; } else { //add customer to ps_newletter $checkdb = 'not in db'; if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'newsletter (email, newsletter_date_add, ip_registration_newsletter, http_referer) VALUES (\''.$emailkd.'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\', NULL )')){ return $this->error = $this->l('Error during subscription'); } } } //END newsletter optin edit global $orderTotal; // Redirect instead of displaying payment modules if any module are grefted on Hook::backBeforePayment('order.php?step=3'); /* We may need to display an order summary */ self::$smarty->assign(self::$cart->getSummaryDetails()); self::$smarty->assign(array( 'total_price' => (float)($orderTotal), 'taxes_enabled' => (int)(Configuration::get('PS_TAX')) )); self::$cookie->checkedTOS = '1'; parent::_assignPayment(); } Then in your tpl file where you'd like to show the checkbox in the checkout area...add the following code: (In my case I chose to use theme/order-carrier.tpl) <!-- Added this to add Newsletter Subscription checkbox in checkout--> <br /> <h3 class="carrier_title">{l s='Would you like to sign up for our Newsletter?'}</h3> <p class="checkbox"> <input type="checkbox" name="newsletterkd" id="newsletterkd" value="1" /> <label for="newsletterkd">{l s='Yes, sign me up!'}</label> </p> <!--END Newsletter Subscription checkbox--> Note: I am using prestashop 1.4.5.1 with Newsletter block v1.4 by PrestaShop This should work in similar way in the newer prestashop versions but I've not tested it with any other prestashop version...so adjust accordingly...it's simply writing the customers email address and other details required (namely: the date stamp, ip address, and http referrer) to the ps_newsletter table in the database. It also checks if the user was already registered or not so you don't get double entries. Feel free to improve my code! Well hope that's useful to someone out there. Does it work for 1.5 version? Link to comment Share on other sites More sharing options...
vekia Posted October 6, 2013 Share Posted October 6, 2013 hello this option appears in prestashop 1.5 by default, just turn on newsletter Link to comment Share on other sites More sharing options...
kenkomuri Posted October 6, 2013 Share Posted October 6, 2013 hello this option appears in prestashop 1.5 by default, just turn on newsletter Where could you turn on? 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