diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 7ec77efbd..1ed7292cf 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -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'; } } diff --git a/core/lib/Thelia/Core/Template/Element/SearchLoopInterface.php b/core/lib/Thelia/Core/Template/Element/SearchLoopInterface.php index e180105a6..48876012f 100644 --- a/core/lib/Thelia/Core/Template/Element/SearchLoopInterface.php +++ b/core/lib/Thelia/Core/Template/Element/SearchLoopInterface.php @@ -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 diff --git a/core/lib/Thelia/Core/Template/Loop/Customer.php b/core/lib/Thelia/Core/Template/Loop/Customer.php index e811606c0..e49d9ef76 100755 --- a/core/lib/Thelia/Core/Template/Loop/Customer.php +++ b/core/lib/Thelia/Core/Template/Loop/Customer.php @@ -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 */ -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 * diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 01a5ed15f..4d32b7101 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -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 */ -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 * diff --git a/templates/admin/default/search.html b/templates/admin/default/search.html index 026e52400..a39eda982 100644 --- a/templates/admin/default/search.html +++ b/templates/admin/default/search.html @@ -22,6 +22,94 @@
+ {* customer search *} +
+
+ + + + + + + + + + + + + + + + + + + + {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} + + + + + + + + + {module_include location='customer_list_row'} + + + + + + + + {/loop} + +
+ {intl l='Customer'} +
+ {intl l="customer ref"} + + {intl l="company"} + + {intl l="firstname & lastname"} + + {intl l="last order"} + {intl l='order amount'}{intl l="Actions"}
{$REF} + {$COMPANY} + + {$FIRSTNAME} {$LASTNAME} + + {$lastOrderDate} + + {$lastOrderCurrency} {$lastOrderAmount} + +
+ + {loop type="auth" name="can_change" role="ADMIN" resource="admin.customer" access="UPDATE"} + + {/loop} + {loop type="auth" name="can_send_mail" role="ADMIN" resource="admin.customer" access="VIEW"} + + {/loop} + {loop type="auth" name="can_delete" role="ADMIN" resource="admin.customer" access="DELETE"} + + {/loop} +
+
+
+
+ {* end customer search *} + {* order search *}
@@ -64,16 +152,11 @@ {$TOTAL_TAXED_AMOUNT} {$orderStatus} - {module_include location='orders_table_row'} -
{loop type="auth" name="can_change" role="ADMIN" resource="admin.order" access="UPDATE"} - {if $STATUS !== 5} - - {/if} {/loop}
@@ -85,6 +168,58 @@
{* end order search *} + {* product search *} +
+
+ + + + + + + + + + + + + + + {loop type="product" name="product-search" visible="*" search_mode="sentence" search_term=$smarty.get.search_term search_in="ref,title"} + + + + + + + + + + + + + {/loop} + +
+ {intl l='Product'} +
{intl l="ID"}{intl l="Reference"}{intl l="Product title"}{intl l="Actions"}
{$ID} + {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} + + {$TITLE} + + {/loop} + + {$REF}{$TITLE} +
+ {loop type="auth" name="can_change" role="ADMIN" resource="admin.product" access="UPDATE"} + + {/loop} +
+
+
+
+ {* end product search *} +