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