Load a bulk of product data.

@param int     $storeId    Store id.
@param string  $productIds Product ids filter.
@param integer $fromId     Load product with id greater than.
@param integer $limit      Number of product to get loaded.

@return array
162653
private function getSearchableProducts($storeId, $productIds = null, $fromId = 0, $limit = 10000)
    {
        return $this->resourceModel->getSearchableProducts($storeId, $productIds, $fromId, $limit);
    }
683701
public function getRateLimitData($applicationId, $userId)
	{
		$sql = "SELECT * FROM `#__developer_rate_limit` 
				WHERE `application_id` = " . $this->db->quote($applicationId) . "
				AND `uidNumber` = " . $this->db->quote($userId) . "
				ORDER BY `created` LIMIT 1";
		$this->db->setQuery($sql);
		return $this->db->loadObject();
	}
875555
public function addData($storeId, array $indexData)
    {
        $priceData = $this->resourceModel->loadPriceData($storeId, array_keys($indexData));

        foreach ($priceData as $priceDataRow) {
            $productId     = (int) $priceDataRow['entity_id'];
            $productTypeId = $indexData[$productId]['type_id'];
            $priceModifier = $this->getPriceDataReader($productTypeId);

            $originalPrice = $priceModifier->getOriginalPrice($priceDataRow);
            $price         = $priceModifier->getPrice($priceDataRow);

            $indexData[$productId]['price'][] = [
                'price'             => $price,
                'original_price'    => $originalPrice,
                'is_discount'       => $price < $originalPrice,
                'customer_group_id' => $priceDataRow['customer_group_id'],
            ];

            if (!isset($indexData[$productId]['indexed_attributes'])) {
                $indexData[$productId]['indexed_attributes'] = ['price'];
            } elseif (!in_array('price', $indexData[$productId]['indexed_attributes'])) {
                // Add price only one time.
                $indexData[$productId]['indexed_attributes'][] = 'price';
            }
        }

        return $indexData;
    }
44392
public function loadByQuoteId($quoteId, $storeId)
    {
        $item = $this->campaignCollection->create()
            ->loadByQuoteId($quoteId, $storeId);

        if ($item) {
            return $item;
        } else {
            return $this->setQuoteId($quoteId)
                ->setStoreId($storeId);
        }
    }
422651
private function getEffectOnProduct($baseProductIds, $optimizedProductIds, $productId)
    {
        $result                   = 0;
        $baseProductPosition      = array_search($productId, $baseProductIds);
        $optimizedProductPosition = array_search($productId, $optimizedProductIds);

        if ($baseProductPosition === false && $optimizedProductPosition !== false) {
            $result = 1;
        } elseif ($baseProductPosition !== false && $optimizedProductPosition === false) {
            $result = -1;
        } elseif ($baseProductPosition !== false && $optimizedProductPosition !== false) {
            if ($baseProductPosition > $optimizedProductPosition) {
                $result = 1;
            }
            if ($baseProductPosition < $optimizedProductPosition) {
                $result = -1;
            }
        }

        return $result;
    }
930107
public function getSearchableCategories($storeId, $categoryIds = null, $fromId = 0, $limit = 100)
    {
        /**
         * @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection
         */
        $categoryCollection = $this->categoryCollectionFactory->create();
        $categoryCollection->addIsActiveFilter();
        $select = $categoryCollection->getSelect();

        $this->addIsVisibleInStoreFilter($select, $storeId);

        if ($categoryIds !== null) {
            $select->where('e.entity_id IN (?)', $categoryIds);
        }

        $select->where('e.entity_id > ?', $fromId)
            ->limit($limit)
            ->order('e.entity_id');

        return $this->connection->fetchAll($select);
    }
34177
public function loadChildrens($productIds, $storeId)
    {
        $children = [];

        foreach ($this->catalogProductType->getCompositeTypes() as $productTypeId) {
            $typeInstance = $this->getProductTypeInstance($productTypeId);
            $relation = $typeInstance->getRelationInfo();

            if ($relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
                $select = $this->getRelationQuery($relation, $productIds, $storeId);
                $data   = $this->getConnection()->fetchAll($select);

                foreach ($data as $relationRow) {
                    $parentId = (int) $relationRow['parent_id'];
                    $childId  = (int) $relationRow['child_id'];
                    $sku      = (string) $relationRow['sku'];
                    $configurableAttributes = array_filter(explode(',', $relationRow["configurable_attributes"]));
                    $children[$childId][] = [
                        "parent_id"               => $parentId,
                        "configurable_attributes" => $configurableAttributes,
                        "sku"                     => $sku,
                    ];
                }
            }
        }

        return $children;
    }
53171
public function syncByStore($storeId, $websiteId, $limit, $importType)
    {
        $products = $this->exporter->exportCatalog($storeId, $limit);

        $success = $this->importerFactory->create()
            ->registerQueue(
                $importType,
                $products,
                \Dotdigitalgroup\Email\Model\Importer::MODE_BULK,
                $websiteId
            );

        if ($success) {
            return $products;
        } else {
            $pid = implode(",", array_keys($products));
            $msg = "Failed to register with IMPORTER. Type(Catalog) / Scope(Bulk) / Store($storeId) / Product Ids($pid)";
            $this->helper->log($msg);
        }

        return [];
    }
570104
public function getProductPositions($categoryId, $storeId)
    {
        $select = $this->getBaseSelect()
            ->where('category_id = ?', (int) $categoryId)
            ->where('store_id = ?', (int) $storeId)
            ->where('position IS NOT NULL')
            ->columns(['product_id', 'position']);

        return $this->getConnection()->fetchPairs($select);
    }
432883
public function loadTargetData($targetId, int $status): array
    {
        $query = $this->getTargetSelectQuery();
        $query->where(
            $query->expr()->eq('id', ':id')
        )
        ->setParameter('id', $targetId, Type::INTEGER);

        $this->applyStatusCondition($query, $status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
578289
public function loadConditionData($conditionId, int $status): array
    {
        $query = $this->getConditionSelectQuery();
        $query->where(
            $query->expr()->eq('id', ':id')
        )
        ->setParameter('id', $conditionId, Type::INTEGER);

        $this->applyStatusCondition($query, $status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
717763
public function readByUser(int $userId, int $expirationInSeconds, int $limit = null): array
    {
        try {
            /** @var TokenInterface[] $tokens */
            $tokens = parent::readByUser($userId, $expirationInSeconds, $limit);

            // select scope identifiers for tokens
            if (empty($tokens) === false) {
                $schema        = $this->getDatabaseSchema();
                $tokenIdColumn = $schema->getTokensScopesTokenIdentityColumn();
                $scopeIdColumn = $schema->getTokensScopesScopeIdentityColumn();

                $connection = $this->getConnection();
                $query      = $connection->createQueryBuilder();

                $tokenIds = array_keys($tokens);
                $query
                    ->select([$tokenIdColumn, $scopeIdColumn])
                    ->from($schema->getTokensScopesTable())
                    ->where($query->expr()->in($tokenIdColumn, $tokenIds))
                    ->orderBy($tokenIdColumn);

                $statement = $query->execute();
                $statement->setFetchMode(PDO::FETCH_ASSOC);
                $tokenScopePairs = $statement->fetchAll();

                $curTokenId = null;
                $curScopes  = null;
                // set selected scopes to tokens
                foreach ($tokenScopePairs as $pair) {
                    $tokenId = $pair[$tokenIdColumn];
                    $scopeId = $pair[$scopeIdColumn];

                    if ($curTokenId !== $tokenId) {
                        $assignScopes = $curTokenId !== null && empty($curScopes) === false;
                        $assignScopes ? $tokens[$curTokenId]->setScopeIdentifiers($curScopes) : null;
                        $curTokenId = $tokenId;
                        $curScopes  = [$scopeId];

                        continue;
                    }

                    $curScopes[] = $scopeId;
                }
                $curTokenId === null || empty($curScopes) === true ?:
                    $tokens[$curTokenId]->setScopeIdentifiers($curScopes);
            }

            return $tokens;
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (RepositoryException | DBALEx $exception) {
            $message = 'Token reading failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }
1037417
public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = [])
    {
        return $this->listForId($customer->id, $from, $limit, $parameters);
    }
1325136
public function getProductsToExportByStore($store, $limit)
    {
        $connectorCollection = $this;
        $connectorCollection->addFieldToFilter(
            ['imported', 'modified'],
            [
                ['null' => 'true'],
                ['eq' => '1']
            ]
        );
        $connectorCollection->getSelect()->limit($limit);
        $connectorCollection->setOrder(
            'product_id',
            'asc'
        );

        //check number of products
        if ($connectorCollection->getSize()) {
            $productIds = $connectorCollection->getColumnValues('product_id');

            $productCollection = $this->productCollection->create()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter(
                    'entity_id',
                    ['in' => $productIds]
                )->addUrlRewrite();

            if (!empty($store)) {
                $productCollection->addStoreFilter($store);
            }

            //visibility filter
            if ($visibility = $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VISIBILITY
            )
            ) {
                $visibility = explode(',', $visibility);
                //remove the default option from values
                $visibility = array_filter($visibility);
                $productCollection->addAttributeToFilter(
                    'visibility',
                    ['in' => $visibility]
                );
            }
            //type filter
            if ($type = $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_CATALOG_TYPE
            )
            ) {
                $type = explode(',', $type);
                $productCollection->addAttributeToFilter(
                    'type_id',
                    ['in' => $type]
                );
            }

            $productCollection->addWebsiteNamesToResult()
                ->addCategoryIds()
                ->addOptionsToResult();

            $productCollection->clear();

            return $productCollection;
        }

        return [];
    }
315425
public function reachedItemLimit( $storageId, $limit )
    {
        return (
            isset( $this->storageData[$storageId] )
            && count( $this->storageData[$storageId] ) >= $limit
        );
    }
248318
protected function getCategoryProductSelect($productIds, $storeId)
    {
        $select = $this->getConnection()->select()
            ->from(['cpi' => $this->getTable($this->getCategoryProductIndexTable($storeId))])
            ->where('cpi.store_id = ?', $storeId)
            ->where('cpi.product_id IN(?)', $productIds);

        return $select;
    }
1173458
public function getStoreQuotesFromQuoteIds($quoteIds, $storeId)
    {
        $salesCollection = $this->quoteCollection->create()
            ->addFieldToFilter('is_active', 1)
            ->addFieldToFilter('items_count', ['gt' => 0])
            ->addFieldToFilter('customer_email', ['neq' => ''])
            ->addFieldToFilter('entity_id', ['in' => $quoteIds]);

        if ($this->helper->isOnlySubscribersForAC($storeId)) {
            $salesCollection = $this->subscriberFilterer->filterBySubscribedStatus($salesCollection);
        }

        return $salesCollection;
    }