.htaccess and seo-friendly urls - apache

We have an ecommerce site right now that carries a range of brands. The brand pages carry urls as follows:
http://www.<DOMAIN>.com/catalog/brand/view?id=2
We need to utilize more friendly (seo-friendly) urls such as:
http://www.<DOMAIN>.com/<BRAND>
but such that it would resolve #1 above.
Is this done in .htaccess files in the root? If so, what is the correct way to go about this?
Keep in mind URL#1 is the legitimate address, but we want to utilize the URL#2 format for linking. It's not a 301 type redirect is it? That's more "permanent" unless I misunderstood it or something, no?
Many thanks.

The apache feature you are looking for is called mod_rewrite. You should be able to google and find good resources for help here.
The basic idea is you'll specify a regular expression matching and then a replacement pattern. You can set it to do a 301 redirect, but the default is to not redirect the user, just access the re-written url.
Here's an example:
RewriteEngine On
RewriteRule (.*) index.php
The RewriteRule says to rewrite any matching url(.*) to index.php. This is not particularly useful for most files. I'm sure you'll have plenty of examples as this is a common problem.

Unless you think the brand names are likely to change then you want to do 2 rewrites, one as a redirect and one internal:
RewriteRule ^catalog/brand/view?id=2 /<BRAND> [R=301,L]
RewriteRule ^<BRAND> /catalog/brand/view?id=2
This means that browsers / spiders will always see the nice URLs while your application will see the real ones.

You can do it by adding a .htaccess on the index or doing the configuration in the httpd.conf.
Here you have a tool that can help you. What you need is an inflector
I hope this helps you.. you will need make few modifications... :P
define('SEO_HOST', "http://www.example.com");
define('SEO_ITEM_PATTERN', SEO_HOST . '/%s-prod-%s');
define('SEO_CATEGORY_PATTERN', SEO_HOST . '/%s-cat-%s');
define('SEO_COMBO_PATTERN', SEO_HOST . '/%s-combo-%s');
class Seo {
function seems_utf8($Str) { # by bmorel at ssi dot fr
$length = strlen($Str);
for ($i=0; $i < $length; $i++) {
if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
else return false; # Does not match any model
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
if ((++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80))
return false;
}
}
return true;
}
function get_beauty_url_string($string) {
if ( !preg_match('/[\x80-\xff]/', $string) )
return self::replace_no_alpha_chars($string);
if (self::seems_utf8($string)) {
$chars = array(
// Decompositions for Latin-1 Supplement
chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
chr(195).chr(191) => 'y',
// Decompositions for Latin Extended-A
chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
// Euro Sign
chr(226).chr(130).chr(172) => 'E',
// GBP (Pound) Sign
chr(194).chr(163) => '');
$string = strtr($string, $chars);
} else {
// Assume ISO-8859-1 if not UTF-8
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
.chr(252).chr(253).chr(255);
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
$string = strtr($string, $chars['in'], $chars['out']);
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
$string = str_replace($double_chars['in'], $double_chars['out'], $string);
}
return self::replace_no_alpha_chars($string);
}
function replace_no_alpha_chars($url) {
$url = strtolower(ereg_replace("[^a-zA-Z0-9]","-",trim($url)));
// Saca los guiones repetidos
$url = strtolower(ereg_replace('-+','-',($url)));
// Saca el último guión en caso de que termine con uno
if ($url[strlen($url)-1] == '-') $url = substr($url, 0, strlen($url)-1);
return $url;
}
function get_item_url($title, $id, $category = '') {
$beauty_category = $beauty_title = '';
$beauty_title = self::get_beauty_url_string($title);
if (strlen($category))
$beauty_category = self::get_beauty_url_string($category);
$url = sprintf(SEO_ITEM_PATTERN, (strlen($beauty_category) ? "{$beauty_category}/" : "") . $beauty_title, $id);
return $url;
}
function get_category_url($title, $id) {
$beauty_title = self::get_beauty_url_string($title);
$url = sprintf(SEO_CATEGORY_PATTERN,$beauty_title, $id);
return $url;
}
function get_combo_url($title, $id) {
$beauty_title = self::get_beauty_url_string($title);
$url = sprintf(SEO_COMBO_PATTERN,$beauty_title, $id);
return $url;
}
}
You can use it like this:
<a ref="<?= Seo::get_category_url("my super category",10)?>">My super category</a>
You will get: http://www.example.com/my-super-category-cat-10
And my .htaccess of course:
RewriteRule ^(.*)-cat-([0-9]+)$ /simple/index.php?categoria_id=$2&estado=mostrar_categoria [L,QSA]
RewriteRule ^(.*)-combo-([0-9]+)$ /simple/index.php?producto_id=$2&estado=mostrar_combo [L,QSA]
RewriteRule ^(.*)-prod-([0-9]+)$ /simple/index.php?producto_id=$2&estado=mostrar_producto [L,QSA]

Related

AUTHENTICATE 2 LDAP USER IN ITOPS

I have some LDAP users in iTops, and i want to login with all of users in iTops. But i have an error like that "user not found in LDAP".
Which folders that i have to change ? So i can login with all LDAP users.
I appreciate for your responses, all of you. Please help me, thanks.
in config-itop.php
$MyModuleSettings = array(
'authent-ldap' => array (
'host' => '192.168.1.2',
'port' => 389,
'default_user' => 'anonim',
'default_pwd' => 'Admin123',
'base_dn' => 'dc=vokasiub,dc=COM',
'user_query' => '(samaccountname=%1$s)',
'options' => array (
17 => 3,
8 => 0,
),
'start_tls' => false,
'debug' => true,
),
'authent-ldap2' => array (
'host' => '192.168.2.2',
'port' => 389,
'default_user' => 'isoiso',
'default_pwd' => 'Admin123',
'base_dn' => 'ou=users ou, dc=bagusyekti,dc=COM',
'user_query' => '(samaccountname=%1$s)',
'options' => array (
17 => 3,
8 => 0,
),
'start_tls' => false,
'debug' => true,
),
'itop-attachments' => array (
'allowed_classes' => array (
0 => 'Ticket',
),
'position' => 'relations',
'preview_max_width' => 290,
),
'email-reply' => array (
'enabled_default' => true,
),
'itop-backup' => array (
'mysql_bindir' => '',
'week_days' => 'monday, tuesday, wednesday, thursday, friday',
'time' => '23:30',
'retention_count' => 5,
'enabled' => true,
'debug' => true,
),
);
iTop 2.7 and older
This was not possible.
iTop 3.0 and newer
This is now possible, check the full documentation here, but basically you have to set the different LDAP servers like this in the iTop configuration file:
'authent-ldap' => array (
'host' => 'localhost',
'port' => 389,
'default_user' => '',
'default_pwd' => '',
'base_dn' => 'dc=mycompany,dc=com',
'user_query' => '(&(uid=%1$s))',
'options' => array (
17 => 3,
8 => 0,
),
'debug' => false,
'servers' => array(
'MySecond-LDAP-Server' => array(
'host' => 'server1',
'port' => 389,
'default_user' => '',
'default_pwd' => '',
'base_dn' => 'dc=mycompany,dc=com',
'user_query' => '(&(uid=%1$s))',
'options' => array (
17 => 3,
8 => 0,
),
'debug' => false,
),
),
),

Omit language preVar for RealURL 2.x with multidomain-multilanguage setup?

In a TYPO3 6.2.30 site, I updated RealURL 1.x to 2.2.1.
It works fine, but it is a multilanguage-multidomain site that doesn't require the language prefix after the domain.
Before I had
www.germandomain.ch/seite
www.frenchdomain.ch/page
Now I get
www.germandomain.ch/de/seite
www.frenchdomain.ch/fr/page
The old paths are still working as an alternative though.
How can I omit the parameter from the URL for both languages - is that still possible with RealURL 2?
Below are the relevant configuration snippets. I don't have domain records defined in the backend / pagetree.
'preVars' => array(
array(
'GETvar' => 'L',
'valueMap' => array(
'de' => '0',
'fr' => '1',
),
//'valueDefault' => 'de',
'noMatch' => 'bypass',
),
array(
'GETvar' => 'no_cache',
'valueMap' => array(
'no_cache' => 1,
),
'noMatch' => 'bypass',
),
),
and
$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DOMAINS'] = array(
'encode' => array(
array(
'GETvar' => 'L',
'value' => '',
'ifDifferentToCurrent' => true,
'useConfiguration' => '_DEFAULT',
'urlPrepend' => 'https://www.germandomain.ch',
),
array(
'GETvar' => 'L',
'value' => '0',
'ifDifferentToCurrent' => true,
'useConfiguration' => '_DEFAULT',
'urlPrepend' => 'https://www.germandomain.ch',
),
array(
'GETvar' => 'L',
'value' => '1',
'ifDifferentToCurrent' => true,
'useConfiguration' => '_DEFAULT',
'urlPrepend' => 'https://www.frenchdomain.ch',
),
),
'decode' => array(
'www.germandomain.ch' => array(
'GETvars' => array(
'L' => '0',
),
'useConfiguration' => '_DEFAULT',
),
'www.frenchdomain.ch' => array(
'GETvars' => array(
'L' => '1',
),
'useConfiguration' => '_DEFAULT',
),
),
);
and in TS
config {
sys_language_uid = 0
linkVars = L
language = de
locale_all = de_DE.utf-8
htmlTag_langKey = de
#defaultGetVars.L = 0
}
[globalVar = GP:L = 1]
config {
sys_language_uid = 1
language = fr
locale_all = fr_FR.utf-8
htmlTag_langKey = fr
#defaultGetVars.L = 1
}
[global]

Prestashop add another field to the the address form

I have been trying to add another two non-mandatory fields to the address pages, (user page, admin page, etc)
I created two columns in the ps_address and named address3 and address4 and changed available files in version 1.6.0.11 according to this article
I was able to add the new adreess3 and address4 fields in the country address settings. But there is no text field to add address3 and address4 in the AddressesController and the customer add addresses list.
Following is my modified AddressesController file.
<?php
/*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 license#prestashop.com 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 <contact#prestashop.com>
* #copyright 2007-2015 PrestaShop SA
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminAddressesControllerCore extends AdminController
{
/** #var array countries list */
protected $countries_array = array();
public function __construct()
{
$this->bootstrap = true;
$this->required_database = true;
$this->required_fields = array('company', 'address2', 'address3', 'address4', 'postcode', 'other', 'phone', 'phone_mobile', 'vat_number', 'dni');
$this->table = 'address';
$this->className = 'Address';
$this->lang = false;
$this->addressType = 'customer';
$this->explicitSelect = true;
$this->context = Context::getContext();
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'),
'icon' => 'icon-trash'
)
);
$this->allow_export = true;
if (!Tools::getValue('realedit'))
$this->deleted = true;
$countries = Country::getCountries($this->context->language->id);
foreach ($countries as $country)
$this->countries_array[$country['id_country']] = $country['name'];
$this->fields_list = array(
'id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
'firstname' => array('title' => $this->l('First Name'), 'filter_key' => 'a!firstname'),
'lastname' => array('title' => $this->l('Last Name'), 'filter_key' => 'a!lastname'),
'address1' => array('title' => $this->l('Address')),
'postcode' => array('title' => $this->l('Zip/Postal Code'), 'align' => 'right'),
'city' => array('title' => $this->l('City')),
'country' => array('title' => $this->l('Country'), 'type' => 'select', 'list' => $this->countries_array, 'filter_key' => 'cl!id_country'));
parent::__construct();
$this->_select = 'cl.`name` as country';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'customer` c ON a.id_customer = c.id_customer
';
$this->_where = 'AND a.id_customer != 0 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
}
public function initToolbar()
{
parent::initToolbar();
if (!$this->display)
$this->toolbar_btn['import'] = array(
'href' => $this->context->link->getAdminLink('AdminImport', true).'&import_type=addresses',
'desc' => $this->l('Import')
);
}
public function initPageHeaderToolbar()
{
if (empty($this->display))
$this->page_header_toolbar_btn['new_address'] = array(
'href' => self::$currentIndex.'&addaddress&token='.$this->token,
'desc' => $this->l('Add new address', null, null, false),
'icon' => 'process-icon-new'
);
parent::initPageHeaderToolbar();
}
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Addresses'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text_customer',
'label' => $this->l('Customer'),
'name' => 'id_customer',
'required' => false,
),
array(
'type' => 'text',
'label' => $this->l('Identification Number'),
'name' => 'dni',
'required' => false,
'col' => '4',
'hint' => $this->l('DNI / NIF / NIE')
),
array(
'type' => 'text',
'label' => $this->l('Address alias'),
'name' => 'alias',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'textarea',
'label' => $this->l('Other'),
'name' => 'other',
'required' => false,
'cols' => 15,
'rows' => 3,
'hint' => $this->l('Forbidden characters:').' <>;=#{}'
),
),
'submit' => array(
'title' => $this->l('Save'),
)
);
$id_customer = (int)Tools::getValue('id_customer');
if (!$id_customer && Validate::isLoadedObject($this->object))
$id_customer = $this->object->id_customer;
if ($id_customer)
{
$customer = new Customer((int)$id_customer);
$token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
}
$this->tpl_form_vars = array(
'customer' => isset($customer) ? $customer : null,
'tokenCustomer' => isset ($token_customer) ? $token_customer : null
);
// Order address fields depending on country format
$addresses_fields = $this->processAddressFormat();
// we use delivery address
$addresses_fields = $addresses_fields['dlv_all_fields'];
// get required field
$required_fields = AddressFormat::getFieldsRequired();
// Merge with field required
$addresses_fields = array_unique(array_merge($addresses_fields, $required_fields));
$temp_fields = array();
foreach ($addresses_fields as $addr_field_item)
{
if ($addr_field_item == 'company')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Company'),
'name' => 'company',
'required' => in_array('company', $required_fields),
'col' => '4',
'hint' => $this->l('Invalid characters:').' <>;=#{}'
);
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('VAT number'),
'col' => '2',
'name' => 'vat_number',
'required' => in_array('vat_number', $required_fields)
);
}
elseif ($addr_field_item == 'lastname')
{
if (isset($customer) &&
!Tools::isSubmit('submit'.strtoupper($this->table)) &&
Validate::isLoadedObject($customer) &&
!Validate::isLoadedObject($this->object))
$default_value = $customer->lastname;
else
$default_value = '';
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Last Name'),
'name' => 'lastname',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()##"�{}_$%:',
'default_value' => $default_value,
);
}
elseif ($addr_field_item == 'firstname')
{
if (isset($customer) &&
!Tools::isSubmit('submit'.strtoupper($this->table)) &&
Validate::isLoadedObject($customer) &&
!Validate::isLoadedObject($this->object))
$default_value = $customer->firstname;
else
$default_value = '';
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('First Name'),
'name' => 'firstname',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()##"�{}_$%:',
'default_value' => $default_value,
);
}
elseif ($addr_field_item == 'address1')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Address'),
'name' => 'address1',
'col' => '6',
'required' => true,
);
}
elseif ($addr_field_item == 'address2')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Address').' (2)',
'name' => 'address2',
'col' => '6',
'required' => in_array('address2', $required_fields),
);
}
elseif ($addr_field_item == 'address3')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Address').' (3)',
'name' => 'address3',
'col' => '6',
'required' => in_array('address3', $required_fields),
);
}
elseif ($addr_field_item == 'address4')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Address').' (4)',
'name' => 'address4',
'col' => '6',
'required' => in_array('address4', $required_fields),
);
}
elseif ($addr_field_item == 'postcode')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Zip/Postal Code'),
'name' => 'postcode',
'col' => '2',
'required' => true,
);
}
elseif ($addr_field_item == 'city')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('City'),
'name' => 'city',
'col' => '4',
'required' => true,
);
}
elseif ($addr_field_item == 'country' || $addr_field_item == 'Country:name')
{
$temp_fields[] = array(
'type' => 'select',
'label' => $this->l('Country'),
'name' => 'id_country',
'required' => in_array('Country:name', $required_fields) || in_array('country', $required_fields),
'col' => '4',
'default_value' => (int)$this->context->country->id,
'options' => array(
'query' => Country::getCountries($this->context->language->id),
'id' => 'id_country',
'name' => 'name'
)
);
$temp_fields[] = array(
'type' => 'select',
'label' => $this->l('State'),
'name' => 'id_state',
'required' => false,
'col' => '4',
'options' => array(
'query' => array(),
'id' => 'id_state',
'name' => 'name'
)
);
}
elseif ($addr_field_item == 'phone')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Home phone'),
'name' => 'phone',
'required' => in_array('phone', $required_fields) || Configuration::get('PS_ONE_PHONE_AT_LEAST'),
'col' => '4',
'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
);
}
elseif ($addr_field_item == 'phone_mobile')
{
$temp_fields[] = array(
'type' => 'text',
'label' => $this->l('Mobile phone'),
'name' => 'phone_mobile',
'required' => in_array('phone_mobile', $required_fields) || Configuration::get('PS_ONE_PHONE_AT_LEAST'),
'col' => '4',
'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
);
}
}
// merge address format with the rest of the form
array_splice($this->fields_form['input'], 3, 0, $temp_fields);
return parent::renderForm();
}
public function processSave()
{
if (Tools::getValue('submitFormAjax'))
$this->redirect_after = false;
// Transform e-mail in id_customer for parent processing
if (Validate::isEmail(Tools::getValue('email')))
{
$customer = new Customer();
$customer->getByEmail(Tools::getValue('email'), null, false);
if (Validate::isLoadedObject($customer))
$_POST['id_customer'] = $customer->id;
else
$this->errors[] = Tools::displayError('This email address is not registered.');
}
elseif ($id_customer = Tools::getValue('id_customer'))
{
$customer = new Customer((int)$id_customer);
if (Validate::isLoadedObject($customer))
$_POST['id_customer'] = $customer->id;
else
$this->errors[] = Tools::displayError('This customer ID is not recognized.');
}
else
$this->errors[] = Tools::displayError('This email address is not valid. Please use an address like bob#example.com.');
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) && !Tools::getValue('dni'))
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
/* If the selected country does not contain states */
$id_state = (int)Tools::getValue('id_state');
$id_country = (int)Tools::getValue('id_country');
$country = new Country((int)$id_country);
if ($country && !(int)$country->contains_states && $id_state)
$this->errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
/* If the selected country contains states, then a state have to be selected */
if ((int)$country->contains_states && !$id_state)
$this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
$postcode = Tools::getValue('postcode');
/* Check zip code format */
if ($country->zip_code_format && !$country->checkZipCode($postcode))
$this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.').'<br />'.Tools::displayError('It must be entered as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
elseif(empty($postcode) && $country->need_zip_code)
$this->errors[] = Tools::displayError('A Zip/postal code is required.');
elseif ($postcode && !Validate::isPostCode($postcode))
$this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile'))
$this->errors[] = Tools::displayError('You must register at least one phone number.');
/* If this address come from order's edition and is the same as the other one (invoice or delivery one)
** we delete its id_address to force the creation of a new one */
if ((int)Tools::getValue('id_order'))
{
$this->_redirect = false;
if (isset($_POST['address_type']))
$_POST['id_address'] = '';
}
// Check the requires fields which are settings in the BO
$address = new Address();
$this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
if (empty($this->errors))
return parent::processSave();
else
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
/* Reassignation of the order's new (invoice or delivery) address */
$address_type = ((int)Tools::getValue('address_type') == 2 ? 'invoice' : ((int)Tools::getValue('address_type') == 1 ? 'delivery' : ''));
if ($this->action == 'save' && ($id_order = (int)Tools::getValue('id_order')) && !count($this->errors) && !empty($address_type))
{
if (!Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET `id_address_'.$address_type.'` = '.Db::getInstance()->Insert_ID().' WHERE `id_order` = '.$id_order))
$this->errors[] = Tools::displayError('An error occurred while linking this address to its order.');
else
Tools::redirectAdmin(Tools::getValue('back').'&conf=4');
}
}
public function processAdd()
{
if (Tools::getValue('submitFormAjax'))
$this->redirect_after = false;
return parent::processAdd();
}
/**
* Get Address formats used by the country where the address id retrieved from POST/GET is.
*
* #return array address formats
*/
protected function processAddressFormat()
{
$tmp_addr = new Address((int)Tools::getValue('id_address'));
$selected_country = ($tmp_addr && $tmp_addr->id_country) ? $tmp_addr->id_country : (int)Configuration::get('PS_COUNTRY_DEFAULT');
$inv_adr_fields = AddressFormat::getOrderedAddressFields($selected_country, false, true);
$dlv_adr_fields = AddressFormat::getOrderedAddressFields($selected_country, false, true);
$inv_all_fields = array();
$dlv_all_fields = array();
$out = array();
foreach (array('inv','dlv') as $adr_type)
{
foreach (${$adr_type.'_adr_fields'} as $fields_line)
foreach (explode(' ', $fields_line) as $field_item)
${$adr_type.'_all_fields'}[] = trim($field_item);
$out[$adr_type.'_adr_fields'] = ${$adr_type.'_adr_fields'};
$out[$adr_type.'_all_fields'] = ${$adr_type.'_all_fields'};
}
return $out;
}
/**
* Method called when an ajax request is made
* #see AdminController::postProcess()
*/
public function ajaxProcess()
{
if (Tools::isSubmit('email'))
{
$email = pSQL(Tools::getValue('email'));
$customer = Customer::searchByName($email);
if (!empty($customer))
{
$customer = $customer['0'];
echo Tools::jsonEncode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company'])));
}
}
die;
}
/**
* Object Delete
*/
public function processDelete()
{
if (Validate::isLoadedObject($object = $this->loadObject()))
if (!$object->isUsed())
$this->deleted = false;
return parent::processDelete();
}
/**
* Delete multiple items
*
* #return boolean true if succcess
*/
protected function processBulkDelete()
{
if (is_array($this->boxes) && !empty($this->boxes))
{
$deleted = false;
foreach ($this->boxes as $id)
{
$to_delete = new Address((int)$id);
if ($to_delete->isUsed())
{
$deleted = true;
break;
}
}
$this->deleted = $deleted;
}
return parent::processBulkDelete();
}
}
I also tried clearing cache using the Advanced Parameters > Performance and also did a manual cache clearance as well.
What might the problem be as to not showing the new address fields in backend or the frontend?
Try also delete (no worries it will be rebuid) class_index.php file at cache folder of Your store

Zend2 combine tablegateway array

I'm new to Zend2, and want to combine two tablegateway objects
I have two tables: prices and sizes. Every price has multiple sizes.
I want to join these tables into an array, so I can list the prices with the sizes in it.
For example:
array(
1 => array(
'price' => 45,
'description' => 'Lorem ipsum',
'sizes' => array(
1 => '16',
2 => '17',
3 => '20',
4 => '21'
)
),
2 => array(
'price' => 50,
'description' => 'Lorem ipsum',
'sizes' => array(
1 => '34',
2 => '12',
3 => '21',
4 => '50'
)
)
)
My PricesTable.php:
public function getPricesbyJewel($jewel)
{
$rowset = $this->tableGateway->select(array('jewelid' => $jewel));
return $rowset;
}
My SizesTable.php
public function getSizesbyPrice($price)
{
$rowset = $this->tableGateway->select(array('priceid' => $price));
return $rowset;
}
How I list the prices (so without the sizes in it)
$jewelPrices = array('jewelryPrices' => $this->getPricesTable()->getPricesbyJewel($jewel->id));
$jewelSizes = array('jewelrySizes' => $this->getSizesTable()->getSizesbyPrice($priceID);
How to list the sizes into the prices as an array of those tables in the controller?
Fixed it with an inner join:
PriceTable.php
public function getPricesbyJewel($jewel)
{
$sql = new Sql($this->tableGateway->getAdapter());
$select = $sql->select();
$select->from('jewelry_prices')
->join('jewelry_sizes', 'jewelry_prices.id=jewelry_sizes.priceID')
->where('jewelry_prices.jewelid='.$jewel);
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
Controller:
$prices = array('jewelryPrices' => array());
foreach($this->getPricesTable()->getPricesbyJewel($jewel->id) as $key => $price){
if(!array_key_exists($price->priceID, $prices['jewelryPrices'])){
$prices['jewelryPrices'][$price->priceID] = array(
'orderNote' => $price->orderNote,
'price' => $price->price,
'description' => $price->description,
'sizes' => array()
);
array_push($prices['jewelryPrices'][$price->priceID]['sizes'], $price->size);
} else {
array_push($prices['jewelryPrices'][$price->priceID]['sizes'], $price->size);
}
}

How To Integrate Easypay.pt API With Opengateway

I need to integrate Easypay.pt with opengateway so if any one know somehting about this i would like to know if some one can help for this i will appreciate thanks
function Settings () {
$settings = array();
$settings['name'] = 'Easypay';
$settings['class_name'] = 'easypay';
$settings['external'] = FALSE;
$settings['no_credit_card'] = FALSE;
$settings['description'] =
'Easypay is a portuguese company that offers a universal payment
platform and is certified by SIBS, Unicre, Visa and MasterCard. Our
primary mission is helping the market to shorten the payment
processing time and offer greater flexibility and convenience in
payment.';
$settings['is_preferred'] = 1;
$settings['setup_fee'] = '$0.00';
$settings['monthly_fee'] = '$30.00';
$settings['transaction_fee'] = '2.5% + $0.30';
$settings['purchase_link'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_updates'] = 0;
$settings['url_live'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php ';
$settings['url_test'] = 'http://test.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_refunds'] = 1;
$settings['requires_customer_information'] = 1;
$settings['requires_customer_ip'] = 1;
$settings['required_fields'] = array(
'enabled',
'mode',
'ep_cin',
'ep_user',
'ep_ref_type',
'ep_entity',
't_key',
'ep_language',
'ep_country'
);
$settings['field_details'] = array(
'enabled' => array(
'text' => 'Enable this gateway?',
'type' => 'radio',
'options' => array(
'1' => 'Enabled',
'0' => 'Disabled'
)
),
'mode' => array(
'text' => 'Mode',
'type' => 'select',
'options' => array(
'live' => 'Live Mode',
'test' => 'Test Mode'
)
),
'ep_cin' => array(
'text' => 'Client Identification Number',
'type' => 'text'
),
'ep_user' => array(
'text' => 'Username',
'type' => 'text'
),
'ep_ref_type' => array(
'text' => 'Type of Identifier',
'type' => 'select',
'options' => array(
'auto' => 'Auto',
)
),
'ep_type' => array(
'text' => 'Type',
'type' => 'select',
'options' => array(
'boleto' => 'Boleto',
)
),
'ep_entity' => array(
'text' => 'Entity in use by Your Account.',
'type' => 'text',
),
't_key' => array(
'text' => 'Transaction key',
'type' => 'text',
),
'ep_language' => array(
'text' => 'Language',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
),
'ep_country' => array(
'text' => 'Currency',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
)
);
return $settings;
}
function TestConnection($client_id, $gateway) {
// Get the proper URL
switch($gateway['mode']) {
case 'live':
$post_url = $gateway['url_live'];
break;
case 'test':
$post_url = $gateway['url_test'];
break;
}
$post = array();
$post['ep_cin'] = $gateway['ep_cin'];
$post['ep_user'] = $gateway['ep_user'];
$post['ep_entity'] = $gateway['ep_entity'];
$post['ep_ref_type'] = $gateway['ep_ref_type'];
$post['ep_type'] = 'boleto';
$post['t_value'] = '504.4';
$post['ep_country'] = $gateway['ep_country'];
$post['ep_language'] = $gateway['ep_language'];
$post['s_code'] = 'sssssssssssyour code ddddddd';
$post['t_key'] = $gateway['t_key'];;
$response = $this->Process($post_url, $post);
$status=$response->ep_status;
//$CI =& get_instance();
if($status != 'err1') {
return TRUE;
} else {
return FALSE;
}
}
//--------------------------------------------------------------------
function Process($url, $post, $order_id = FALSE) {
$response = simplexml_load_file(
$url . "ep_cin=" . $post['ep_cin'] . "&ep_user=" . $post['ep_user']
. "&ep_entity=" . $post['ep_entity'] . "&ep_ref_type=" . $post['ep_ref_type']
. "&ep_type=" . $post['ep_type'] . "&ep_country=" . $post['ep_country']
. "&ep_language='" . $post['ep_language'] . "'&s_code=" . $post['s_code']
. "&t_key=" . $post['t_key'] . "&t_value=" . $post['t_value']
);
return $response;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
private function response_to_array($string) {
$string = urldecode($string);
$pairs = explode('&', $string);
$values = array();
foreach($pairs as $pair) {
list($key, $value) = explode('=', $pair);
$values[$key] = $value;
}
return $values;
}