Opencart-2.1.0.2 custom field sort order issue with registration page - opencart2.x

I have installed open cart version 2.1.0.2.
I have added one custom field named phone number from administrator section and assigned the sort-order 6 to this field.
When I check the registration page I am unable to see this field, but when I change the sort order to 5 or 7 then this field is visible . I am not sure why for sort order 6, this field does not show on registration page.

In registration field, there is one condition missing in javascript for sort order in custom filed
Condition : When data-sort is equal to form-group lenght
Update you code with following in your register.tpl file. line no arround 533.
<script type="text/javascript"><!--
// Sort the custom fields
$('#account .form-group[data-sort]').detach().each(function() {
if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('#account .form-group').length) {
$('#account .form-group').eq($(this).attr('data-sort')).before(this);
}
if ($(this).attr('data-sort') > $('#account .form-group').length) {
$('#account .form-group:last').after(this);
}
if ($(this).attr('data-sort') == $('#account .form-group').length) {
$('#account .form-group:last').after(this);
}
if ($(this).attr('data-sort') < -$('#account .form-group').length) {
$('#account .form-group:first').before(this);
}
});
$('#address .form-group[data-sort]').detach().each(function() {
if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('#address .form-group').length) {
$('#address .form-group').eq($(this).attr('data-sort')).before(this);
}
if ($(this).attr('data-sort') > $('#address .form-group').length) {
$('#address .form-group:last').after(this);
}
if ($(this).attr('data-sort') == $('#address .form-group').length) {
$('#address .form-group:last').after(this);
}
if ($(this).attr('data-sort') < -$('#address .form-group').length) {
$('#address .form-group:first').before(this);
}
});
</script>

Related

Create a search bar with multiple columns in codeigniter

Controller:
public function search_products_auto(){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('homemodel','',TRUE);
$this->homemodel->search_products_auto();
}
public function search($subcategory=''){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('homemodel','',TRUE);
$search_name=$this->input->post("title"); // first get search character
$data['records']=$this->homemodel->search($search_name,$_GET); // SearchModel is the model class name
$data['category']=$this->homemodel->getAllCategories();
$data['subcategory']=$subcategory;
$data['mens']=$this->homemodel->getAllMen();
$data['womens']=$this->homemodel->getAllWomen();
$data['scarves']=$this->homemodel->getAllScarve();
$data['collections']=$this->homemodel->getAllCollection();
$data['material']=['Cotton'=>'Cotton','Polyster'=>'Polyster'];
$data['color']=['Red'=>'Red','Black'=>'Black','Blue'=>'Blue','Green'=>'Green','Orange'=>'Orange','Black'=>'Black'];
$data['size'] =['S'=>'S','M'=>'M','L'=>'L','XL'=>'XL','XXL'=>'XXL','XXL'=>'XXL'];
$data['subcat']=$this->homemodel->getAllSubCat($search_name,$_GET);
$data['price']=$this->homemodel->getPrice($search_name,$_GET);
$this->load->view('products',$data);
}
Model:
function search($search_name,$search=array(),$cat_array=array()){
$search=array_filter($search);
$this->db->select('product.*');
$this->db->select('product_images.features');
$this->db->select('product_images.image');
$this->db->from('product');
$this->db->join('product_images',"product.id=product_images.product_id and product_images.features='yes'");
$this->db->join('product_material',"product.id=product_material.product_id",'left');
$this->db->join('product_color',"product.id=product_color.product_id",'left');
$this->db->join('product_size',"product.id=product_size.product_id",'left');
if(isset($cat_array->sub_cat_id) && $cat_array->sub_cat_id!=''){
$this->db->where('product.product_subcategory',$cat_array->sub_cat_id);
}
if(isset($search['material']) && $search['material']!=''){
$this->db->where_in('product_material.material',explode(",",$search['material']));
}
if(isset($search['color']) && $search['color']!=''){
$this->db->where_in('product_color.color',explode(",",$search['color']));
}
if(isset($search['size']) && $search['size']!=''){
$this->db->where_in('product_size.size',explode(",",$search['size']));
}
if(isset($search['price']) && $search['price']!=''){
$this->db->where_in('product.product_price',explode(",",$search['price']));
}
if(isset($search['search']) && $search['search']!=''){
$this->db->or_like(array('product.product_name'=>$search['search'],'product.sku_number'=>$search['search']));
}
$this->db->or_like(array('product.product_name'=>$search_name,'product.sku_number'=>$search_name));
$this->db->where("product.status='active'");
$this->db->group_by(['product_color.product_id','product_material.product_id','product_size.product_id']);
$query=$this->db->get();
$result=$query->result();
return $result;
}
function search_products_auto(){
$search_item = $this->input->post('query');
$this->db->select(['product.id','product.product_name','product.sku_number']);
$this->db->from('product');
if($search_item!=''){
$this->db->or_like(array('product.product_name'=>$search_item,'product.sku_number'=>$search_item));
}
$this->db->where("product.status='active'");
$query=$this->db->get();
$result=$query->result();
$dataSearch=[];
if(count($result)>0){
$i=0;
foreach($result as $results)
{
$dataSearch[$i]['id']=isset($results->id)?$results->id:"";
$dataSearch[$i]['name']=isset($results->product_name)?$results->product_name:"";
$dataSearch[$i]['name']=isset($results->sku_number)?$results->sku_number:"";
$i++;
}
}
echo json_encode($dataSearch);
}
Now, I am getting only sku number values in search bar...not the other value. How can I get all three in one search bar. I am unable to understand the concept of integrating three into one array.Rest of the things are working properly, except this search bar and also the search results are also not fine.
Please try these code it may help you, I have change only in Model:
function search($search_name, $search=array(), $cat_array=array()){
$search = array_filter($search);
$this->db->select('product.*');
$this->db->select('product_images.features');
$this->db->select('product_images.image');
$this->db->from('product');
$this->db->join('product_images',"product.id=product_images.product_id and product_images.features='yes'");
if(isset($cat_array->sub_cat_id) && $cat_array->sub_cat_id!=''){
$this->db->where('product.product_subcategory',$cat_array->sub_cat_id);
}
if(isset($search['price']) && $search['price']!=''){
$this->db->where_in('product.product_price',explode(",", $search['price']));
}
if(isset($search['search']) && $search['search']!=''){
$this->db->or_like(array('product.product_name' => $search['search'],'product.sku_number' => $search['search']));
}
if(isset($search['material']) && $search['material']!=''){
$this->db->join('product_material',"product.id=product_material.product_id",'left');
$this->db->where_in('product_material.material',explode(",",$search['material']));
}
if(isset($search['color']) && $search['color']!=''){
$this->db->join('product_color',"product.id=product_color.product_id",'left');
$this->db->where_in('product_color.color',explode(",",$search['color']));
}
if(isset($search['size']) && $search['size']!=''){
$this->db->join('product_size',"product.id=product_size.product_id",'left');
$this->db->where_in('product_size.size',explode(",",$search['size']));
}
$this->db->or_like( array('product.product_name' => $search_name, 'product.sku_number' => $search_name));
$this->db->where("product.status='active'");
$this->db->group_by(['product_color.product_id','product_material.product_id','product_size.product_id']);
$query = $this->db->get();
$result_array = $query->result_array();
/* $result=$query->result(); */
return $result_array;
}
function search_products_auto(){
$search_item = $this->input->post('query');
$this->db->select(['product.id','product.product_name','product.sku_number']);
$this->db->from('product');
if($search_item != ''){
$this->db->or_like(array('product.product_name' => $search_item, 'product.sku_number' => $search_item));
}
$this->db->where("product.status","active");
$query = $this->db->get();
/* $result=$query->result();
$dataSearch=[];
if(count($result)>0){
$i=0;
foreach($result as $results)
{
$dataSearch[$i]['id']=isset($results->id)?$results->id:"";
$dataSearch[$i]['name']=isset($results->product_name)?$results->product_name:"";
$dataSearch[$i]['sku_number']=isset($results->sku_number)?$results->sku_number:"";
$i++;
}
}
echo json_encode($dataSearch); */
echo json_encode($query->result_array());
}

How generate yii2 captcha and verifycode be unmber without any word?

I am trying to generate a captcha in yii2 with a verify code in number instead of string.
is there any way?
Extend CaptchaAction with your own class and override generateVerifyCode() there like:
<?php
namespace common\captcha;
use yii\captcha\CaptchaAction as DefaultCaptchaAction;
class CaptchaAction extends DefaultCaptchaAction
{
protected function generateVerifyCode()
{
if ($this->minLength > $this->maxLength) {
$this->maxLength = $this->minLength;
}
if ($this->minLength < 3) {
$this->minLength = 3;
}
if ($this->maxLength > 8) {
$this->maxLength = 8;
}
$length = mt_rand($this->minLength, $this->maxLength);
$digits = '0123456789';
$code = '';
for ($i = 0; $i < $length; ++$i) {
$code .= $digits[mt_rand(0, 9)];
}
return $code;
}
}
In this example class is saved in common\captcha folder. Remember to change the namespace if you would like to save it somewhere else.
Now you just need to use it in controller:
public function actions()
{
return [
'captcha' => [
'class' => 'common\captcha\CaptchaAction', // change this as well in case of moving the class
],
];
}
The rest is exactly the same like with default captcha.

Pagination link not work properly?

Pagination not work properly?
I saved this code in "Forum-Com.php" file and when i open this file, pagination works properly and correctly but when I include this file in another page, its open first page correctly but when I click second or another page link it open same comments which are on first page. Please help me. ( I am using Scriptsmill comments script v1.06 and function make_pages_string from admin.php )
$COM_CONF['full_path'] = dirname(__FILE__);
function make_pages_string ($all_count, $records_per_page, $cur_page, $base_url) {
if ($all_count > $records_per_page) {
if ($cur_page > 0) { $cur_page=$cur_page-1; }
$first_record = ($cur_page) * $records_per_page;
$limit_string = "LIMIT $first_record, $records_per_page";
$pages=$all_count/$records_per_page;
if ($pages > (int) $pages) { $pages=(int)$pages+1; }
}
if ($pages>1) {
$pages_string.="Page: ";
if ($cur_page>10 && $pages>20) { $first_page=$cur_page-9; }
else { $first_page=1; }
if ($pages>20 && ($cur_page+10)<$pages) { $last_page=$first_page+19; }
else { $last_page=$pages; }
if ($cur_page+1>1) {
$prev=$cur_page;
$pages_string.="<a href='$base_url&page=$prev'>&lt</a> ";
}
for ($i=$first_page; $i<=$last_page; $i++){
if ($i != $cur_page+1) {
$pages_string.="<a href='$base_url&page=$i'>$i</a> ";
}
else {
$pages_string.="<b>$i</b> ";
}
}
if ($cur_page+1<$pages) {
$next=$cur_page+2;
$pages_string.="<a href='$base_url&page=$next'>&gt</a> ";
}
}
return array ($pages_string, $limit_string);
}
function smcom_view()
{
global $comments_db_link, $COM_CONF, $COM_LANG;
$result = mysql_query("select COUNT(id) from {$COM_CONF['dbmaintable']}", $comments_db_link);
list ($all_count) = mysql_fetch_row($result);
list ($pages_string, $limit_string) = make_pages_string ($all_count, 10, $_REQUEST['page'], "{$COM_CONF['base_url']}?action=view");
$result = mysql_query("select time, text, author, email, dont_show_email from {$COM_CONF['dbmaintable']} order by time {$COM_CONF['sort_order']} $limit_string", $comments_db_link);
$comments_count=0;
$id=$time=$text=$author=$email=$dont_show_email=$ip=array();
while (list($id[$comments_count], $time[$comments_count], $text[$comments_count], $author[$comments_count], $email[$comments_count], $dont_show_email[$comments_count], $ip[$comments_count])=mysql_fetch_array($result)) {
$comments_count++;
}
require("{$COM_CONF['full_path']}/templates/Forum-default.php");
}
The code given above has no problem at all. The problem is with the server configuration which turned off $_REQUEST global variable from direct access.

conditional ObservableForProperty

I'm new in WPF trying to use ReactiveUI,
I want to call 3 different method based on property value changed.
so
public int Number
{
set
{
number = val;
if (_number == 1) Call1()
else if (_number == 2) call2()
else if (_number == 3) call3()
}
}
above is working but now I'm trying using ReactiveUI
so what i did
this.ObservableForProperty(x => x._number).Subscribe( => Call1());
is there any way to achieve above?
If you set up your property like this (assuming your class derives from ReactiveObject):
public int Number
{
get
{
return _number;
}
set
{
this.RaiseAndSetIfChanged(ref _number, value);
}
}
Or, you need to get it to fire property changed notifications some other way.
You didn't say if you are observing the property within the class itself or from a different one. For example, is this all occurring in your ViewModel or in your View watching your ViewModel?
If within the ViewModel with the Number property, I would try something along these lines:
this.WhenAnyValue(t => t.Number)
.Subscribe(i =>
{
if (i == 1)
{
Call1();
}
else if (i == 2)
{
Call2();
}
else if (i == 3)
{
Call3();
}
}
);
If you were in your View that had a ViewModel property holding the ViewModel with the Number property I would try:
this.ObservableForProperty(t => t.ViewModel.Number,i => i)
.Subscribe(i =>
{
if (i == 1)
{
Call1();
}
else if (i == 2)
{
Call2();
}
else if (i == 3)
{
Call3();
}
}
);
How about this:
this.WhenAnyValue(x => x.Number)
.Where(x => x == 1)
.Subscribe(Call1);

SharePoint 2007: AfterProperties of person input field shows always -1 as lookupid

I'm struggling with the SharePoint 2007 AfterProperties. I've a people input field, where several people can be added.
On the ItemUpdating event I now need to determine which users were added, removed or stayed the same.
Unfortunately this becomes quit difficult, as the id of the untouched users turns to -1 in the AfterProperties, so that I cant not use SPFieldUserValueCollection to find the user.
An example. properties.ListItem["AssignedTo"].ToString() shows:
1;#domain\user1;#2;#domain\user2
properties.AfterProperties["AssignedTo"].ToString() shows:
-1;#domain\user1;#-1;#domain\user2;#3;#domain\user3 <-Added a user
I planned to use following code, to determine removed and added users:
foreach (SPFieldUserValue oldUser in oldUserCollection)
{
if (newUserCollection.Find(x => x.LookupId == oldUser.LookupId) == null)
{
RemoveRole(aListItem, oldUser.User, roleDefCollection[workerRoleName]);
}
}
foreach (SPFieldUserValue newUser in newUserCollection)
{
if(oldUserCollection.Find(x => x.User.LoginName == newUser.LookupValue) == null)
{
AddRole(aListItem, newUser.User, roleDefCollection[workerRoleName]);
}
}
How can I archive, that the AfterProperties show the right lookupid?
Solved the problem by myself. Instead of using the SPFieldUserCollection I'm now using a list and try to parse all the information by myself out of the string.
Regex reg = new Regex(#"\;\#");
string[] usernameParts = reg.Split(usernames);
List<SPUser> list = new List<SPUser>();
int id;
foreach (string s in usernameParts)
{
if (!string.IsNullOrEmpty(s))
{
if (!Int32.TryParse(s, out id))
{
if (list.Find(x => x.ID == spweb.Users[s].ID) == null)
list.Add(spweb.Users[s]);
}
else
{
if (Convert.ToInt32(s) != -1)
{
if (list.Find(x => x.ID == Convert.ToInt32(s)) == null)
list.Add(spweb.Users.GetByID(Convert.ToInt32(s)));
}
}
}
}

Resources