Passed
Push — master ( 43437d...11506f )
by Aimeos
02:47
created

Standard::conditions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Catalog\Suggest;
12
13
14
/**
15
 * Default implementation of catalog suggest section HTML clients.
16
 *
17
 * @package Client
18
 * @subpackage Html
19
 */
20
class Standard
21
	extends \Aimeos\Client\Html\Common\Client\Factory\Base
22
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
23
{
24
	/** client/html/catalog/suggest/name
25
	 * Class name of the used catalog suggest client implementation
26
	 *
27
	 * Each default HTML client can be replace by an alternative imlementation.
28
	 * To use this implementation, you have to set the last part of the class
29
	 * name as configuration value so the client factory knows which class it
30
	 * has to instantiate.
31
	 *
32
	 * For example, if the name of the default class is
33
	 *
34
	 *  \Aimeos\Client\Html\Catalog\Suggest\Standard
35
	 *
36
	 * and you want to replace it with your own version named
37
	 *
38
	 *  \Aimeos\Client\Html\Catalog\Suggest\Mysuggest
39
	 *
40
	 * then you have to set the this configuration option:
41
	 *
42
	 *  client/html/catalog/suggest/name = Mysuggest
43
	 *
44
	 * The value is the last part of your own class name and it's case sensitive,
45
	 * so take care that the configuration value is exactly named like the last
46
	 * part of the class name.
47
	 *
48
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
49
	 * characters are possible! You should always start the last part of the class
50
	 * name with an upper case character and continue only with lower case characters
51
	 * or numbers. Avoid chamel case names like "MySuggest"!
52
	 *
53
	 * @param string Last part of the class name
54
	 * @since 2015.02
55
	 */
56
57
58
	/**
59
	 * Sets the necessary parameter values in the view.
60
	 *
61
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
62
	 * @param array &$tags Result array for the list of tags that are associated to the output
63
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
64
	 * @return \Aimeos\Base\View\Iface Modified view object
65
	 */
66
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
67
	{
68
		$context = $this->context();
69
		$config = $context->config();
70
71
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )
72
			->text( $view->param( 'f_search' ) ); // sort by relevance first
73
74
75
		/** client/html/catalog/suggest/domains
76
		 * List of domain items that should be fetched along with the products
77
		 *
78
		 * The suggsted entries for the full text search in the catalog filter component
79
		 * usually consist of the names of the matched products. By default, only the
80
		 * product item including the localized name is available. You can add more domains
81
		 * like e.g. "media" to get the images of the product as well.
82
		 *
83
		 * **Note:** The more domains you will add, the slower the autocomplete requests
84
		 * will be! Keep it to an absolute minium for user friendly response times.
85
		 *
86
		 * @param array List of domain names
87
		 * @since 2016.08
88
		 * @see client/html/catalog/suggest/template-body
89
		 * @see client/html/catalog/suggest/restrict
90
		 * @see client/html/catalog/suggest/size
91
		 */
92
		$domains = $config->get( 'client/html/catalog/suggest/domains', ['text'] );
93
94
		/** client/html/catalog/suggest/size
95
		 * The number of products shown in the list of suggestions
96
		 *
97
		 * Limits the number of products that are shown in the list of suggested
98
		 * products.
99
		 *
100
		 * @param integer Number of products
101
		 * @since 2018.10
102
		 * @see client/html/catalog/suggest/domains
103
		 * @see client/html/catalog/suggest/restrict
104
		 */
105
		$size = $config->get( 'client/html/catalog/suggest/size', 24 );
106
107
		/** client/html/catalog/suggest/restrict
108
		 * Restricts suggestions to category and attribute facets
109
		 *
110
		 * Limits the shown suggestions to the current category and selected
111
		 * attribute facets. If disabled, suggestions are limited by the
112
		 * entered text only.
113
		 *
114
		 * @param boolean True to use category and facets, false for all results
115
		 * @since 2019.07
116
		 * @see client/html/catalog/suggest/domains
117
		 * @see client/html/catalog/suggest/size
118
		 */
119
		if( $config->get( 'client/html/catalog/suggest/restrict', true ) == true )
120
		{
121
			$level = $config->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
122
			$catids = $view->param( 'f_catid', $config->get( 'client/html/catalog/lists/catid-default' ) );
123
124
			$cntl->category( $catids, 'default', $level )
125
				->allOf( $view->param( 'f_attrid', [] ) )
126
				->oneOf( $view->param( 'f_optid', [] ) )
127
				->oneOf( $view->param( 'f_oneid', [] ) );
128
129
			$this->call( 'conditions', $cntl, $view );
130
		}
131
132
		$view->suggestItems = $cntl->uses( $domains )->slice( 0, $size )->search();
133
134
		return parent::data( $view, $tags, $expire );
135
	}
136
137
138
	/**
139
	 * Adds additional conditions for filtering
140
	 *
141
	 * @param \Aimeos\Controller\Frontend\Product\Iface $cntl Product controller
142
	 * @param \Aimeos\Base\View\Iface $view View object
143
	 */
144
	protected function conditions( \Aimeos\Controller\Frontend\Product\Iface $cntl, \Aimeos\Base\View\Iface $view )
145
	{
146
		if( $view->config( 'client/html/catalog/instock', false ) ) {
147
			$cntl->compare( '>', 'product.instock', 0 );
148
		}
149
	}
150
151
152
	/** client/html/catalog/suggest/template-body
153
	 * Relative path to the HTML body template of the catalog suggest client.
154
	 *
155
	 * The template file contains the HTML code and processing instructions
156
	 * to generate the result shown in the body of the frontend. The
157
	 * configuration string is the path to the template file relative
158
	 * to the templates directory (usually in client/html/templates).
159
	 *
160
	 * You can overwrite the template file configuration in extensions and
161
	 * provide alternative templates. These alternative templates should be
162
	 * named like the default one but suffixed by
163
	 * an unique name. You may use the name of your project for this. If
164
	 * you've implemented an alternative client class as well, it
165
	 * should be suffixed by the name of the new class.
166
	 *
167
	 * @param string Relative path to the template creating code for the HTML page body
168
	 * @since 2015.02
169
	 * @see client/html/catalog/suggest/template-header
170
	 * @see client/html/catalog/suggest/domains
171
	 */
172
173
	/** client/html/catalog/suggest/template-header
174
	 * Relative path to the HTML header template of the catalog suggest client.
175
	 *
176
	 * The template file contains the HTML code and processing instructions
177
	 * to generate the HTML code that is inserted into the HTML page header
178
	 * of the rendered page in the frontend. The configuration string is the
179
	 * path to the template file relative to the templates directory (usually
180
	 * in client/html/templates).
181
	 *
182
	 * You can overwrite the template file configuration in extensions and
183
	 * provide alternative templates. These alternative templates should be
184
	 * named like the default one but suffixed by
185
	 * an unique name. You may use the name of your project for this. If
186
	 * you've implemented an alternative client class as well, it
187
	 * should be suffixed by the name of the new class.
188
	 *
189
	 * @param string Relative path to the template creating code for the HTML page head
190
	 * @since 2015.02
191
	 * @see client/html/catalog/suggest/template-body
192
	 * @see client/html/catalog/suggest/domains
193
	 */
194
}
195