| Conditions | 7 |
| Paths | 8 |
| Total Lines | 103 |
| Code Lines | 28 |
| 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 |
||
| 124 | public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
||
| 125 | { |
||
| 126 | $context = $this->context(); |
||
| 127 | $config = $context->config(); |
||
| 128 | $productItems = map(); |
||
| 129 | |||
| 130 | /** client/html/catalog/product/domains |
||
| 131 | * A list of domain names whose items should be available in the catalog product view template |
||
| 132 | * |
||
| 133 | * The templates rendering product lists usually add the images, prices |
||
| 134 | * and texts associated to each product item. If you want to display additional |
||
| 135 | * content like the product attributes, you can configure your own list of |
||
| 136 | * domains (attribute, media, price, product, text, etc. are domains) |
||
| 137 | * whose items are fetched from the storage. Please keep in mind that |
||
| 138 | * the more domains you add to the configuration, the more time is required |
||
| 139 | * for fetching the content! |
||
| 140 | * |
||
| 141 | * This configuration option overwrites the "client/html/catalog/domains" |
||
| 142 | * option that allows to configure the domain names of the items fetched |
||
| 143 | * for all catalog related data. |
||
| 144 | * |
||
| 145 | * @param array List of domain names |
||
| 146 | * @since 2019.06 |
||
| 147 | * @category Developer |
||
| 148 | * @see client/html/catalog/domains |
||
| 149 | * @see client/html/catalog/detail/domains |
||
| 150 | * @see client/html/catalog/stage/domains |
||
| 151 | * @see client/html/catalog/lists/domains |
||
| 152 | */ |
||
| 153 | $domains = ['media', 'media/property', 'price', 'text']; |
||
| 154 | $domains = $config->get( 'client/html/catalog/domains', $domains ); |
||
| 155 | $domains = $config->get( 'client/html/catalog/product/domains', $domains ); |
||
| 156 | |||
| 157 | if( $config->get( 'client/html/catalog/product/basket-add', false ) ) { |
||
| 158 | $domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] ); |
||
| 159 | } |
||
| 160 | |||
| 161 | /** client/html/catalog/product/product-codes |
||
| 162 | * List of codes of products to load for the current list. |
||
| 163 | * Should be set dynamically through some integration plugin, |
||
| 164 | * to allow a list of products with configurable products. |
||
| 165 | * |
||
| 166 | * @param string List of codes of products to load for the current list |
||
| 167 | * @since 2019.06 |
||
| 168 | * @category Developer |
||
| 169 | */ |
||
| 170 | $productCodes = $config->get( 'client/html/catalog/product/product-codes', [] ); |
||
| 171 | |||
| 172 | $products = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
||
| 173 | ->compare( '==', 'product.code', $productCodes ) |
||
| 174 | ->slice( 0, count( $productCodes ) ) |
||
| 175 | ->uses( $domains ) |
||
| 176 | ->search(); |
||
| 177 | |||
| 178 | // Sort products by the order given in the configuration "client/html/catalog/product/product-codes". |
||
| 179 | $productCodesOrder = array_flip( $productCodes ); |
||
| 180 | $products->usort( function( $a, $b ) use ( $productCodesOrder ) { |
||
| 181 | return $productCodesOrder[$a->getCode()] - $productCodesOrder[$b->getCode()]; |
||
| 182 | } ); |
||
| 183 | |||
| 184 | if( $config->get( 'client/html/catalog/product/basket-add', false ) ) |
||
| 185 | { |
||
| 186 | foreach( $products as $product ) |
||
| 187 | { |
||
| 188 | if( $product->getType() === 'select' ) { |
||
| 189 | $productItems->union( $product->getRefItems( 'product', 'default', 'default' ) ); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | /** client/html/catalog/product/stock/enable |
||
| 195 | * Enables or disables displaying product stock levels in product list views |
||
| 196 | * |
||
| 197 | * This configuration option allows shop owners to display product |
||
| 198 | * stock levels for each product in list views or to disable |
||
| 199 | * fetching product stock information. |
||
| 200 | * |
||
| 201 | * The stock information is fetched via AJAX and inserted via Javascript. |
||
| 202 | * This allows to cache product items by leaving out such highly |
||
| 203 | * dynamic content like stock levels which changes with each order. |
||
| 204 | * |
||
| 205 | * @param boolean Value of "1" to display stock levels, "0" to disable displaying them |
||
| 206 | * @since 2019.06 |
||
| 207 | * @category User |
||
| 208 | * @category Developer |
||
| 209 | * @see client/html/catalog/detail/stock/enable |
||
| 210 | * @see client/html/catalog/stock/url/target |
||
| 211 | * @see client/html/catalog/stock/url/controller |
||
| 212 | * @see client/html/catalog/stock/url/action |
||
| 213 | * @see client/html/catalog/stock/url/config |
||
| 214 | */ |
||
| 215 | if( !$products->isEmpty() && (bool) $config->get( 'client/html/catalog/product/stock/enable', true ) === true ) { |
||
| 216 | $view->itemsStockUrl = $this->getStockUrl( $view, $products->union( $productItems ) ); |
||
| 217 | } |
||
| 218 | |||
| 219 | // Delete cache when products are added or deleted even when in "tag-all" mode |
||
| 220 | $this->addMetaItems( $products->union( $productItems ), $expire, $tags, ['product'] ); |
||
| 221 | |||
| 222 | $view->productItems = $products; |
||
| 223 | $view->productTotal = count( $products ); |
||
| 224 | $view->productProductItems = $productItems; |
||
| 225 | |||
| 226 | return parent::data( $view, $tags, $expire ); |
||
| 227 | } |
||
| 273 |