Skip to content

Commit

Permalink
first commit version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
taoufiqaitali committed Nov 26, 2019
1 parent 4e0db43 commit 9279420
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# prestashop-phone-field-for-registration
module to add phone field for registration in prestashop 1.7
this module allow to add phone field in registration form, you can use same module as template to create other fields


[![Github All Releases](https://img.shields.io/github/downloads/taoufiqaitali/prestashop-phone-field-for-registration/total.svg)]()
[![Twitter](https://img.shields.io/twitter/url?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Ftaoufiqaitali%2Fprestashop-phone-field-for-registration)

![phone field for registration](docs/screenshot1.png)

##Installation
1. download the archive from [GitHub](https://github.com/taoufiqaitali/prestashop-phone-field-for-registration/archive/master.zip)
2. rename prestashop-phone-field-for-registration-master zip and folder to **regphonefield**
3. install from prestashop backoffice like any other module
4. Clear cache and enjoy

##To create other fields
1. Download repository
2. search "phone" and replace with your field name
3. Follow installation steps

Binary file added docs/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header("Location: ../");
exit;
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions override/classes/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: clever
* Date: 14/12/18
* Time: 11:03
*/

class Customer extends CustomerCore
{
/** @var string phone */
public $phone;

public function __construct($idStore = null, $idLang = null)
{
Self::$definition['fields']['phone']=array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 64);
parent::__construct($idStore, $idLang);
}


}
80 changes: 80 additions & 0 deletions regphonefield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @author Taoufiq Ait Ali
*/

if (!defined('_PS_VERSION_')) {
exit;
}

class Regphonefield extends Module
{
public function __construct()
{
$this->name = 'regphonefield';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Taoufiq Ait Ali';
$this->need_instance = 0;
$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('phone field for registration');
$this->description = $this->l('Add phone field to registration form.');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
$result = true;
if (!parent::install()
|| !$this->registerHook('additionalCustomerFormFields')
|| !$this->registerHook('actionCustomerAccountAdd')
|| !$this->registerHook('actionAdminCustomersListingFieldsModifier')
) {
$result = false;
}

$res =(bool)Db::getInstance()->execute(
'ALTER TABLE `'._DB_PREFIX_.'customer` ADD `phone` varchar(64) NULL'
);

return $result;
}

public function uninstall()
{
if (!parent::uninstall()
) {
return false;
}
$res =(bool)Db::getInstance()->execute(
'ALTER TABLE `'._DB_PREFIX_.'customer` DROP `phone`'
);
return true;
}

public function hookAdditionalCustomerFormFields($params)
{
$formField = new FormField();
$formField->setName('phone');
$formField->setType('text');
$formField->setLabel($this->l('Phone'));
$formField->setRequired(true);
return array($formField);
}

public function hookActionCustomerAccountAdd($params)
{
$customerId =$params['newCustomer']->id;
$phone= Tools::getValue('phone','');
return (bool) Db::getInstance()->execute('update '._DB_PREFIX_.'customer set phone=\''.pSQL($phone)."' WHERE id_customer=".(int) $customerId);
}
public function hookActionAdminCustomersListingFieldsModifier($params)
{
$params['fields']['phone'] = array(
'title' => $this->l('Phone'),
'align' => 'center',
);
}
}

0 comments on commit 9279420

Please sign in to comment.