Returns the product counts per node

@param \Aimeos\MShop\Catalog\Item\Iface $node Tree node, maybe with children
@return array Associative list of catalog IDs as keys and product counts as values
484042
protected function counts( \Aimeos\MShop\Catalog\Item\Iface $node )
	{
		$list = [$node->getId() => $node->count];

		foreach( $node->getChildren() as $child ) {
			$list += $this->counts( $child );
		}

		return $list;
	}
1118110
public function countVisitsByProduct()
    {
        $em = $this->getEntityManager();
        $query = $em->createQuery(
            'SELECT SUM(s.visits) as visit,  '
                . ' p.id, p.name , p.slug, o.latitude, o.longitude, '
                . ' c.id categoryId, c.name categoryName,  '
                . ' b.id brandId, b.name brandName, b.slug brandSlug,  '
                . ' i.path imagePath, '
                . ' p.price,  p.priceType, p.initPrice, p.discount, p.discountType, p.stock, p.active, p.available, p.highlighted, p.freeTransport,  '
                . ' o.id actorId, o.name actorName '
                . ' FROM EcommerceBundle:ProductStats as s '
                . ' LEFT JOIN s.product as p'
                . ' LEFT JOIN p.actor as o'
                . ' LEFT JOIN p.category as c'
                . ' LEFT JOIN p.brand as b '
                . ' LEFT JOIN p.images as i '
                . ' GROUP BY s.product ORDER BY visit DESC'
        );

        $visitas = $query->getResult();

        return $visitas;
    }
380935
protected function getCatalogItems( \DOMNode $node )
	{
		foreach( $node->childNodes as $node )
		{
			if( $node->nodeName === 'catalogitem'
				&& ( $refAttr = $node->attributes->getNamedItem( 'ref' ) ) !== null
			) {
				$codes[] = $refAttr->nodeValue;
			}
		}

		$items = [];

		if( !empty( $codes ) )
		{
			$manager = \Aimeos\MShop::create( $this->getContext(), 'catalog' );

			$search = $manager->createSearch()->setSlice( 0, count( $codes ) );
			$search->setConditions( $search->compare( '==', 'catalog.code', $codes ) );

			foreach( $manager->searchItems( $search ) as $item ) {
				$items[$item->getCode()] = $item;
			}
		}

		return $items;
	}
454800
public function getChildren(Node $node, $includeHiddenFromNav = true)
    {
        $this->init();
        $children = array();

        if (array_key_exists($node->getId(), $this->childNodes)) {
            $nodes = $this->childNodes[$node->getId()];
            /* @var Node $childNode */
            foreach ($nodes as $childNode) {
                $nodeTranslation = $childNode->getNodeTranslation(
                    $this->locale,
                    $this->includeOffline
                );
                if (!is_null($nodeTranslation)) {
                    $children[] = new NodeMenuItem(
                        $childNode,
                        $nodeTranslation,
                        false,
                        $this
                    );
                }
            }

            $children = array_filter(
                $children,
                function (NodeMenuItem $entry) use ($includeHiddenFromNav) {
                    if ($entry->getNode()->isHiddenFromNav(
                        ) && !$includeHiddenFromNav
                    ) {
                        return false;
                    }

                    return true;
                }
            );
        }

        return $children;
    }
445945
protected function getCatalogIdsFromTree( \Aimeos\MShop\Catalog\Item\Iface $item )
	{
		if( $item->getStatus() < 1 ) {
			return [];
		}

		$list = [ $item->getId() ];

		foreach( $item->getChildren() as $child ) {
			$list = array_merge( $list, $this->getCatalogIdsFromTree( $child ) );
		}

		return $list;
	}
1206901
protected function toArray( \Aimeos\MShop\Locale\Item\Site\Iface $item, $copy = false )
	{
		$data = $item->toArray( true );
		$data['config'] = [];

		if( $copy === true )
		{
			$data['locale.site.code'] = $data['locale.site.code'] . '_copy';
			$data['locale.site.id'] = '';
		}

		foreach( $item->getConfig() as $key => $value )
		{
			$data['config']['key'][] = $key;
			$data['config']['val'][] = $value;
		}

		return $data;
	}
68558
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();
		$manager = \Aimeos\MShop::create( $context, 'product' );
		$listManager = \Aimeos\MShop::create( $context, 'product/lists' );

		$prodItem = $manager->createItem()->setType( 'default' );
		$listItem = $listManager->createItem()->setType( 'default' );
		$articles = $item->getRefItems( 'product', null, 'default', false );
		$listItems = $item->getListItems( 'product', 'default', null, false );

		foreach( $data as $idx => $entry )
		{
			if( ( $litem = $item->getListItem( 'product', 'default', $entry['product.id'], false ) ) === null ) {
				$litem = clone $listItem;
			}

			if( isset( $articles[$litem->getRefId()] ) ) {
				$refItem = $articles[$litem->getRefId()];
			} else {
				$refItem = clone $prodItem;
			}

			$litem->fromArray( $entry, true );
			$litem->setPosition( $idx );

			$refItem->fromArray( $entry, true );

			if( isset( $entry['attr'] ) ) {
				$refItem = $this->fromArrayAttributes( $refItem, $entry['attr'] );
			}

			$item->addListItem( 'product', $litem, $refItem );
			unset( $listItems[$litem->getId()] );
		}

		return $item->deleteListItems( $listItems );
	}
1088416
protected function getProductItems( \Aimeos\MShop\Context\Item\Iface $context, array $prodIds )
	{
		$productManager = \Aimeos\MShop::create( $context, 'product' );

		$search = $productManager->createSearch( true );
		$expr = array(
			$search->compare( '==', 'product.id', $prodIds ),
			$search->getConditions(),
		);
		$search->setConditions( $search->combine( '&&', $expr ) );
		$search->setSlice( 0, count( $prodIds ) );

		return $productManager->searchItems( $search, array( 'text', 'price', 'media' ) );
	}
878573
protected function fromArray( \Aimeos\MShop\Customer\Item\Iface $item, array $data )
	{
		$context = $this->getContext();
		$listIds = $this->getValue( $data, 'customer.lists.id', [] );

		$listManager = \Aimeos\MShop::create( $context, 'customer/lists' );

		$search = $listManager->createSearch()->setSlice( 0, count( $listIds ) );
		$search->setConditions( $search->compare( '==', 'customer.lists.id', $listIds ) );

		$listItems = $listManager->searchItems( $search );


		foreach( (array) $listIds as $idx => $listid )
		{
			if( isset( $listItems[$listid] ) ) {
				$litem = $listItems[$listid];
			} else {
				$litem = $listManager->createItem();
			}

			$litem->setParentId( $item->getId() );
			$litem->setDomain( 'product' );

			if( isset( $data['customer.lists.refid'][$idx] ) ) {
				$litem->setRefId( $this->getValue( $data, 'customer.lists.refid/' . $idx ) );
			}

			if( isset( $data['customer.lists.status'][$idx] ) ) {
				$litem->setStatus( $this->getValue( $data, 'customer.lists.status/' . $idx ) );
			}

			if( isset( $data['customer.lists.type'][$idx] ) ) {
				$litem->setType( $this->getValue( $data, 'customer.lists.type/' . $idx ) );
			}

			if( isset( $data['customer.lists.position'][$idx] ) ) {
				$litem->setPosition( $this->getValue( $data, 'customer.lists.position/' . $idx ) );
			}

			if( isset( $data['customer.lists.datestart'][$idx] ) ) {
				$litem->setDateStart( $this->getValue( $data, 'customer.lists.datestart/' . $idx ) );
			}

			if( isset( $data['customer.lists.dateend'][$idx] ) ) {
				$litem->setDateEnd( $this->getValue( $data, 'customer.lists.dateend/' . $idx ) );
			}

			if( isset( $data['customer.lists.config'][$idx] )
				&& ( $conf = json_decode( $this->getValue( $data, 'customer.lists.config/' . $idx ), true ) ) !== null
			) {
				$litem->setConfig( $conf );
			}

			if( $litem->getId() === null && isset( $data['config'][$idx]['key'] ) )
			{
				$conf = [];

				foreach( (array) $data['config'][$idx]['key'] as $pos => $key )
				{
					if( trim( $key ) !== '' && isset( $data['config'][$idx]['val'][$pos] ) ) {
						$conf[$key] = $data['config'][$idx]['val'][$pos];
					}
				}

				$litem->setConfig( $conf );
			}

			$listManager->saveItem( $litem, false );
		}
	}
1187790
protected function getProductListPage( \Aimeos\MW\View\Iface $view )
	{
		$page = (int) $view->param( 'fav_page', 1 );
		return ( $page < 1 ? 1 : $page );
	}
194883
protected function toArray( \Aimeos\MShop\Customer\Item\Iface $item, $copy = false )
	{
		$data = $item->toArray( true );

		if( $copy === true )
		{
			$data['customer.siteid'] = $this->getContext()->getLocale()->getSiteId();
			$data['customer.email'] = '';
			$data['customer.id'] = '';
		}

		return $data;
	}
1363022
public function countNodes()
	{
		$nodes = 1;
		if( $this->left || $this->right )
		{
			if( $this->left )
				$nodes += $this->left->countNodes();
			if( $this->right )
				$nodes += $this->right->countNodes();
		}
		return $nodes;
	}
1182097
protected function getProductListSize( \Aimeos\MW\View\Iface $view )
	{
		/** client/html/account/favorite/size
		 * The number of products shown in a list page for favorite products
		 *
		 * Limits the number of products that is shown in the list pages to the
		 * given value. If more products are available, the products are split
		 * into bunches which will be shown on their own list page. The user is
		 * able to move to the next page (or previous one if it's not the first)
		 * to display the next (or previous) products.
		 *
		 * The value must be an integer number from 1 to 100. Negative values as
		 * well as values above 100 are not allowed. The value can be overwritten
		 * per request if the "l_size" parameter is part of the URL.
		 *
		 * @param integer Number of products
		 * @since 2014.09
		 * @category User
		 * @category Developer
		 * @see client/html/catalog/lists/size
		 */
		$defaultSize = $this->getContext()->getConfig()->get( 'client/html/account/favorite/size', 48 );

		$size = (int) $view->param( 'fav-size', $defaultSize );
		return ( $size < 1 || $size > 100 ? $defaultSize : $size );
	}
477215
public function get( \Aimeos\MShop\Context\Item\Iface $context )
	{
		if( $this->locale === null )
		{
			$status = $this->container->getParameter( 'aimeos_shop.disable_sites' );
			$request = $this->requestStack->getMasterRequest();

			$site = $request->attributes->get( 'site', $request->query->get( 'site', 'default' ) );
			$currency = $request->attributes->get( 'currency', $request->query->get( 'currency', '' ) );
			$lang = $request->attributes->get( 'locale', $request->query->get( 'locale', '' ) );

			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
			$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $status );
		}

		return $this->locale;
	}
1109508
private function _countItemsInCategory($table, $catid)
	{
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);

		// Count the items in this category
		$query->select('COUNT(id)')
			->from($table)
			->where('catid = ' . $catid);
		$db->setQuery($query);

		try
		{
			$count = $db->loadResult();
		}
		catch (RuntimeException $e)
		{
			JError::raiseWarning(500, $e->getMessage());

			return false;
		}

		return $count;
	}
733689
public function displayNode( $node )
	{
		return ! isset( $node['label'] ) ||
			(
				! $this->nodeIsHypercube( $node ) &&
				! $this->nodeIsLineItemsAxis( $node ) &&
				! $this->nodeIsAxis( $node ) /* &&
				(
					( isset( $node['children'] ) && count( $node['children'] ) ) ||
					( isset( $node['elements'] ) && count( $node['elements'] ) )
				) */
			);
	}
1037468
public function getIdempotencyKeys(Node $node): array
    {
        $qname = $node::schema()->getQName();
        $keys = [];

        if ($node->has('title')) {
            $keys[$this->getCacheKey($qname, SlugUtils::create($node->get('title')))] = true;
        }

        if ($node->has('slug')) {
            $keys[$this->getCacheKey($qname, $node->get('slug'))] = true;
        }

        if ($node instanceof User && $node->has('email')) {
            $keys[$this->getCacheKey($qname, $node->get('email'))] = true;
        }

        return array_keys($keys);
    }