Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
7d450a17
Commit
7d450a17
authored
Mar 07, 2023
by
dhn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sku排序
parent
8d3f4bcb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
43 deletions
+102
-43
app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php
+34
-0
app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
+39
-43
lib/internal/Magento/Framework/Search/Search.php
+29
-0
No files found.
app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php
View file @
7d450a17
...
...
@@ -450,6 +450,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
protected
function
_renderFiltersBefore
()
{
if
(
isset
(
$_REQUEST
[
'skus'
])
&&
!
empty
(
$_REQUEST
[
'skus'
]))
{
$this
->
_renderFiltersSku
();
return
;
}
if
(
$this
->
isLoaded
())
{
return
;
}
...
...
@@ -477,6 +482,35 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
$this
->
getSearchResultApplier
(
$this
->
searchResult
)
->
apply
();
parent
::
_renderFiltersBefore
();
}
protected
function
_renderFiltersSku
()
{
if
(
$this
->
isLoaded
())
{
return
;
}
if
(
$this
->
searchRequestName
!==
'quick_search_container'
||
strlen
(
trim
(
$this
->
queryText
))
)
{
$this
->
prepareSearchTermFilter
();
$this
->
preparePriceAggregation
();
$searchCriteria
=
$this
->
getSearchCriteriaResolver
()
->
resolve
();
try
{
$this
->
searchResult
=
$this
->
getSearch
()
->
searchSku
(
$searchCriteria
);
$this
->
_totalRecords
=
$this
->
getTotalRecordsResolver
(
$this
->
searchResult
)
->
resolve
();
}
catch
(
EmptyRequestDataException
$e
)
{
$this
->
searchResult
=
$this
->
createEmptyResult
();
}
catch
(
NonExistingRequestNameException
$e
)
{
$this
->
_logger
->
error
(
$e
->
getMessage
());
throw
new
LocalizedException
(
__
(
'An error occurred. For details, see the error log.'
));
}
}
else
{
$this
->
searchResult
=
$this
->
createEmptyResult
();
}
$this
->
getSearchResultApplier
(
$this
->
searchResult
)
->
applySku
();
parent
::
_renderFiltersBefore
();
}
/**
* Create empty search result
...
...
app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
View file @
7d450a17
...
...
@@ -63,6 +63,7 @@ class SearchResultApplier implements SearchResultApplierInterface
return
;
}
$items
=
$this
->
sliceItems
(
$this
->
searchResult
->
getItems
(),
$this
->
size
,
$this
->
currentPage
);
$ids
=
[];
foreach
(
$items
as
$item
)
{
...
...
@@ -73,60 +74,55 @@ class SearchResultApplier implements SearchResultApplierInterface
->
reset
(
\Magento\Framework\DB\Select
::
ORDER
);
$sortOrder
=
$this
->
searchResult
->
getSearchCriteria
()
->
getSortOrders
();
if
(
!
empty
(
$sortOrder
[
'price'
])
&&
$this
->
collection
->
getLimitationFilters
()
->
isUsingPriceIndex
())
{
$sortDirection
=
$sortOrder
[
'price'
];
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"price_index.min_price = 0, price_index.min_price
{
$sortDirection
}
"
)
);
}
else
{
$orderList
=
join
(
','
,
$ids
);
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"FIELD(e.entity_id,
$orderList
)"
));
}
}
public
function
applySku
()
{
if
(
empty
(
$this
->
searchResult
->
getItems
()))
{
$this
->
collection
->
getSelect
()
->
where
(
'NULL'
);
return
;
}
$items
=
$this
->
searchResult
->
getItems
();
$ids
=
[];
foreach
(
$items
as
$item
)
{
$ids
[]
=
(
int
)
$item
->
getId
();
}
$this
->
collection
->
getSelect
()
->
where
(
'e.entity_id IN (?)'
,
$ids
)
->
reset
(
\Magento\Framework\DB\Select
::
ORDER
);
$sortOrder
=
$this
->
searchResult
->
getSearchCriteria
()
->
getSortOrders
();
$skus
=
[];
if
(
isset
(
$_GET
[
'skus'
])
&&
!
empty
(
$_GET
[
'skus'
]))
$skus
=
explode
(
','
,
$_REQUEST
[
'skus'
]);
foreach
(
$skus
as
$sku
)
{
if
(
!
isset
(
$_GET
[
'p'
])
||
$_GET
[
'p'
]
==
1
)
{
$skus
=
explode
(
','
,
$_GET
[
'skus'
]);
$this
->
collection
->
getSelect
()
->
orWhere
(
"e.sku in ('"
.
implode
(
"','"
,
$skus
)
.
"')"
);
}
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
'e.sku = "'
.
$sku
.
'" desc'
));
}
if
(
!
empty
(
$sortOrder
[
'price'
])
&&
$this
->
collection
->
getLimitationFilters
()
->
isUsingPriceIndex
())
{
$sortDirection
=
$sortOrder
[
'price'
];
if
(
empty
(
$skus
))
{
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"price_index.min_price = 0, price_index.min_price
{
$sortDirection
}
"
)
);
}
else
{
foreach
(
$skus
as
$sku
)
{
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
'e.sku = "'
.
$sku
.
'" desc'
));
}
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"price_index.min_price = 0, price_index.min_price
{
$sortDirection
}
"
)
);
}
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"price_index.min_price = 0, price_index.min_price
{
$sortDirection
}
"
)
);
}
else
{
$orderList
=
join
(
','
,
$ids
);
if
(
empty
(
$skus
))
{
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"FIELD(e.entity_id,
$orderList
)"
));
}
else
{
foreach
(
$skus
as
$sku
)
{
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
'e.sku = "'
.
$sku
.
'" desc'
));
}
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"FIELD(e.entity_id,
$orderList
)"
));
}
$this
->
collection
->
getSelect
()
->
order
(
new
\Zend_Db_Expr
(
"FIELD(e.entity_id,
$orderList
)"
));
}
$this
->
collection
->
getSelect
()
->
limit
(
$this
->
size
);
}
/**
* Slice current items
*
...
...
lib/internal/Magento/Framework/Search/Search.php
View file @
7d450a17
...
...
@@ -83,7 +83,36 @@ class Search implements SearchInterface
}
$request
=
$this
->
requestBuilder
->
create
();
$searchResponse
=
$this
->
searchEngine
->
search
(
$request
);
return
$this
->
searchResponseBuilder
->
build
(
$searchResponse
)
->
setSearchCriteria
(
$searchCriteria
);
}
public
function
searchSku
(
SearchCriteriaInterface
$searchCriteria
)
{
$this
->
requestBuilder
->
setRequestName
(
$searchCriteria
->
getRequestName
());
$scope
=
$this
->
scopeResolver
->
getScope
()
->
getId
();
$this
->
requestBuilder
->
bindDimension
(
'scope'
,
$scope
);
foreach
(
$searchCriteria
->
getFilterGroups
()
as
$filterGroup
)
{
foreach
(
$filterGroup
->
getFilters
()
as
$filter
)
{
$this
->
addFieldToFilter
(
$filter
->
getField
(),
$filter
->
getValue
());
}
}
// $this->requestBuilder->setFrom($searchCriteria->getCurrentPage() * $searchCriteria->getPageSize());
// $this->requestBuilder->setSize($searchCriteria->getPageSize());
/**
* This added in Backward compatibility purposes.
* Temporary solution for an existing API of a fulltext search request builder.
* It must be moved to different API.
* Scope to split Search request builder API in MC-16461.
*/
if
(
method_exists
(
$this
->
requestBuilder
,
'setSort'
))
{
$this
->
requestBuilder
->
setSort
(
$searchCriteria
->
getSortOrders
());
}
$request
=
$this
->
requestBuilder
->
create
();
$searchResponse
=
$this
->
searchEngine
->
search
(
$request
);
return
$this
->
searchResponseBuilder
->
build
(
$searchResponse
)
->
setSearchCriteria
(
$searchCriteria
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment