@@ -1800,6 +1800,280 @@ public function testProductBasicFullTextSearchQuery()
1800
1800
}
1801
1801
}
1802
1802
1803
+ /**
1804
+ * Partial search filtered for price and sorted by price and name
1805
+ *
1806
+ * @magentoApiDataFixture Magento/Catalog/_files/category.php
1807
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
1808
+ */
1809
+ public function testProductPartialNameFullTextSearchQuery ()
1810
+ {
1811
+ $ this ->reIndexAndCleanCache ();
1812
+ $ textToSearch = 'Sim ' ;
1813
+ $ query
1814
+ =<<<QUERY
1815
+ {
1816
+ products(
1817
+ search: " {$ textToSearch }"
1818
+ filter:{
1819
+ price:{to:"25"}
1820
+ }
1821
+ sort:{
1822
+ price:DESC
1823
+ name:ASC
1824
+ }
1825
+ )
1826
+ {
1827
+ total_count
1828
+ items {
1829
+ name
1830
+ sku
1831
+ price {
1832
+ minimalPrice {
1833
+ amount {
1834
+ value
1835
+ currency
1836
+ }
1837
+ }
1838
+ }
1839
+ }
1840
+ page_info {
1841
+ page_size
1842
+ current_page
1843
+ }
1844
+ filters{
1845
+ filter_items {
1846
+ items_count
1847
+ label
1848
+ value_string
1849
+ }
1850
+ }
1851
+ aggregations{
1852
+ attribute_code
1853
+ count
1854
+ label
1855
+ options{
1856
+ count
1857
+ label
1858
+ value
1859
+ }
1860
+ }
1861
+ }
1862
+ }
1863
+ QUERY ;
1864
+ /** @var ProductRepositoryInterface $productRepository */
1865
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
1866
+
1867
+ $ prod1 = $ productRepository ->get ('simple1 ' );
1868
+ $ prod2 = $ productRepository ->get ('simple2 ' );
1869
+ $ prod3 = $ productRepository ->get ('simple3 ' );
1870
+ $ response = $ this ->graphQlQuery ($ query );
1871
+ $ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
1872
+
1873
+ $ filteredProducts = [$ prod1 , $ prod2 ];
1874
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
1875
+ foreach ($ productItemsInResponse as $ itemIndex => $ itemArray ) {
1876
+ $ this ->assertNotEmpty ($ itemArray );
1877
+ $ this ->assertResponseFields (
1878
+ $ productItemsInResponse [$ itemIndex ][0 ],
1879
+ [
1880
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku (),
1881
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
1882
+ 'price ' => [
1883
+ 'minimalPrice ' => [
1884
+ 'amount ' => [
1885
+ 'value ' => $ filteredProducts [$ itemIndex ]->getSpecialPrice (),
1886
+ 'currency ' => 'USD '
1887
+ ]
1888
+ ]
1889
+ ]
1890
+ ]
1891
+ );
1892
+ }
1893
+ }
1894
+
1895
+ /**
1896
+ * Partial search on sku filtered for price and sorted by price and sku
1897
+ *
1898
+ * @magentoApiDataFixture Magento/Catalog/_files/category.php
1899
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_products_with_different_sku_and_name.php
1900
+ */
1901
+ public function testProductPartialSkuFullTextSearchQuery ()
1902
+ {
1903
+ $ this ->reIndexAndCleanCache ();
1904
+ $ textToSearch = 'prd ' ;
1905
+ $ query
1906
+ =<<<QUERY
1907
+ {
1908
+ products(
1909
+ search: " {$ textToSearch }"
1910
+ filter:{
1911
+ price:{to:"25"}
1912
+ }
1913
+ sort:{
1914
+ price:DESC
1915
+ name:ASC
1916
+ }
1917
+ )
1918
+ {
1919
+ total_count
1920
+ items {
1921
+ name
1922
+ sku
1923
+ price {
1924
+ minimalPrice {
1925
+ amount {
1926
+ value
1927
+ currency
1928
+ }
1929
+ }
1930
+ }
1931
+ }
1932
+ page_info {
1933
+ page_size
1934
+ current_page
1935
+ }
1936
+ filters{
1937
+ filter_items {
1938
+ items_count
1939
+ label
1940
+ value_string
1941
+ }
1942
+ }
1943
+ aggregations{
1944
+ attribute_code
1945
+ count
1946
+ label
1947
+ options{
1948
+ count
1949
+ label
1950
+ value
1951
+ }
1952
+ }
1953
+ }
1954
+ }
1955
+ QUERY ;
1956
+ /** @var ProductRepositoryInterface $productRepository */
1957
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
1958
+
1959
+ $ prod1 = $ productRepository ->get ('prd1sku ' );
1960
+ $ prod2 = $ productRepository ->get ('prd2-sku2 ' );
1961
+ $ response = $ this ->graphQlQuery ($ query );
1962
+ $ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
1963
+
1964
+ $ filteredProducts = [$ prod1 , $ prod2 ];
1965
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
1966
+ foreach ($ productItemsInResponse as $ itemIndex => $ itemArray ) {
1967
+ $ this ->assertNotEmpty ($ itemArray );
1968
+ $ this ->assertResponseFields (
1969
+ $ productItemsInResponse [$ itemIndex ][0 ],
1970
+ [
1971
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku (),
1972
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
1973
+ 'price ' => [
1974
+ 'minimalPrice ' => [
1975
+ 'amount ' => [
1976
+ 'value ' => $ filteredProducts [$ itemIndex ]->getSpecialPrice (),
1977
+ 'currency ' => 'USD '
1978
+ ]
1979
+ ]
1980
+ ]
1981
+ ]
1982
+ );
1983
+ }
1984
+ }
1985
+
1986
+ /**
1987
+ * Partial search on hyphenated sku filtered for price and sorted by price and sku
1988
+ *
1989
+ * @magentoApiDataFixture Magento/Catalog/_files/category.php
1990
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_products_with_different_sku_and_name.php
1991
+ */
1992
+ public function testProductPartialSkuHyphenatedFullTextSearchQuery ()
1993
+ {
1994
+ $ this ->reIndexAndCleanCache ();
1995
+ /** @var ProductRepositoryInterface $productRepository */
1996
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
1997
+
1998
+ $ prod2 = $ productRepository ->get ('prd2-sku2 ' );
1999
+ $ textToSearch = 'sku2 ' ;
2000
+ $ query
2001
+ =<<<QUERY
2002
+ {
2003
+ products(
2004
+ search: " {$ textToSearch }"
2005
+ filter:{
2006
+ price:{to:"25"}
2007
+ }
2008
+ sort:{
2009
+ price:DESC
2010
+ name:ASC
2011
+ }
2012
+ )
2013
+ {
2014
+ total_count
2015
+ items {
2016
+ name
2017
+ sku
2018
+ price {
2019
+ minimalPrice {
2020
+ amount {
2021
+ value
2022
+ currency
2023
+ }
2024
+ }
2025
+ }
2026
+ }
2027
+ page_info {
2028
+ page_size
2029
+ current_page
2030
+ }
2031
+ filters{
2032
+ filter_items {
2033
+ items_count
2034
+ label
2035
+ value_string
2036
+ }
2037
+ }
2038
+ aggregations{
2039
+ attribute_code
2040
+ count
2041
+ label
2042
+ options{
2043
+ count
2044
+ label
2045
+ value
2046
+ }
2047
+ }
2048
+ }
2049
+ }
2050
+ QUERY ;
2051
+
2052
+ $ response = $ this ->graphQlQuery ($ query );
2053
+ $ this ->assertEquals (1 , $ response ['products ' ]['total_count ' ]);
2054
+
2055
+ $ filteredProducts = [$ prod2 ];
2056
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
2057
+ foreach ($ productItemsInResponse as $ itemIndex => $ itemArray ) {
2058
+ $ this ->assertNotEmpty ($ itemArray );
2059
+ $ this ->assertResponseFields (
2060
+ $ productItemsInResponse [$ itemIndex ][0 ],
2061
+ [
2062
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku (),
2063
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
2064
+ 'price ' => [
2065
+ 'minimalPrice ' => [
2066
+ 'amount ' => [
2067
+ 'value ' => $ filteredProducts [$ itemIndex ]->getSpecialPrice (),
2068
+ 'currency ' => 'USD '
2069
+ ]
2070
+ ]
2071
+ ]
2072
+ ]
2073
+ );
2074
+ }
2075
+ }
2076
+
1803
2077
/**
1804
2078
* Filter products purely in a given price range
1805
2079
*
0 commit comments