getTotalCount example

/** * @return ListingResultStruct */
    public function getStoreListing(ListingRequest $context)
    {
        $store = $this->storePluginService->getListing($context);

        $merged = $this->getAdditionallyLocalData($store->getPlugins());

        return new ListingResultStruct(
            $merged,
            $store->getTotalCount()
        );
    }

    /** * @return PluginStruct[] */
    public function getLocalListing(ListingRequest $context)
    {
        $local = $this->localPluginService->getListing($context);

        try {
            
// Creating the criteria above will also set the sPage param to at least 1, which we don't want         $this->Request()->setParam('sPage', null);

        // Performance increase         $criteria->setFetchCount(false);
        $criteria->resetFacets();
        $criteria->limit(1);

        $numberResult = $this->productNumberSearch->search($criteria$context);

        return $numberResult->getTotalCount() > 0;
    }

    /** * @param array<string, mixed> $categoryContent */
    private function getRedirectLocation(array $categoryContent, bool $hasEmotion, ShopContextInterface $context): ?string
    {
        if (\is_string($categoryContent['external']) && $categoryContent['external'] !== '') {
            return $categoryContent['external'];
        }

        


        $condition = $criteria->getCondition('search');
        if (!$condition instanceof SearchTermCondition) {
            return;
        }

        $now = new DateTime();
        $this->connection->insert('s_statistics_search', [
            'datum' => $now->format('Y-m-d H:i:s'),
            'searchterm' => $condition->getTerm(),
            'results' => $result->getTotalCount(),
            'shop_id' => $shop->getId(),
        ]);
    }
}
$criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                break;
            case 'newcomer':
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                break;
        }

        /** @var ProductSearchResult $result */
        $result = Shopware()->Container()->get(ProductSearchInterface::class)->search($criteria$context);
        $data = Shopware()->Container()->get(LegacyStructConverter::class)->convertListProductStructList($result->getProducts());

        $count = $result->getTotalCount();
        if ($limit !== 0) {
            $pages = round($count / $limit);
        } else {
            $pages = 0;
        }

        if ($pages === 0 && $count > 0) {
            $pages = 1;
        }

        return ['values' => $data, 'pages' => $pages];
    }
// Verify the same when loading the site in a non-default language.     $this->drupalGet($this->language['langcode'] . '/' . $path);
    $settings = $this->getDrupalSettings();
    $this->assertSession()->responseMatches($expected_library);
    $this->assertSame($settings['statistics']['data']['nid']$this->node->id(), 'Found statistics settings on valid node page in a non-default language.');

    // Manually call statistics.php to simulate ajax data collection behavior.     global $base_root;
    $post = ['nid' => $this->node->id()];
    $this->client->post($base_root . $stats_path['form_params' => $post]);
    $node_counter = \Drupal::service('statistics.storage.node')->fetchView($this->node->id());
    $this->assertSame(1, $node_counter->getTotalCount());

    // Try fetching statistics for an invalid node ID and verify it returns     // FALSE.     $node_id = 1000000;
    $node = Node::load($node_id);
    $this->assertNull($node);

    // This is a test specifically for the deprecated statistics_get() function     // and so should remain unconverted until that function is removed.     $result = \Drupal::service('statistics.storage.node')->fetchView($node_id);
    $this->assertFalse($result);
  }
class StatisticsViewsResultTest extends UnitTestCase {

  /** * Tests migration of node counter. * * @covers ::__construct * * @dataProvider providerTestStatisticsCount */
  public function testStatisticsCount($total_count$day_count$timestamp) {
    $statistics = new StatisticsViewsResult($total_count$day_count$timestamp);
    $this->assertSame((int) $total_count$statistics->getTotalCount());
    $this->assertSame((int) $day_count$statistics->getDayCount());
    $this->assertSame((int) $timestamp$statistics->getTimestamp());
  }

  public function providerTestStatisticsCount() {
    return [
      [2, 0, 1421727536],
      [1, 0, 1471428059],
      [1, 1, 1478755275],
      ['1', '1', '1478755275'],
    ];
  }

                $price = $cheapestPrice->getCalculatedPrice();
                $product = json_decode(json_encode($product, JSON_THROW_ON_ERROR), true);
                $product['cheapestPrice'] = $price;

                return $product;
            }$products);

            $success = true;
            $error = false;
            $data = $products;
            $total = $result->getTotalCount();
        } catch (Exception $e) {
            $success = false;
            $error = $e->getMessage();
            $data = [];
            $total = 0;
        }

        $this->View()->assign([
            'success' => $success,
            'data' => $data,
            'total' => $total,
            
Criteria $criteria,
        ShopContextInterface $context
    ) {
        $numberResult = $this->searchGateway->search($criteria$context);

        $numbers = array_keys($numberResult->getProducts());
        $products = $this->productService->getList($numbers$context);
        $products = $this->assignAttributes($products$numberResult->getProducts());

        $result = new ProductSearchResult(
            $products,
            $numberResult->getTotalCount(),
            $numberResult->getFacets(),
            $criteria,
            $context
        );

        $result->addAttributes($numberResult->getAttributes());

        return $result;
    }

    /** * @param ListProduct[] $products * @param BaseProduct[] $searchProducts * * @return ListProduct[] */
$navigation['nextProduct']['name'] = $nextListProduct->getName();

                $nextCover = $nextListProduct->getCover();
                if ($nextCover) {
                    $navigation['nextProduct']['image'] = $this->legacyStructConverter->convertMediaStruct(
                        $nextCover
                    );
                }
            }

            $navigation['currentListing']['position'] = $index + 1;
            $navigation['currentListing']['totalCount'] = $searchResult->getTotalCount();

            return $navigation;
        }

        return [];
    }

    private function buildCategoryLink(int $categoryId, Enlight_Controller_Request_RequestHttp $request): string
    {
        $params = $this->queryAliasMapper->replaceLongParams($request->getParams());

        

  protected function assertNodeCounter(int $nid, int $total_count, int $day_count, int $timestamp): void {
    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
    $this->assertSame($total_count$statistics->getTotalCount());
    $this->assertSame($day_count$statistics->getDayCount());
    $this->assertSame($timestamp$statistics->getTimestamp());
  }

}
$this->setDefaultSorting();

        /** @var ShopContextInterface $context */
        $context = $this->get(\Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface::class)->getShopContext();

        $criteria = $this->get(\Shopware\Bundle\SearchBundle\StoreFrontCriteriaFactoryInterface::class)
            ->createAjaxSearchCriteria($this->Request()$context);

        $result = $this->search($term$criteria$context);

        if ($result->getTotalCount() > 0) {
            $products = $this->convertProducts($result);
            $this->View()->assign('searchResult', $result);
            $this->View()->assign('sSearchRequest', ['sSearch' => $term]);
            $this->View()->assign('sSearchResults', [
                'sResults' => $products,
                'sArticlesCount' => $result->getTotalCount(),
            ]);
        }
    }

    /** * @return array */
->from('s_categories', 'category')
            ->where('category.parent = :parentId')
            ->andWhere('category.active = 1')
            ->setParameter(':parentId', $categoryId);

        return array_map('\intval', $query->execute()->fetchFirstColumn());
    }

    private function setSearchResultResponse(ProductSearchResult $result): void
    {
        $body = [
            'totalCount' => $result->getTotalCount(),
        ];

        if ($this->Request()->getParam('loadFacets')) {
            $body['facets'] = array_values($result->getFacets());
            $body['listing'] = false;
            $body['pagination'] = false;
        }
        if ($this->Request()->getParam('loadProducts')) {
            $this->prepareListing($result);
            $body['listing'] = true;
            $this->preparePagination($result);
            
$data = $result->getData();

        foreach ($data as &$row) {
            if (empty($row['partner'])) {
                $row['partner'] = $row['trackingCode'];
            }
            if (empty($row['PartnerID'])) {
                $row['PartnerID'] = 0;
            }
        }

        $this->send($data$result->getTotalCount());
    }

    /** * @return void */
    public function getCustomerGroupAmountAction()
    {
        $result = $this->getRepository()->getCustomerGroupAmount(
            $this->getFromDate(),
            $this->getToDate(),
            $this->getSelectedShopIds()
        );

  protected function assertNodeCounter(int $nid, int $total_count, int $day_count, int $timestamp): void {
    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
    $this->assertSame($total_count$statistics->getTotalCount());
    $this->assertSame($day_count$statistics->getDayCount());
    $this->assertSame($timestamp$statistics->getTimestamp());
  }

}
try {
            $listingResult = $this->get('shopware_plugininstaller.plugin_service_view')->getStoreListing($context);
        } catch (Exception $e) {
            $this->handleException($e);

            return;
        }

        $this->View()->assign([
            'success' => true,
            'data' => array_values($listingResult->getPlugins()),
            'total' => $listingResult->getTotalCount(),
        ]);
    }

    /** * @return void */
    public function refreshPluginListAction()
    {
        $pluginManager = $this->get(InstallerService::class);
        $pluginManager->refreshPluginList();
        $this->View()->assign([
            
Home | Imprint | This part of the site doesn't use cookies.