CakePHP Search plugin search in many fields - search

I'm using CakePHP search plugin http://cakedc.com/downloads/view/cakephp_search_plugin and want to make an arg to search multiple fields I have the array filterArgs as follows
var $filterArgs = array(
array('name' => 'search', 'type' => 'like', 'field' => 'Interview.title_en'),
);
I want the search arg to search not only the field Interview.title_en but to search also another field I tried something like
var $filterArgs = array(
array('name' => 'search', 'type' => 'like', 'field' => array('Interview.title_en', 'Interview.Desc'));
but It doesn't work!!
Any suggestions?

In order to achieve this, you have to create a simple method in your model which builds the 'OR' conditions for searching the fields.
public $filterArgs = array(
array('name' => 'q', 'type' => 'query', 'method' => 'filterQuery'),
);
public function filterQuery($data = array()) {
if(empty($data['q'])) { // q is the name of my search field
return array();
}
$query = '%'.$data['q'].'%';
return array(
'OR' => array(
'Model.title LIKE' => $query,
'Model.description LIKE' => $query,
'Model.resources LIKE' => $query,
)
);
}

Related

Article(Product) is not showing in front which is created using API article

I have created one product using api of shopware.
Reference: https://developers.shopware.com/developers-guide/rest-api/api-resource-article/
This product(article) is listed in Item -> Overview of shopware. But when I edit this product and try to Preview this product(article) that How it looks in front, it does not show in front. It shows :
Unfortunately, this product is no longer available.
Can Someone help me why this product is not showing in front? I want to show the article in the front which I have created using API in my Plugin.
My array for insert article data in shopware is following.
$client->post('articles',
array(
'name' => 'Damen Organic T-Shirt',
'description' => 'Description',
'descriptionLong' => 'Test Description',
'active' => 1,
'taxId' => 1,
'metaTitle' => '',
'keywords' => '',
'changetime' => date("Y-m-d H:i:s"),
'notification' => 0,
'supplier' => 'Shirtee',
'categories' => 'Shopware',
'mainDetail' => array(
'number' => 'MO1C38Q',
'inStock' => 1,
'weight' => '1.000',
'position' => '1',
'width' => null,
'height' => null,
'attribute' => array(
'attr1' => '',
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 50,
),
),
),
'images' => array(
'link' => 'test.png'
),
'configuratorSet' => array(
'groups' => array(
array(
'name' => 'Size',
'options' => 'M'
),
array(
'name' => 'Color',
'options' => 'Green'
),
)
)
));
Your answer will really help me out.
It is required to pass active => true within mainDetail as shown in the example:
$minimalTestArticle = array(
'name' => 'Sport Shoes',
'active' => true,
'tax' => 19,
'supplier' => 'Sport Shoes Inc.',
'categories' => array(
array('id' => 15),
),
'mainDetail' => array(
'number' => 'turn',
'active' => true,
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 999,
),
)
),
);
$client->post('articles', $minimalTestArticle);
Following is the query that you can find within engine/Shopware/Bundle/StoreFrontBundle/Service/Core/ProductNumberService.php -> isNumberAvailable
SELECT variant.ordernumber FROM s_articles_details variant INNER JOIN s_articles product ON product.id = variant.articleID AND variant.active = 1 WHERE (variant.ordernumber = 'number') AND ((variant.laststock * variant.instock) >= (variant.laststock * variant.minpurchase)) LIMIT 1
Also, it is required to set active => true for each variation if you creating them.

Custom Taxonomy and tax_query Issue?

I am working on Plugin development and my plugin name is plugindev.I have a custom post type called team.I have a custom taxonomy Team_Category which is being registered by this code
/***************************taxonomy****************************/
add_action( 'init', 'create_team_taxonomies', 0 );
function create_team_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Team_Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Team_Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Team_Categories' ),
'all_items' => __( 'All Team_Categories' ),
'parent_item' => __( 'Parent Team_Category' ),
'parent_item_colon' => __( 'Parent Team_Category:' ),
'edit_item' => __( 'Edit Team_Category' ),
'update_item' => __( 'Update Team_Category' ),
'add_new_item' => __( 'Add New Team_Category' ),
'new_item_name' => __( 'New Team_Category Name' ),
'menu_name' => __( 'Team_Category' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'Team_Category' ),
);
register_taxonomy( 'Team_Category', array( 'team' ), $args );
}
/****************************taxanomy end***********************************/
But when I use a tax_query in my WP_Query, I do not get any posts.
here is my code
<?php
$taxonomy_name = 'Team_Category';
$get_categories = get_terms($taxonomy_name);
$total_categories = count($get_categories);
// Loop through the obituaries:
for ($i = 0; $i < $total_categories; $i++) {
?>
<div class="row">
<div class="col-md-4">
<?php echo $category_name = $get_categories[$i]->name; ?>
</div>
<?php
$args = array(
'post_type' => 'team',
'tax_query' => array(
array(
'taxonomy' => 'Team_Category',
'field' => 'slug', 'terms' => $category_name,)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
the_title();
}
}
wp_reset_query(); ?>
</div>
<?php }
It works perfectly without tax_query.I did lot of google but found no suitable result.Any solution to solve this problem .Any help would be highly appreciated
register_taxonomy()
$taxonomy (string) (required) The name of the taxonomy. Name should
only contain lowercase letters and the underscore character, and not
be more than 32 characters long (database structure restriction).
change your taxonomy name from Team_Category to team_category
you should then be able to use argument like this
$arg = array(
'post_type' => 'team',
'taxonomy' => 'team_category',
'term' => 'term_name',
);
//using tax_query
$mytax = get_terms('your_taxonomy');
$arg = array(
'post_type' => 'team',
'tax_query' => array(
array(
'taxonomy' => 'team_category',
'field' => 'slug',
'terms' => 'term_slug', //you need to use slug not name $mytax[0]->slug;
#or
//'field' => 'name',
//'terms' => 'term_name', //you need to use term name $mytax[0]->name;
#or
//'field' => 'term_id',
//'terms' => 'term_ID', //you need to use term ID $mytax[0]->term_id;
),
),
);
WP_Query($nivelquery) and the loop will now print every post registered using my custom taxonomy in $terms, and order them by the meta_key 'salary'.
$terms = get_terms('Team_Category',
array(
'orderby' => 'slug',
'order' => 'ASC',
'hide_empty' => 1,
'fields' => 'ids',
));
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'vagas_tipo',
'field' => 'id',
'terms' => $terms,
),
),
'orderby' => 'meta_value',
'meta_key' => 'salary',
'order' => 'DESC'
);
$query = new WP_Query($args);

Exclude custom taxonomy

I have a custom post type 'listings' and one of its taxonomies is 'status'. I want to create two widgets:
display all 'listings' WITH 'status' 'sold'.
display all 'listings' WITHOUT 'status' 'sold'.
I've achieved the first widget using
query_posts( array(
'status' => 'sold' )
);
I can't create the second widget. It should be like "status => !sold", or exclude sold. Any ideas?
Try below code when you need status = sold
$args = array(
'post_type' => 'listing',
'meta_query' => array(
array(
'key' => 'status',
'value' => 'sold',
'compare' => 'LIKE'
)
)
);
$myQuery = new WP_Query($args);
And below code when you want status != sold
$args1 = array(
'post_type' => 'listing',
'meta_query' => array(
array(
'key' => 'status',
'value' => 'sold',
'compare' => 'NOT LIKE'
)
)
);
$myQuery1 = new WP_Query($args1);
This works perfectly...
query_posts( array(
'post_type' => 'listings',
'tax_query' => array(
array(
'taxonomy' => 'status',
'field' => 'slug',
'terms' => 'sold',
'operator' => 'NOT IN'
),
)
)
);
This code excludes status => sold from post_type => listings

Cakephp Group By pagination is not working

While i'm using "group by" query, the pagination is not showing up.. Only the first page were shows...
If anyone have a solution for this, Please post an example.. Thanks in advance
Add GROUP BY clause
var $paginate = array(
'MyModel' => array(
'limit' => 20,
'order' => array('week' => 'desc'),
'group' => array('week', 'home_team_id', 'away_team_id')
)
);
Or on-the-fly from within the action
function index() {
$this->paginate = array(
'MyModel' => array(
'limit' => 20,
'order' => array('week' => 'desc'),
'group' => array('week', 'home_team_id', 'away_team_id')
)
);
}

How Kohana implement sessions saved to database?

the source code hands Session_Cookie and Session_Native class but the Session_Database,
here the config file
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'database' => array(
'database' => array(
'name' => 'blog_session_cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => 'default',
'table' => 'sessions',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
),
);
usage
$session = Session::Instance("Database");
$session->set('username', 'far');
great, its added a column in database, amusing! How the core do that?
thank you.
It's handled by Session_Database class in Database module
See the source: https://github.com/kohana/database/blob/3.2/master/classes/kohana/session/database.php
To implement database session mechanism there is Auth_ORM class in Kohana 3.2.

Resources