Conditions | 12 |
Paths | 768 |
Total Lines | 266 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
Bugs | 0 | Features | 1 |
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 addData( \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', '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 | */ |
||
536 | $domains = $config->get( 'client/html/catalog/lists/domains', $domains ); |
||
537 | |||
538 | if( $view->config( 'client/html/catalog/lists/basket-add', false ) ) { |
||
539 | $domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute'] ); |
||
540 | } |
||
541 | |||
542 | /** client/html/catalog/lists/pages |
||
543 | * Maximum number of product pages shown in pagination |
||
544 | * |
||
545 | * Limits the number of product pages that are shown in the navigation. |
||
546 | * The user is able to move to the next page (or previous one if it's not |
||
547 | * the first) to display the next (or previous) products. |
||
548 | * |
||
549 | * The value must be a positive integer number. Negative values are not |
||
550 | * allowed. The value can't be overwritten per request. |
||
551 | * |
||
552 | * @param integer Number of pages |
||
553 | * @since 2019.04 |
||
554 | * @category User |
||
555 | * @category Developer |
||
556 | * @see client/html/catalog/lists/catid-default |
||
557 | * @see client/html/catalog/lists/supid-default |
||
558 | * @see client/html/catalog/lists/domains |
||
559 | * @see client/html/catalog/lists/levels |
||
560 | * @see client/html/catalog/lists/sort |
||
561 | * @see client/html/catalog/lists/size |
||
562 | */ |
||
563 | $pages = $config->get( 'client/html/catalog/lists/pages', 100 ); |
||
564 | |||
565 | /** client/html/catalog/lists/size |
||
566 | * The number of products shown in a list page |
||
567 | * |
||
568 | * Limits the number of products that are shown in the list pages to the |
||
569 | * given value. If more products are available, the products are split |
||
570 | * into bunches which will be shown on their own list page. The user is |
||
571 | * able to move to the next page (or previous one if it's not the first) |
||
572 | * to display the next (or previous) products. |
||
573 | * |
||
574 | * The value must be an integer number from 1 to 100. Negative values as |
||
575 | * well as values above 100 are not allowed. The value can be overwritten |
||
576 | * per request if the "l_size" parameter is part of the URL. |
||
577 | * |
||
578 | * @param integer Number of products |
||
579 | * @since 2014.03 |
||
580 | * @category User |
||
581 | * @category Developer |
||
582 | * @see client/html/catalog/lists/catid-default |
||
583 | * @see client/html/catalog/lists/supid-default |
||
584 | * @see client/html/catalog/lists/domains |
||
585 | * @see client/html/catalog/lists/levels |
||
586 | * @see client/html/catalog/lists/sort |
||
587 | * @see client/html/catalog/lists/pages |
||
588 | */ |
||
589 | $size = $config->get( 'client/html/catalog/lists/size', 48 ); |
||
590 | |||
591 | /** client/html/catalog/lists/levels |
||
592 | * Include products of sub-categories in the product list of the current category |
||
593 | * |
||
594 | * Sometimes it may be useful to show products of sub-categories in the |
||
595 | * current category product list, e.g. if the current category contains |
||
596 | * no products at all or if there are only a few products in all categories. |
||
597 | * |
||
598 | * Possible constant values for this setting are: |
||
599 | * |
||
600 | * * 1 : Only products from the current category |
||
601 | * * 2 : Products from the current category and the direct child categories |
||
602 | * * 3 : Products from the current category and the whole category sub-tree |
||
603 | * |
||
604 | * Caution: Please keep in mind that displaying products of sub-categories |
||
605 | * can slow down your shop, especially if it contains more than a few |
||
606 | * products! You have no real control over the positions of the products |
||
607 | * in the result list too because all products from different categories |
||
608 | * with the same position value are placed randomly. |
||
609 | * |
||
610 | * Usually, a better way is to associate products to all categories they |
||
611 | * should be listed in. This can be done manually if there are only a few |
||
612 | * ones or during the product import automatically. |
||
613 | * |
||
614 | * @param integer Tree level constant |
||
615 | * @since 2015.11 |
||
616 | * @category Developer |
||
617 | * @see client/html/catalog/lists/catid-default |
||
618 | * @see client/html/catalog/lists/supid-default |
||
619 | * @see client/html/catalog/lists/domains |
||
620 | * @see client/html/catalog/lists/size |
||
621 | * @see client/html/catalog/lists/sort |
||
622 | * @see client/html/catalog/lists/pages |
||
623 | */ |
||
624 | $level = $config->get( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||
625 | |||
626 | |||
627 | /** client/html/catalog/lists/catid-default |
||
628 | * The default category ID used if none is given as parameter |
||
629 | * |
||
630 | * If users view a product list page without a category ID in the |
||
631 | * parameter list, the first found products are displayed with a |
||
632 | * random order. You can circumvent this by configuring a default |
||
633 | * category ID that should be used in this case (the ID of the root |
||
634 | * category is best for this). In most cases you can set this value |
||
635 | * via the administration interface of the shop application. |
||
636 | * |
||
637 | * @param array|string Category ID or IDs |
||
638 | * @since 2014.03 |
||
639 | * @category User |
||
640 | * @category Developer |
||
641 | * @see client/html/catalog/lists/sort |
||
642 | * @see client/html/catalog/lists/size |
||
643 | * @see client/html/catalog/lists/domains |
||
644 | * @see client/html/catalog/lists/levels |
||
645 | * @see client/html/catalog/detail/prodid-default |
||
646 | * @see client/html/catalog/lists/supid-default |
||
647 | */ |
||
648 | $catids = $view->param( 'f_catid', $config->get( 'client/html/catalog/lists/catid-default' ) ); |
||
649 | $catids = $catids != null && is_scalar( $catids ) ? explode( ',', $catids ) : $catids; // workaround for TYPO3 |
||
650 | |||
651 | |||
652 | /** client/html/catalog/lists/supid-default |
||
653 | * The default supplier ID used if none is given as parameter |
||
654 | * |
||
655 | * Products in the list page can be limited to one or more suppliers. |
||
656 | * By default, the products are not limited to any supplier until one or |
||
657 | * more supplier IDs are passed in the URL using the f_supid parameter. |
||
658 | * You can also configure the default supplier IDs for limiting the |
||
659 | * products if no IDs are passed in the URL using this configuration. |
||
660 | * |
||
661 | * @param array|string Supplier ID or IDs |
||
662 | * @since 2021.01 |
||
663 | * @category User |
||
664 | * @category Developer |
||
665 | * @see client/html/catalog/lists/sort |
||
666 | * @see client/html/catalog/lists/size |
||
667 | * @see client/html/catalog/lists/domains |
||
668 | * @see client/html/catalog/lists/levels |
||
669 | * @see client/html/catalog/lists/catid-default |
||
670 | * @see client/html/catalog/detail/prodid-default |
||
671 | */ |
||
672 | $supids = $view->param( 'f_supid', $config->get( 'client/html/catalog/lists/supid-default' ) ); |
||
673 | $supids = $supids != null && is_scalar( $supids ) ? explode( ',', $supids ) : $supids; // workaround for TYPO3 |
||
674 | |||
675 | /** client/html/catalog/lists/sort |
||
676 | * Default sorting of product list if no other sorting is given by parameter |
||
677 | * |
||
678 | * Configures the standard sorting of products in list views. This sorting is used |
||
679 | * as long as it's not overwritten by an URL parameter. Except "relevance", all |
||
680 | * other sort codes can be prefixed by a "-" (minus) sign to sort the products in |
||
681 | * a descending order. By default, the sorting is ascending. |
||
682 | * |
||
683 | * @param string Sort code "relevance", "name", "-name", "price", "-price", "ctime" or "-ctime" |
||
684 | * @since 2018.07 |
||
685 | * @category User |
||
686 | * @category Developer |
||
687 | * @see client/html/catalog/lists/catid-default |
||
688 | * @see client/html/catalog/lists/supid-default |
||
689 | * @see client/html/catalog/lists/domains |
||
690 | * @see client/html/catalog/lists/levels |
||
691 | * @see client/html/catalog/lists/size |
||
692 | */ |
||
693 | $sort = $view->param( 'f_sort', $config->get( 'client/html/catalog/lists/sort', 'relevance' ) ); |
||
694 | $size = min( max( $view->param( 'l_size', $size ), 1 ), 100 ); |
||
695 | $page = min( max( $view->param( 'l_page', 1 ), 1 ), $pages ); |
||
696 | |||
697 | $products = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
||
698 | ->sort( $sort ) // prioritize user sorting over the sorting through relevance and category |
||
699 | ->text( $view->param( 'f_search' ) ) |
||
700 | ->price( $view->param( 'f_price' ) ) |
||
701 | ->category( $catids, 'default', $level ) |
||
702 | ->supplier( $supids ) |
||
703 | ->allOf( $view->param( 'f_attrid', [] ) ) |
||
704 | ->oneOf( $view->param( 'f_optid', [] ) ) |
||
705 | ->oneOf( $view->param( 'f_oneid', [] ) ) |
||
706 | ->slice( ( $page - 1 ) * $size, $size ) |
||
707 | ->uses( $domains ) |
||
708 | ->search( $total ); |
||
709 | |||
710 | if( $catids != null ) |
||
711 | { |
||
712 | $controller = \Aimeos\Controller\Frontend::create( $context, 'catalog' )->uses( $domains ); |
||
713 | $listCatPath = $controller->getPath( is_array( $catids ) ? reset( $catids ) : $catids ); |
||
714 | |||
715 | if( ( $categoryItem = $listCatPath->last() ) !== null ) { |
||
716 | $view->listCurrentCatItem = $categoryItem; |
||
717 | } |
||
718 | |||
719 | $view->listCatPath = $listCatPath; |
||
720 | $this->addMetaItems( $listCatPath, $expire, $tags ); |
||
721 | } |
||
722 | |||
723 | |||
724 | // Delete cache when products are added or deleted even when in "tag-all" mode |
||
725 | $this->addMetaItems( $products, $expire, $tags, ['product'] ); |
||
726 | |||
727 | |||
728 | $view->listProductItems = $products; |
||
729 | $view->listProductSort = $sort; |
||
730 | $view->listProductTotal = $total; |
||
731 | |||
732 | $view->listPageSize = $size; |
||
733 | $view->listPageCurr = $page; |
||
734 | $view->listPagePrev = ( $page > 1 ? $page - 1 : 1 ); |
||
735 | $view->listPageLast = ( $total != 0 ? ceil( $total / $size ) : 1 ); |
||
|
|||
736 | $view->listPageNext = ( $page < $view->listPageLast ? $page + 1 : $view->listPageLast ); |
||
737 | |||
738 | $view->listParams = $this->getClientParams( map( $view->param() )->toArray() ); |
||
739 | |||
740 | return parent::addData( $view, $tags, $expire ); |
||
741 | } |
||
743 |