| Conditions | 10 |
| Paths | 192 |
| Total Lines | 235 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 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 |
||
| 461 | public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
||
| 462 | { |
||
| 463 | $total = 0; |
||
| 464 | $context = $this->getContext(); |
||
| 465 | $config = $context->getConfig(); |
||
| 466 | |||
| 467 | |||
| 468 | /** client/html/catalog/domains |
||
| 469 | * A list of domain names whose items should be available in the catalog view templates |
||
| 470 | * |
||
| 471 | * The templates rendering catalog related data usually add the images and |
||
| 472 | * texts associated to each item. If you want to display additional |
||
| 473 | * content like the attributes, you can configure your own list of |
||
| 474 | * domains (attribute, media, price, product, text, etc. are domains) |
||
| 475 | * whose items are fetched from the storage. Please keep in mind that |
||
| 476 | * the more domains you add to the configuration, the more time is required |
||
| 477 | * for fetching the content! |
||
| 478 | * |
||
| 479 | * This configuration option can be overwritten by the "client/html/catalog/lists/domains" |
||
| 480 | * configuration option that allows to configure the domain names of the |
||
| 481 | * items fetched specifically for all types of product listings. |
||
| 482 | * |
||
| 483 | * @param array List of domain names |
||
| 484 | * @since 2014.03 |
||
| 485 | * @category Developer |
||
| 486 | * @see client/html/catalog/lists/domains |
||
| 487 | * @see client/html/catalog/lists/catid-default |
||
| 488 | * @see client/html/catalog/lists/size |
||
| 489 | * @see client/html/catalog/lists/levels |
||
| 490 | * @see client/html/catalog/lists/sort |
||
| 491 | * @see client/html/catalog/lists/pages |
||
| 492 | */ |
||
| 493 | $domains = $config->get( 'client/html/catalog/domains', ['media', 'price', 'text'] ); |
||
| 494 | |||
| 495 | if( $view->config( 'client/html/catalog/lists/basket-add', false ) ) { |
||
| 496 | $domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute'] ); |
||
| 497 | } |
||
| 498 | |||
| 499 | /** client/html/catalog/lists/domains |
||
| 500 | * A list of domain names whose items should be available in the product list view template |
||
| 501 | * |
||
| 502 | * The templates rendering product lists usually add the images, prices |
||
| 503 | * and texts associated to each product item. If you want to display additional |
||
| 504 | * content like the product attributes, you can configure your own list of |
||
| 505 | * domains (attribute, media, price, product, text, etc. are domains) |
||
| 506 | * whose items are fetched from the storage. Please keep in mind that |
||
| 507 | * the more domains you add to the configuration, the more time is required |
||
| 508 | * for fetching the content! |
||
| 509 | * |
||
| 510 | * This configuration option overwrites the "client/html/catalog/domains" |
||
| 511 | * option that allows to configure the domain names of the items fetched |
||
| 512 | * for all catalog related data. |
||
| 513 | * |
||
| 514 | * @param array List of domain names |
||
| 515 | * @since 2014.03 |
||
| 516 | * @category Developer |
||
| 517 | * @see client/html/catalog/domains |
||
| 518 | * @see client/html/catalog/detail/domains |
||
| 519 | * @see client/html/catalog/stage/domains |
||
| 520 | * @see client/html/catalog/lists/catid-default |
||
| 521 | * @see client/html/catalog/lists/size |
||
| 522 | * @see client/html/catalog/lists/levels |
||
| 523 | * @see client/html/catalog/lists/sort |
||
| 524 | * @see client/html/catalog/lists/pages |
||
| 525 | */ |
||
| 526 | $domains = $config->get( 'client/html/catalog/lists/domains', $domains ); |
||
| 527 | |||
| 528 | /** client/html/catalog/lists/pages |
||
| 529 | * Maximum number of product pages shown in pagination |
||
| 530 | * |
||
| 531 | * Limits the number of product pages that are shown in the navigation. |
||
| 532 | * The user is able to move to the next page (or previous one if it's not |
||
| 533 | * the first) to display the next (or previous) products. |
||
| 534 | * |
||
| 535 | * The value must be a positive integer number. Negative values are not |
||
| 536 | * allowed. The value can't be overwritten per request. |
||
| 537 | * |
||
| 538 | * @param integer Number of pages |
||
| 539 | * @since 2019.04 |
||
| 540 | * @category User |
||
| 541 | * @category Developer |
||
| 542 | * @see client/html/catalog/lists/catid-default |
||
| 543 | * @see client/html/catalog/lists/domains |
||
| 544 | * @see client/html/catalog/lists/levels |
||
| 545 | * @see client/html/catalog/lists/sort |
||
| 546 | * @see client/html/catalog/lists/size |
||
| 547 | */ |
||
| 548 | $pages = $config->get( 'client/html/catalog/lists/pages', 100 ); |
||
| 549 | |||
| 550 | /** client/html/catalog/lists/size |
||
| 551 | * The number of products shown in a list page |
||
| 552 | * |
||
| 553 | * Limits the number of products that are shown in the list pages to the |
||
| 554 | * given value. If more products are available, the products are split |
||
| 555 | * into bunches which will be shown on their own list page. The user is |
||
| 556 | * able to move to the next page (or previous one if it's not the first) |
||
| 557 | * to display the next (or previous) products. |
||
| 558 | * |
||
| 559 | * The value must be an integer number from 1 to 100. Negative values as |
||
| 560 | * well as values above 100 are not allowed. The value can be overwritten |
||
| 561 | * per request if the "l_size" parameter is part of the URL. |
||
| 562 | * |
||
| 563 | * @param integer Number of products |
||
| 564 | * @since 2014.03 |
||
| 565 | * @category User |
||
| 566 | * @category Developer |
||
| 567 | * @see client/html/catalog/lists/catid-default |
||
| 568 | * @see client/html/catalog/lists/domains |
||
| 569 | * @see client/html/catalog/lists/levels |
||
| 570 | * @see client/html/catalog/lists/sort |
||
| 571 | * @see client/html/catalog/lists/pages |
||
| 572 | */ |
||
| 573 | $size = $config->get( 'client/html/catalog/lists/size', 48 ); |
||
| 574 | |||
| 575 | /** client/html/catalog/lists/levels |
||
| 576 | * Include products of sub-categories in the product list of the current category |
||
| 577 | * |
||
| 578 | * Sometimes it may be useful to show products of sub-categories in the |
||
| 579 | * current category product list, e.g. if the current category contains |
||
| 580 | * no products at all or if there are only a few products in all categories. |
||
| 581 | * |
||
| 582 | * Possible constant values for this setting are: |
||
| 583 | * * 1 : Only products from the current category |
||
| 584 | * * 2 : Products from the current category and the direct child categories |
||
| 585 | * * 3 : Products from the current category and the whole category sub-tree |
||
| 586 | * |
||
| 587 | * Caution: Please keep in mind that displaying products of sub-categories |
||
| 588 | * can slow down your shop, especially if it contains more than a few |
||
| 589 | * products! You have no real control over the positions of the products |
||
| 590 | * in the result list too because all products from different categories |
||
| 591 | * with the same position value are placed randomly. |
||
| 592 | * |
||
| 593 | * Usually, a better way is to associate products to all categories they |
||
| 594 | * should be listed in. This can be done manually if there are only a few |
||
| 595 | * ones or during the product import automatically. |
||
| 596 | * |
||
| 597 | * @param integer Tree level constant |
||
| 598 | * @since 2015.11 |
||
| 599 | * @category Developer |
||
| 600 | * @see client/html/catalog/lists/catid-default |
||
| 601 | * @see client/html/catalog/lists/domains |
||
| 602 | * @see client/html/catalog/lists/size |
||
| 603 | * @see client/html/catalog/lists/sort |
||
| 604 | * @see client/html/catalog/lists/pages |
||
| 605 | */ |
||
| 606 | $level = $config->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||
| 607 | |||
| 608 | |||
| 609 | /** client/html/catalog/lists/catid-default |
||
| 610 | * The default category ID used if none is given as parameter |
||
| 611 | * |
||
| 612 | * If users view a product list page without a category ID in the |
||
| 613 | * parameter list, the first found products are displayed with a |
||
| 614 | * random order. You can circumvent this by configuring a default |
||
| 615 | * category ID that should be used in this case (the ID of the root |
||
| 616 | * category is best for this). In most cases you can set this value |
||
| 617 | * via the administration interface of the shop application. |
||
| 618 | * |
||
| 619 | * @param string Category ID |
||
| 620 | * @since 2014.03 |
||
| 621 | * @category User |
||
| 622 | * @category Developer |
||
| 623 | * @see client/html/catalog/lists/sort |
||
| 624 | * @see client/html/catalog/lists/size |
||
| 625 | * @see client/html/catalog/lists/domains |
||
| 626 | * @see client/html/catalog/lists/levels |
||
| 627 | * @see client/html/catalog/detail/prodid-default |
||
| 628 | */ |
||
| 629 | $catids = $view->param( 'f_catid', $config->get( 'client/html/catalog/lists/catid-default' ) ); |
||
| 630 | $catids = $catids != null && is_scalar( $catids ) ? explode( ',', $catids ) : $catids; // workaround for TYPO3 |
||
| 631 | |||
| 632 | /** client/html/catalog/lists/sort |
||
| 633 | * Default sorting of product list if no other sorting is given by parameter |
||
| 634 | * |
||
| 635 | * Configures the standard sorting of products in list views. This sorting is used |
||
| 636 | * as long as it's not overwritten by an URL parameter. Except "relevance", all |
||
| 637 | * other sort codes can be prefixed by a "-" (minus) sign to sort the products in |
||
| 638 | * a descending order. By default, the sorting is ascending. |
||
| 639 | * |
||
| 640 | * @param string Sort code "relevance", "name", "-name", "price", "-price", "ctime" or "-ctime" |
||
| 641 | * @since 2018.07 |
||
| 642 | * @category User |
||
| 643 | * @category Developer |
||
| 644 | * @see client/html/catalog/lists/catid-default |
||
| 645 | * @see client/html/catalog/lists/domains |
||
| 646 | * @see client/html/catalog/lists/levels |
||
| 647 | * @see client/html/catalog/lists/size |
||
| 648 | */ |
||
| 649 | $sort = $view->param( 'f_sort', $config->get( 'client/html/catalog/lists/sort', 'relevance' ) ); |
||
| 650 | $size = min( max( $view->param( 'l_size', $size ), 1 ), 100 ); |
||
| 651 | $page = min( max( $view->param( 'l_page', 1 ), 1 ), $pages ); |
||
| 652 | |||
| 653 | $products = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
||
| 654 | ->sort( $sort ) // prioritize user sorting over the sorting through category |
||
| 655 | ->category( $catids, 'default', $level ) |
||
| 656 | ->supplier( $view->param( 'f_supid', [] ) ) |
||
| 657 | ->allOf( $view->param( 'f_attrid', [] ) ) |
||
| 658 | ->oneOf( $view->param( 'f_optid', [] ) ) |
||
| 659 | ->oneOf( $view->param( 'f_oneid', [] ) ) |
||
| 660 | ->text( $view->param( 'f_search' ) ) |
||
| 661 | ->slice( ( $page - 1 ) * $size, $size ) |
||
| 662 | ->uses( $domains ) |
||
| 663 | ->search( $total ); |
||
| 664 | |||
| 665 | if( $catids != null ) |
||
| 666 | { |
||
| 667 | $controller = \Aimeos\Controller\Frontend::create( $context, 'catalog' )->uses( $domains ); |
||
| 668 | $listCatPath = $controller->getPath( is_array( $catids ) ? reset( $catids ) : $catids ); |
||
| 669 | |||
| 670 | if( ( $categoryItem = $listCatPath->last() ) !== null ) { |
||
| 671 | $view->listCurrentCatItem = $categoryItem; |
||
| 672 | } |
||
| 673 | |||
| 674 | $view->listCatPath = $listCatPath; |
||
| 675 | $this->addMetaItems( $listCatPath, $expire, $tags ); |
||
| 676 | } |
||
| 677 | |||
| 678 | |||
| 679 | // Delete cache when products are added or deleted even when in "tag-all" mode |
||
| 680 | $this->addMetaItems( $products, $expire, $tags, ['product'] ); |
||
| 681 | |||
| 682 | |||
| 683 | $view->listProductItems = $products; |
||
| 684 | $view->listProductSort = $sort; |
||
| 685 | $view->listProductTotal = $total; |
||
| 686 | |||
| 687 | $view->listPageSize = $size; |
||
| 688 | $view->listPageCurr = $page; |
||
| 689 | $view->listPagePrev = ( $page > 1 ? $page - 1 : 1 ); |
||
| 690 | $view->listPageLast = ( $total != 0 ? ceil( $total / $size ) : 1 ); |
||
|
|
|||
| 691 | $view->listPageNext = ( $page < $view->listPageLast ? $page + 1 : $view->listPageLast ); |
||
| 692 | |||
| 693 | $view->listParams = $this->getClientParams( map( $view->param() )->toArray() ); |
||
| 694 | |||
| 695 | return parent::addData( $view, $tags, $expire ); |
||
| 696 | } |
||
| 698 |