admin search in customer and products
This commit is contained in:
@@ -253,7 +253,7 @@ abstract class BaseLoop
|
||||
$searchTerm = explode(' ', $searchTerm);
|
||||
break;
|
||||
case SearchLoopInterface::MODE_SENTENCE:
|
||||
$searchCriteria = Criteria::EQUAL;
|
||||
$searchCriteria = Criteria::LIKE;
|
||||
$searchTerm = '%' . $searchTerm . '%';
|
||||
break;
|
||||
case SearchLoopInterface::MODE_STRICT_SENTENCE:
|
||||
@@ -262,8 +262,6 @@ abstract class BaseLoop
|
||||
}
|
||||
|
||||
$this->doSearch($search, $searchTerm, $searchIn, $searchCriteria);
|
||||
|
||||
$in = 'true';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
*/
|
||||
interface SearchLoopInterface
|
||||
{
|
||||
const MODE_ANY_WORD = 1;
|
||||
const MODE_SENTENCE = 2;
|
||||
const MODE_STRICT_SENTENCE = 3;
|
||||
const MODE_ANY_WORD = 'any_word';
|
||||
const MODE_SENTENCE = 'sentence';
|
||||
const MODE_STRICT_SENTENCE = 'strict_sentence';
|
||||
|
||||
/**
|
||||
* @return array of available field to search in
|
||||
|
||||
@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Element\SearchLoopInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
@@ -44,7 +45,7 @@ use Thelia\Type;
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Customer extends BaseLoop
|
||||
class Customer extends BaseLoop implements SearchLoopInterface
|
||||
{
|
||||
public $timestampable = true;
|
||||
|
||||
@@ -67,6 +68,47 @@ class Customer extends BaseLoop
|
||||
);
|
||||
}
|
||||
|
||||
public function getSearchIn()
|
||||
{
|
||||
return array(
|
||||
"ref",
|
||||
"firstname",
|
||||
"lastname",
|
||||
"email",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CustomerQuery $search
|
||||
* @param $searchTerm
|
||||
* @param $searchIn
|
||||
* @param $searchCriteria
|
||||
*/
|
||||
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
|
||||
{
|
||||
|
||||
$search->_and();
|
||||
foreach($searchIn as $index => $searchInElement) {
|
||||
if($index > 0) {
|
||||
$search->_or();
|
||||
}
|
||||
switch($searchInElement) {
|
||||
case "ref":
|
||||
$search->filterByRef($searchTerm, $searchCriteria);
|
||||
break;
|
||||
case "firstname":
|
||||
$search->filterByFirstname($searchTerm, $searchCriteria);
|
||||
break;
|
||||
case "lastname":
|
||||
$search->filterByLastname($searchTerm, $searchCriteria);
|
||||
break;
|
||||
case "email":
|
||||
$search->filterByEmail($searchTerm, $searchCriteria);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Element\SearchLoopInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
@@ -53,7 +54,7 @@ use Thelia\Type;
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Product extends BaseI18nLoop
|
||||
class Product extends BaseI18nLoop implements SearchLoopInterface
|
||||
{
|
||||
public $timestampable = true;
|
||||
public $versionable = true;
|
||||
@@ -129,6 +130,39 @@ class Product extends BaseI18nLoop
|
||||
);
|
||||
}
|
||||
|
||||
public function getSearchIn()
|
||||
{
|
||||
return array(
|
||||
"ref",
|
||||
"title",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProductQuery $search
|
||||
* @param $searchTerm
|
||||
* @param $searchIn
|
||||
* @param $searchCriteria
|
||||
*/
|
||||
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
|
||||
{
|
||||
|
||||
$search->_and();
|
||||
foreach($searchIn as $index => $searchInElement) {
|
||||
if($index > 0) {
|
||||
$search->_or();
|
||||
}
|
||||
switch($searchInElement) {
|
||||
case "ref":
|
||||
$search->filterByRef($searchTerm, $searchCriteria);
|
||||
break;
|
||||
case "title":
|
||||
$search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".$searchCriteria." ?", $searchTerm, \PDO::PARAM_STR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
|
||||
@@ -22,6 +22,94 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
{* customer search *}
|
||||
<div class="general-block-decorator">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<caption class="clearfix">
|
||||
{intl l='Customer'}
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="object-title">
|
||||
{intl l="customer ref"}
|
||||
</th>
|
||||
|
||||
<th class="object-title">
|
||||
{intl l="company"}
|
||||
</th>
|
||||
|
||||
<th>
|
||||
{intl l="firstname & lastname"}
|
||||
</th>
|
||||
|
||||
<th>
|
||||
{intl l="last order"}
|
||||
</th>
|
||||
|
||||
<th>{intl l='order amount'}</th>
|
||||
|
||||
<th class="actions">{intl l="Actions"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{loop name="customer_list" type="customer" current="false" visible="*" backend_context="1" search_term=$smarty.get.search_term search_in="ref,firstname,lastname,email"}
|
||||
{assign "lastOrderDate" ''}
|
||||
{assign "lastOrderAmount" ''}
|
||||
{assign "lastOrderCurrency" ''}
|
||||
|
||||
{loop type="order" name="last-order" customer=$ID order="create-date-reverse" limit="1"}
|
||||
{assign "lastOrderDate" "{format_date date=$CREATE_DATE}"}
|
||||
{assign "lastOrderAmount" "{format_number number=$TOTAL_TAXED_AMOUNT}"}
|
||||
{loop type="currency" name="order-currency" id=$CURRENCY}
|
||||
{assign "lastOrderCurrency" $SYMBOL}
|
||||
{/loop}
|
||||
{/loop}
|
||||
|
||||
<tr>
|
||||
<td><a href="{url path="/admin/customer/update/{$ID}"}">{$REF}</a></td>
|
||||
|
||||
<td>
|
||||
{$COMPANY}
|
||||
</td>
|
||||
|
||||
<td class="object-title">
|
||||
{$FIRSTNAME} {$LASTNAME}
|
||||
</td>
|
||||
|
||||
{module_include location='customer_list_row'}
|
||||
|
||||
<td>
|
||||
{$lastOrderDate}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{$lastOrderCurrency} {$lastOrderAmount}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
||||
{loop type="auth" name="can_change" role="ADMIN" resource="admin.customer" access="UPDATE"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Edit this customer'}" href="{url path="/admin/customer/update/{$ID}" }"><i class="glyphicon glyphicon-edit"></i></a>
|
||||
{/loop}
|
||||
{loop type="auth" name="can_send_mail" role="ADMIN" resource="admin.customer" access="VIEW"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l="Send a mail to this customer"}" href="mailto:{$EMAIL}"><span class="glyphicon glyphicon-envelope"></span></a>
|
||||
{/loop}
|
||||
{loop type="auth" name="can_delete" role="ADMIN" resource="admin.customer" access="DELETE"}
|
||||
<a class="btn btn-default btn-xs customer-delete" title="{intl l='Delete this customer and all his orders'}" href="#delete_customer_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
{/loop}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
{/loop}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{* end customer search *}
|
||||
|
||||
{* order search *}
|
||||
<div class="general-block-decorator">
|
||||
<div class="table-responsive">
|
||||
@@ -64,16 +152,11 @@
|
||||
<td>{$TOTAL_TAXED_AMOUNT}</td>
|
||||
<td><span class="label label-{#$orderStatusLabel#}">{$orderStatus}</span></td>
|
||||
|
||||
{module_include location='orders_table_row'}
|
||||
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
||||
{loop type="auth" name="can_change" role="ADMIN" resource="admin.order" access="UPDATE"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Edit this order'}" href="{url path="/admin/order/update/$ID"}"><span class="glyphicon glyphicon-edit"></span></a>
|
||||
{if $STATUS !== 5}
|
||||
<a class="btn btn-default btn-xs order-cancel" title="{intl l='Cancel this order'}" href="#cancel_order_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-remove-sign"></span></a>
|
||||
{/if}
|
||||
{/loop}
|
||||
</div>
|
||||
</td>
|
||||
@@ -85,6 +168,58 @@
|
||||
</div>
|
||||
{* end order search *}
|
||||
|
||||
{* product search *}
|
||||
<div class="general-block-decorator">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<caption class="clearfix">
|
||||
{intl l='Product'}
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l="ID"}</th>
|
||||
<th></th>
|
||||
<th>{intl l="Reference"}</th>
|
||||
<th>{intl l="Product title"}</th>
|
||||
|
||||
<th class="actions">{intl l="Actions"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{loop type="product" name="product-search" visible="*" search_mode="sentence" search_term=$smarty.get.search_term search_in="ref,title"}
|
||||
|
||||
<tr>
|
||||
<td>{$ID}</td>
|
||||
|
||||
<td>
|
||||
{loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
|
||||
<a href="{url path='/admin/products/update' product_id=$ID}" title="{intl l='Edit this product'}">
|
||||
<img src="{$IMAGE_URL}" alt="{$TITLE}" />
|
||||
</a>
|
||||
{/loop}
|
||||
|
||||
<td class="object-title"><a href="{url path='/admin/products/update' product_id=$ID}" title="{intl l='Edit this product'}">{$REF}</a></td>
|
||||
|
||||
<td class="object-title"><a href="{url path='/admin/products/update' product_id=$ID}" title="{intl l='Edit this product'}">{$TITLE}</a></td>
|
||||
|
||||
|
||||
<td class="actions">
|
||||
<div class="btn-group">
|
||||
{loop type="auth" name="can_change" role="ADMIN" resource="admin.product" access="UPDATE"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path='/admin/products/update' product_id=$ID}"><i class="glyphicon glyphicon-edit"></i></a>
|
||||
{/loop}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{/loop}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{* end product search *}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user