Conditions | 7 |
Paths | 16 |
Total Lines | 143 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
158 | public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
||
159 | { |
||
160 | $context = $this->context(); |
||
161 | $config = $context->config(); |
||
162 | $session = $context->session(); |
||
|
|||
163 | $domains = [ |
||
164 | 'attribute', 'media', 'media/property', 'price', 'product', |
||
165 | 'product/property', 'supplier', 'supplier/address', 'text' |
||
166 | ]; |
||
167 | |||
168 | /** client/html/catalog/domains |
||
169 | * A list of domain names whose items should be available in the catalog view templates |
||
170 | * |
||
171 | * @see client/html/catalog/detail/domains |
||
172 | */ |
||
173 | $domains = $config->get( 'client/html/catalog/domains', $domains ); |
||
174 | |||
175 | /** client/html/catalog/detail/domains |
||
176 | * A list of domain names whose items should be available in the product detail view template |
||
177 | * |
||
178 | * The templates rendering product details usually add the images, |
||
179 | * prices, texts, attributes, products, etc. associated to the product |
||
180 | * item. If you want to display additional or less content, you can |
||
181 | * configure your own list of domains (attribute, media, price, product, |
||
182 | * text, etc. are domains) whose items are fetched from the storage. |
||
183 | * Please keep in mind that the more domains you add to the configuration, |
||
184 | * the more time is required for fetching the content! |
||
185 | * |
||
186 | * Since version 2014.05 this configuration option overwrites the |
||
187 | * "client/html/catalog/domains" option that allows to configure the |
||
188 | * domain names of the items fetched for all catalog related data. |
||
189 | * |
||
190 | * @param array List of domain names |
||
191 | * @since 2014.03 |
||
192 | * @category Developer |
||
193 | * @see client/html/catalog/domains |
||
194 | * @see client/html/catalog/lists/domains |
||
195 | */ |
||
196 | $domains = $config->get( 'client/html/catalog/detail/domains', $domains ); |
||
197 | |||
198 | /** client/html/catalog/detail/prodid-default |
||
199 | * The default product ID used if none is given as parameter |
||
200 | * |
||
201 | * To display a product detail view or a part of it for a specific |
||
202 | * product, you can configure its ID using this setting. This is |
||
203 | * most useful in a CMS where the product ID can be configured |
||
204 | * separately for each content node. |
||
205 | * |
||
206 | * @param string Product ID |
||
207 | * @since 2016.01 |
||
208 | * @category User |
||
209 | * @category Developer |
||
210 | * @see client/html/catalog/detail/prodid-default |
||
211 | * @see client/html/catalog/lists/catid-default |
||
212 | */ |
||
213 | $id = $view->param( 'd_prodid', $config->get( 'client/html/catalog/detail/prodid-default' ) ); |
||
214 | |||
215 | /** client/html/catalog/detail/prodcode-default |
||
216 | * The default product code used if none is given as parameter |
||
217 | * |
||
218 | * To display a product detail view or a part of it for a specific |
||
219 | * product, you can configure its code using this setting. This is |
||
220 | * most useful in a CMS where the product code can be configured |
||
221 | * separately for each content node. |
||
222 | * |
||
223 | * @param string Product code |
||
224 | * @since 2019.10 |
||
225 | * @category User |
||
226 | * @category Developer |
||
227 | * @see client/html/catalog/detail/prodid-default |
||
228 | * @see client/html/catalog/lists/catid-default |
||
229 | */ |
||
230 | $code = $config->get( 'client/html/catalog/detail/prodcode-default' ); |
||
231 | |||
232 | $cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains ); |
||
233 | $productItem = ( $id ? $cntl->get( $id ) : ( $code ? $cntl->find( $code ) : $cntl->resolve( $view->param( 'd_name' ) ) ) ); |
||
234 | |||
235 | $propItems = $productItem->getPropertyItems(); |
||
236 | $supItems = $productItem->getRefItems( 'supplier', null, 'default' ); |
||
237 | $attrItems = $productItem->getRefItems( 'attribute', null, 'default' ); |
||
238 | $mediaItems = $productItem->getRefItems( 'media', 'default', 'default' ); |
||
239 | |||
240 | $this->addMetaItems( $productItem, $expire, $tags ); |
||
241 | $this->addMetaItems( $supItems, $expire, $tags ); |
||
242 | |||
243 | if( in_array( $productItem->getType(), ['bundle', 'select'] ) ) |
||
244 | { |
||
245 | \Aimeos\Map::method( 'attrparent', function( $subProdId ) { |
||
246 | foreach( $this->list as $item ) { |
||
247 | $item->parent = array_merge( $item->parent ?? [], [$subProdId] ); |
||
248 | } |
||
249 | return $this; |
||
250 | } ); |
||
251 | |||
252 | foreach( $productItem->getRefItems( 'product', null, 'default' ) as $subProdId => $subProduct ) |
||
253 | { |
||
254 | $propItems->merge( $subProduct->getPropertyItems()->assign( ['parent' => $subProdId] ) ); |
||
255 | $mediaItems->merge( $subProduct->getRefItems( 'media', 'default', 'default' ) ); |
||
256 | $attrItems->replace( |
||
257 | $subProduct->getRefItems( 'attribute', null, ['default', 'variant'] )->attrparent( $subProdId ) |
||
258 | ); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | |||
263 | /** client/html/catalog/detail/stock/enable |
||
264 | * Enables or disables displaying product stock levels in product detail view |
||
265 | * |
||
266 | * This configuration option allows shop owners to display product |
||
267 | * stock levels for each product in the detail views or to disable |
||
268 | * fetching product stock information. |
||
269 | * |
||
270 | * The stock information is fetched via AJAX and inserted via Javascript. |
||
271 | * This allows to cache product items by leaving out such highly |
||
272 | * dynamic content like stock levels which changes with each order. |
||
273 | * |
||
274 | * @param boolean Value of "1" to display stock levels, "0" to disable displaying them |
||
275 | * @since 2014.03 |
||
276 | * @category User |
||
277 | * @category Developer |
||
278 | * @see client/html/catalog/lists/stock/enable |
||
279 | * @see client/html/catalog/stock/url/target |
||
280 | * @see client/html/catalog/stock/url/controller |
||
281 | * @see client/html/catalog/stock/url/action |
||
282 | * @see client/html/catalog/stock/url/config |
||
283 | */ |
||
284 | |||
285 | if( (bool) $view->config( 'client/html/catalog/detail/stock/enable', true ) === true ) |
||
286 | { |
||
287 | $products = $productItem->getRefItems( 'product', null, 'default' )->push( $productItem ); |
||
288 | $view->detailStockUrl = $this->getStockUrl( $view, $products ); |
||
289 | } |
||
290 | |||
291 | |||
292 | $view->detailMediaItems = $mediaItems; |
||
293 | $view->detailProductItem = $productItem; |
||
294 | $view->detailAttributeMap = $attrItems->groupBy( 'attribute.type' ); |
||
295 | $view->detailPropertyMap = $propItems->groupBy( 'product.property.type' ); |
||
296 | $view->serviceItems = $this->call( 'services' ); |
||
297 | |||
298 | $this->call( 'seen', $productItem ); |
||
299 | |||
300 | return parent::data( $view, $tags, $expire ); |
||
301 | } |
||
454 |