@param array            $productsToBuy
@param array            $productIds
@param DataBaseExporter $exporter
@param int              $internalOrderId

@return int
323953
public function purchase(array $productsToBuy, array $productIds, DataBaseExporter $exporter, int $internalOrderId): int
    {
        $preOrdersCount = 0;
        $order = Order::createOrder($productsToBuy, $internalOrderId, true);

        foreach ($order->getProducts() as $product) {
            $numberOfPreOrders = 0;
            $links = [];

            foreach ($product->getCodes() as $code) {

                if ($code->isPreOrder()) {
                    $numberOfPreOrders++;
                    $preOrdersCount++;
                }

                $links[] = $code->getCodeId();
            }

            $orderedCodes = [
                'cwOrderId' => $order->getOrderId(),
                'links' => $links,
                'preOrders' => $numberOfPreOrders
            ];

            $exporter->export(null, $orderedCodes, $productIds[$product->getProductId()], $internalOrderId);
        }

        return $preOrdersCount;
    }
120086
private function reindex($productIds)
    {
        $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->reindexList($productIds);
    }
855180
protected function getUnprocessedTransactionStatusLogs($idSalesOrder, $idSalesOrderItem)
    {
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsBySalesOrder($idSalesOrder)->find();

        $ids = [];

        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */
        foreach ($transactionStatusLogs as $transactionStatusLog) {
            $ids[$transactionStatusLog->getIdPaymentPayoneTransactionStatusLog()] = $transactionStatusLog;
        }

        $relations = $this->queryContainer
            ->createTransactionStatusLogOrderItemsByLogIds($idSalesOrderItem, array_keys($ids))
            ->find();

        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogOrderItem $relation */
        foreach ($relations as $relation) {
            unset($ids[$relation->getIdPaymentPayoneTransactionStatusLog()]);
        }

        return $ids;
    }
1092944
public function addProducts($productIds)
    {
        $fullTextIndexer    = $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID);
        $indexerChangeLog   = $fullTextIndexer->getView()->getChangelog();

        $changelogTableName = $indexerChangeLog->getName();
        $columnName         = $indexerChangeLog->getColumnName();

        try {
            $indexerChangeLog->create();

            $this->resource->getConnection()->insertArray(
                $changelogTableName,
                [$columnName],
                $productIds
            );
        } catch (\Exception $e) {
            throw new CouldNotSaveException(__(
                'Could not schedule products for reindexing : %1',
                $e->getMessage()
            ));
        }
    }
426965
public function incrementStockCount(string $productNumber, int $amount) : array
    {
        Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0');

        return $this->incrementOrDecrementStockCount($productNumber, abs($amount));
    }
851582
private function addFilterByParent(ProductCollection $productCollection, $parentId)
    {
        $tableProductRelation = $productCollection->getTable('catalog_product_relation');
        $productCollection->getSelect()->join(
            ['pr' => $tableProductRelation],
            'e.entity_id = pr.child_id'
        )->where('pr.parent_id = ?', $parentId);
    }
1087129
protected function mergeRecords(array $records)
    {
        foreach ($records as $key => $record) {
            if (null === $id = array_get($record, static::ID_FIELD)) {
                throw new InternalServerErrorException('No ' .
                    static::ID_FIELD .
                    ' field found in supplied record(s). Cannot merge record(s) for PATCH operation.');
            }

            $rs = $this->getConnection()->getDocument($this->transactionTable, $id);
            $record = array_merge($rs, $record);
            $records[$key] = $record;
        }

        return $records;
    }
1112721
protected function _getProductData(Product $product, ProductIterator $children)
    {
        $categoryIds = $this->categoryRepository->getCategoryIds($product);
        $productData = new IndexDocument(array(
            'id' => $product->getSolrId(), // primary identifier, must be unique
            'product_id' => $product->getId(),
            'category' => $categoryIds, // @todo get category ids from parent anchor categories as well
            'category_name_t_mv' => $this->categoryRepository->getCategoryNames($categoryIds, $product->getStoreId()),
            'store_id' => $product->getStoreId(),
            'content_type' => self::CONTENT_TYPE,
            'is_visible_in_catalog_i' => intval($product->isVisibleInCatalog()),
            'is_visible_in_search_i' => intval($product->isVisibleInSearch()),
            'has_special_price_i' => intval($product->hasSpecialPrice()),
            'is_in_stock_i' => intval($product->isInStock()),
        ));

        $this->_addBoostToProductData($product, $productData);

        $this->_addFacetsToProductData($product, $productData, $children);

        $this->_addSearchDataToProductData($product, $productData, $children);

        $this->_addSortingDataToProductData($product, $productData);

        $this->_addResultHtmlToProductData($product, $productData);

        $this->_addCategoryProductPositionsToProductData($product, $productData);

        $this->eventDispatcher->dispatch('integernet_solr_get_product_data', array(
            'product' => $product,
            'product_data' => $productData,
            'children' => $children,
        ));

        return $productData;
    }
460623
public function set($product_id, array $products)
    {
        $this->delete(array('product_id' => $product_id));

        $added = $count = 0;
        foreach ($products as $product) {

            $count++;

            $data = array(
                'product_id' => $product_id,
                'item_product_id' => $product['product_id']
            );

            if ($this->add($data)) {
                $added++;
            }
        }

        return $count && $added == $count;
    }
710425
protected function saveProductListCustomerRelation(
        ProductListTransfer $productListTransfer,
        ProductListCustomerRelationTransfer $productListCustomerRelationTransfer
    ): ProductListTransfer {
        $productListCustomerRelationTransfer->setIdProductList($productListTransfer->getIdProductList());

        $productListCustomerRelationTransfer = $this->getFacade()
            ->saveProductListCustomerRelation($productListCustomerRelationTransfer);

        $productListTransfer->setProductListCustomerRelation($productListCustomerRelationTransfer);

        return $productListTransfer;
    }
704362
public function loadInventoryData($storeId, $productIds)
    {
        $websiteId = $this->getWebsiteId($storeId);
        $stockId   = $this->getStockId($websiteId);
        $tableName = $this->stockIndexTableProvider->execute($stockId);

        $select = $this->getConnection()->select()
            ->from(['product' => $this->getTable('catalog_product_entity')], [])
            ->join(
                ['stock_index' => $tableName],
                'product.sku = stock_index.' . IndexStructure::SKU,
                [
                    'product_id'    => 'product.entity_id',
                    'stock_status'  => 'stock_index.' . IndexStructure::IS_SALABLE,
                    'qty'           => 'stock_index.' . IndexStructure::QUANTITY,
                ]
            )
            ->where('product.entity_id IN (?)', $productIds)
            ->group('product.entity_id');

        return $this->getConnection()->fetchAll($select);
    }
65085
protected function setItemByProductData($productData, ApiItemInterface $item, $locale)
    {
        $productId = $this->getProductId($productData, 'product.id');

        /** @var Product $product */
        $product = $this->productRepository->find($productId);
        if (!$product) {
            throw new ProductNotFoundException(self::$productEntityName, $productId);
        }
        $item->setProduct($product);
        $translation = $product->getTranslation($locale);

        // When the product is not available in the current language choose the first translation you find.
        if (is_null($translation)) {
            if (count($product->getTranslations()) > 0) {
                $translation = $product->getTranslations()[0];
            } else {
                throw new ProductException('Product ' . $product->getId() . ' has no translations!');
            }
        }

        $this->setItemSupplier($item, $product);

        $item->setName($translation->getName());
        $item->setDescription($translation->getLongDescription());
        $item->setNumber($product->getNumber());

        // set order unit
        if ($product->getOrderUnit()) {
            $item->setQuantityUnit($product->getOrderUnit()->getTranslation($locale)->getName());
        } else if ($product->getParent() && $product->getParent()->getOrderUnit()) {
            $item->setQuantityUnit($product->getParent()->getOrderUnit()->getTranslation($locale)->getName());
        }

        $item->setIsRecurringPrice($product->isRecurringPrice());

        $taxClass = $product->getTaxClass();

        /*
         * If the product doesn't have a taxClass but has a parent, we try to get the taxClass from the parent.
         * This is used for product variants, which get the taxClass from the original product.
         */
        if (!$taxClass && $product->getParent()) {
            $taxClass = $product->getParent()->getTaxClass();
        }

        if ($taxClass) {
            $tax = $this->retrieveTaxForClass($taxClass);
            $item->setTax($tax);
        } else {
            $item->setTax(0);
        }

        return $product;
    }
1173800
public function expandProductListTransferWithProductListCompanyRelationTransfer(
        ProductListTransfer $productListTransfer
    ): ProductListTransfer {
        $productListTransfer = $this->getFactory()->createProductListTransferExpander()
            ->expandWithProductListCompanyRelationTransfer($productListTransfer);

        return $productListTransfer;
    }
1214945
public function rebuildStoreIndex($storeId, $productIds = null)
    {
        $productId = 0;

        // Magento is only sending children ids here. Ensure to reindex also the parents product ids, if any.
        if (!empty($productIds)) {
            $productIds = array_unique(array_merge($productIds, $this->resourceModel->getRelationsByChild($productIds)));
        }

        do {
            $products = $this->getSearchableProducts($storeId, $productIds, $productId);

            foreach ($products as $productData) {
                $productId = (int) $productData['entity_id'];
                $productData['has_options']      = (bool) $productData['has_options'];
                $productData['required_options'] = (bool) $productData['required_options'];
                yield $productId => $productData;
            }
        } while (!empty($products));
    }
136427
public function listProductFamily($productFamilyId)
    {
        $service = $this->getService();

        $response      = $service->request('product_families/' . (int)$productFamilyId . '/components', 'GET');
        $responseArray = $this->getResponseArray($response);

        if (!$this->isError()) {
            $this->_data = $this->_normalizeResponseArray($responseArray);
        } else {
            $this->_data = array();
        }

        return $this;
    }
926125
public function deleteProductListCompanyRelations(ProductListTransfer $productListTransfer): void
    {
        $productListCompanyEntities = $this->getFactory()
            ->createProductListCompanyQuery()
            ->filterByFkProductList($productListTransfer->getIdProductList())
            ->find();

        foreach ($productListCompanyEntities as $productListCompanyEntity) {
            $productListCompanyEntity->delete();
        }
    }
1085118
public function getExportProductId()
    {
        return $this->getInternalOrderInfo()->getItemType() == Grouped::TYPE_CODE
            ? $this->getChildId()
            : $this->getParentId();
    }