Conditions | 8 |
Paths | 16 |
Total Lines | 105 |
Code Lines | 22 |
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 |
||
107 | public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
||
108 | { |
||
109 | $context = $this->context(); |
||
110 | $config = $context->config(); |
||
111 | |||
112 | /** client/html/catalog/home/domains |
||
113 | * A list of domain names whose items should be available in the catalog home view template |
||
114 | * |
||
115 | * The templates rendering home lists usually add the images, prices |
||
116 | * and texts associated to each home item. If you want to display additional |
||
117 | * content like the home attributes, you can configure your own list of |
||
118 | * domains (attribute, media, price, home, text, etc. are domains) |
||
119 | * whose items are fetched from the storage. Please keep in mind that |
||
120 | * the more domains you add to the configuration, the more time is required |
||
121 | * for fetching the content! |
||
122 | * |
||
123 | * This configuration option overwrites the "client/html/catalog/domains" |
||
124 | * option that allows to configure the domain names of the items fetched |
||
125 | * for all catalog related data. |
||
126 | * |
||
127 | * @param array List of domain names |
||
128 | * @since 2020.10 |
||
129 | * @category Developer |
||
130 | * @see client/html/catalog/domains |
||
131 | * @see client/html/catalog/detail/domains |
||
132 | * @see client/html/catalog/stage/domains |
||
133 | * @see client/html/catalog/lists/domains |
||
134 | */ |
||
135 | $domains = ['media', 'media/property', 'price', 'text', 'product' => ['promotion']]; |
||
136 | $domains = $config->get( 'client/html/catalog/domains', $domains ); |
||
137 | $domains = $config->get( 'client/html/catalog/home/domains', $domains ); |
||
138 | |||
139 | /** client/html/catalog/home/basket-add |
||
140 | * Display the "add to basket" button for each product item in the catalog home component |
||
141 | * |
||
142 | * Enables the button for adding products to the basket for the listed products. |
||
143 | * This works for all type of products, even for selection products with product |
||
144 | * variants and product bundles. By default, also optional attributes are |
||
145 | * displayed if they have been associated to a product. |
||
146 | * |
||
147 | * @param boolean True to display the button, false to hide it |
||
148 | * @since 2020.10 |
||
149 | * @category Developer |
||
150 | * @category User |
||
151 | * @see client/html/catalog/lists/basket-add |
||
152 | * @see client/html/catalog/detail/basket-add |
||
153 | * @see client/html/basket/related/basket-add |
||
154 | * @see client/html/catalog/product/basket-add |
||
155 | */ |
||
156 | if( $config->get( 'client/html/catalog/home/basket-add', false ) ) { |
||
157 | $domains = array_merge_recursive( $domains, ['attribute' => ['variant', 'custom', 'config']] ); |
||
158 | } |
||
159 | |||
160 | $tree = \Aimeos\Controller\Frontend::create( $context, 'catalog' )->uses( $domains ) |
||
161 | ->getTree( \Aimeos\Controller\Frontend\Catalog\Iface::LIST ); |
||
162 | |||
163 | |||
164 | $articles = map(); |
||
165 | $products = $tree->getRefItems( 'product', null, 'promotion' ); |
||
166 | |||
167 | foreach( $tree->getChildren() as $child ) { |
||
168 | $products->union( $child->getRefItems( 'product', null, 'promotion' ) ); |
||
169 | } |
||
170 | |||
171 | if( $config->get( 'client/html/catalog/home/basket-add', false ) ) |
||
172 | { |
||
173 | foreach( $products as $product ) |
||
174 | { |
||
175 | if( $product->getType() === 'select' ) { |
||
176 | $articles->union( $product->getRefItems( 'product', 'default', 'default' ) ); |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | |||
181 | /** client/html/catalog/home/stock/enable |
||
182 | * Enables or disables displaying product stock levels in product list views |
||
183 | * |
||
184 | * This configuration option allows shop owners to display product |
||
185 | * stock levels for each product in list views or to disable |
||
186 | * fetching product stock information. |
||
187 | * |
||
188 | * The stock information is fetched via AJAX and inserted via Javascript. |
||
189 | * This allows to cache product items by leaving out such highly |
||
190 | * dynamic content like stock levels which changes with each order. |
||
191 | * |
||
192 | * @param boolean Value of "1" to display stock levels, "0" to disable displaying them |
||
193 | * @since 2020.10 |
||
194 | * @category User |
||
195 | * @category Developer |
||
196 | * @see client/html/catalog/detail/stock/enable |
||
197 | * @see client/html/catalog/stock/url/target |
||
198 | * @see client/html/catalog/stock/url/controller |
||
199 | * @see client/html/catalog/stock/url/action |
||
200 | * @see client/html/catalog/stock/url/config |
||
201 | */ |
||
202 | if( !$products->isEmpty() && (bool) $config->get( 'client/html/catalog/home/stock/enable', true ) === true ) { |
||
203 | $view->homeStockUrl = $this->getStockUrl( $view, $products->union( $articles ) ); |
||
204 | } |
||
205 | |||
206 | // Delete cache when products are added or deleted even when in "tag-all" mode |
||
207 | $this->addMetaItems( $tree, $expire, $tags, ['catalog', 'product'] ); |
||
208 | |||
209 | $view->homeTree = $tree; |
||
210 | |||
211 | return parent::data( $view, $tags, $expire ); |
||
212 | } |
||
258 |