Block/Recommended/Recentlyviewed.php
public function getLoadedProductCollection()
    {
        $params = $this->getRequest()->getParams();
        //check for param code and id
        if (! isset($params['customer_id']) ||
            ! isset($params['code']) ||
            ! $this->helper->isCodeValid($params['code'])
        ) {
            $this->helper->log('Recently viewed no id or valid code is set');
            return [];
        }

        $productsToDisplay = [];
        $mode = $this->getRequest()->getActionName();
        $customerId = (int) $this->getRequest()->getParam('customer_id');
        $limit = (int) $this->recommnededHelper->getDisplayLimitByMode($mode);

        //login customer to receive the recent products
        $session = $this->sessionFactory->create();
        $isLoggedIn = $session->loginById($customerId);
        $productIds = $this->catalog->getRecentlyViewed($customerId, $limit);

        //get product collection to check for salable
        $productCollection = $this->catalog->getProductCollectionFromIds($productIds);

        //show products only if is salable
        foreach ($productCollection as $product) {
            if ($product->isSalable()) {
                $productsToDisplay[$product->getId()] = $product;
            }
        }
        $this->helper->log(
            'Recentlyviewed customer  : ' . $customerId . ', mode ' . $mode
            . ', limit : ' . $limit .
            ', items found : ' . count($productIds) . ', is customer logged in : '
            . $isLoggedIn . ', products :' . count($productsToDisplay)
        );

        $session->logout();

        return $productsToDisplay;
    }
public function getLoadedProductCollection()
    {
        $params = $this->getRequest()->getParams();
        //check for param code and id
        if (! isset($params['customer_id']) ||
            ! isset($params['code']) ||
            ! $this->helper->isCodeValid($params['code'])
        ) {
            $this->helper->log('Recently viewed no id or valid code is set');
            return [];
        }

        $productsToDisplay = [];
        $mode = $this->getRequest()->getActionName();
        $customerId = (int) $this->getRequest()->getParam('customer_id');
        $limit = (int) $this->recommnededHelper->getDisplayLimitByMode($mode);

        //login customer to receive the recent products
        $session = $this->sessionFactory->create();
        $isLoggedIn = $session->loginById($customerId);
        $productIds = $this->catalog->getRecentlyViewed($customerId, $limit);

        //get product collection to check for salable
        $productCollection = $this->catalog->getProductCollectionFromIds($productIds);

        //show products only if is salable
        foreach ($productCollection as $product) {
            if ($product->isSalable()) {
                $productsToDisplay[$product->getId()] = $product;
            }
        }
        $this->helper->log(
            'Recentlyviewed customer  : ' . $customerId . ', mode ' . $mode
            . ', limit : ' . $limit .
            ', items found : ' . count($productIds) . ', is customer logged in : '
            . $isLoggedIn . ', products :' . count($productsToDisplay)
        );

        $session->logout();

        return $productsToDisplay;
    }
public function getLoadedProductCollection ( ) { $ params = $ this -> getRequest ( ) -> getParams ( ) ; //check for param code and id if ( ! isset ( $ params [ 'customer_id' ] ) || ! isset ( $ params [ 'code' ] ) || ! $ this -> helper -> isCodeValid ( $ params [ 'code' ] ) ) { $ this -> helper -> log ( 'Recently viewed no id or valid code is set' ) ; return [ ] ; } $ productsToDisplay = [ ] ; $ mode = $ this -> getRequest ( ) -> getActionName ( ) ; $ customerId = ( int ) $ this -> getRequest ( ) -> getParam ( 'customer_id' ) ; $ limit = ( int ) $ this -> recommnededHelper -> getDisplayLimitByMode ( $ mode ) ; //login customer to receive the recent products $ session = $ this -> sessionFactory -> create ( ) ; $ isLoggedIn = $ session -> loginById ( $ customerId ) ; $ productIds = $ this -> catalog -> getRecentlyViewed ( $ customerId , $ limit ) ; //get product collection to check for salable $ productCollection = $ this -> catalog -> getProductCollectionFromIds ( $ productIds ) ; //show products only if is salable foreach ( $ productCollection as $ product ) { if ( $ product -> isSalable ( ) ) { $ productsToDisplay [ $ product -> getId ( ) ] = $ product ; } } $ this -> helper -> log ( 'Recentlyviewed customer  : ' . $ customerId . ', mode ' . $ mode . ', limit : ' . $ limit . ', items found : ' . count ( $ productIds ) . ', is customer logged in : ' . $ isLoggedIn . ', products :' . count ( $ productsToDisplay ) ) ; $ session -> logout ( ) ; return $ productsToDisplay ; }
Products collection.

@return array
Products collection .