本文整理汇总了PHP中Magento\Framework\DB\Adapter\AdapterInterface::fetchPairs方法的典型用法代码示例。如果您正苦于以下问题:PHP AdapterInterface::fetchPairs方法的具体用法?PHP AdapterInterface::fetchPairs怎么用?PHP AdapterInterface::fetchPairs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DB\Adapter\AdapterInterface
的用法示例。
在下文中一共展示了AdapterInterface::fetchPairs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveLinksData
/**
* @param array $linksData
* @return void
*/
public function saveLinksData($linksData)
{
$mainTable = $this->productLink->getMainTable();
$relationTable = $this->productLink->getTable('catalog_product_relation');
// save links and relations
if ($linksData['product_ids']) {
$this->deleteOldLinks(array_keys($linksData['product_ids']));
$mainData = [];
foreach ($linksData['relation'] as $productData) {
$mainData[] = ['product_id' => $productData['parent_id'], 'linked_product_id' => $productData['child_id'], 'link_type_id' => $this->getLinkTypeId()];
}
$this->connection->insertOnDuplicate($mainTable, $mainData);
$this->connection->insertOnDuplicate($relationTable, $linksData['relation']);
}
$attributes = $this->getAttributes();
// save positions and default quantity
if ($linksData['attr_product_ids']) {
$savedData = $this->connection->fetchPairs($this->connection->select()->from($mainTable, [new \Zend_Db_Expr('CONCAT_WS(" ", product_id, linked_product_id)'), 'link_id'])->where('product_id IN (?) AND link_type_id = ' . $this->connection->quote($this->getLinkTypeId()), array_keys($linksData['attr_product_ids'])));
foreach ($savedData as $pseudoKey => $linkId) {
if (isset($linksData['position'][$pseudoKey])) {
$linksData['position'][$pseudoKey]['link_id'] = $linkId;
}
if (isset($linksData['qty'][$pseudoKey])) {
$linksData['qty'][$pseudoKey]['link_id'] = $linkId;
}
}
if (!empty($linksData['position'])) {
$this->connection->insertOnDuplicate($attributes['position']['table'], $linksData['position']);
}
if (!empty($linksData['qty'])) {
$this->connection->insertOnDuplicate($attributes['qty']['table'], $linksData['qty']);
}
}
}
示例2: getAggregation
/**
* {@inheritdoc}
*/
public function getAggregation(BucketInterface $bucket, array $dimensions, $range, \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
{
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
$column = $select->getPart(Select::COLUMNS)[0];
$select->reset(Select::COLUMNS);
$rangeExpr = new \Zend_Db_Expr($this->connection->quoteInto('(FLOOR(' . $column[1] . ' / ? ) + 1)', $range));
$select->columns(['range' => $rangeExpr])->columns(['metrix' => 'COUNT(*)'])->group('range')->order('range');
$result = $this->connection->fetchPairs($select);
return $result;
}
示例3: _reindexRows
/**
* Refresh entities index
*
* @param array $changedIds
* @return array Affected ids
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _reindexRows($changedIds = [])
{
$this->_emptyTable($this->_getIdxTable());
$this->_prepareWebsiteDateTable();
$select = $this->_connection->select()->from($this->_getTable('catalog_product_entity'), ['entity_id', 'type_id'])->where('entity_id IN(?)', $changedIds);
$pairs = $this->_connection->fetchPairs($select);
$byType = [];
foreach ($pairs as $productId => $productType) {
$byType[$productType][$productId] = $productId;
}
$compositeIds = [];
$notCompositeIds = [];
foreach ($byType as $productType => $entityIds) {
$indexer = $this->_getIndexer($productType);
if ($indexer->getIsComposite()) {
$compositeIds += $entityIds;
} else {
$notCompositeIds += $entityIds;
}
}
if (!empty($notCompositeIds)) {
$select = $this->_connection->select()->from(['l' => $this->_getTable('catalog_product_relation')], 'parent_id')->join(['e' => $this->_getTable('catalog_product_entity')], 'e.entity_id = l.parent_id', ['type_id'])->where('l.child_id IN(?)', $notCompositeIds);
$pairs = $this->_connection->fetchPairs($select);
foreach ($pairs as $productId => $productType) {
if (!in_array($productId, $changedIds)) {
$changedIds[] = $productId;
$byType[$productType][$productId] = $productId;
$compositeIds[$productId] = $productId;
}
}
}
if (!empty($compositeIds)) {
$this->_copyRelationIndexData($compositeIds, $notCompositeIds);
}
$this->_prepareTierPriceIndex($compositeIds + $notCompositeIds);
$this->_prepareGroupPriceIndex($compositeIds + $notCompositeIds);
$indexers = $this->getTypeIndexers();
foreach ($indexers as $indexer) {
if (!empty($byType[$indexer->getTypeId()])) {
$indexer->reindexEntity($byType[$indexer->getTypeId()]);
}
}
$this->_syncData($changedIds);
return $compositeIds + $notCompositeIds;
}
示例4: getProductAttributes
/**
* Load product(s) attributes
*
* @param int $storeId
* @param array $productIds
* @param array $attributeTypes
* @return array
*/
public function getProductAttributes($storeId, array $productIds, array $attributeTypes)
{
$result = [];
$selects = [];
$ifStoreValue = $this->connection->getCheckSql('t_store.value_id > 0', 't_store.value', 't_default.value');
$linkField = $this->metadata->getLinkField();
$productLinkFieldsToEntityIdMap = $this->connection->fetchPairs($this->connection->select()->from(['cpe' => $this->getTable('catalog_product_entity')], [$linkField, 'entity_id'])->where('cpe.entity_id IN (?)', $productIds));
foreach ($attributeTypes as $backendType => $attributeIds) {
if ($attributeIds) {
$tableName = $this->getTable('catalog_product_entity_' . $backendType);
$selects[] = $this->connection->select()->from(['t_default' => $tableName], [$linkField, 'attribute_id'])->joinLeft(['t_store' => $tableName], $this->connection->quoteInto('t_default.' . $linkField . '=t_store.' . $linkField . ' AND t_default.attribute_id=t_store.attribute_id' . ' AND t_store.store_id = ?', $storeId), ['value' => $this->unifyField($ifStoreValue, $backendType)])->where('t_default.store_id = ?', 0)->where('t_default.attribute_id IN (?)', $attributeIds)->where('t_default.' . $linkField . ' IN (?)', array_keys($productLinkFieldsToEntityIdMap));
}
}
if ($selects) {
$select = $this->connection->select()->union($selects, \Magento\Framework\DB\Select::SQL_UNION_ALL);
$query = $this->connection->query($select);
while ($row = $query->fetch()) {
$entityId = $productLinkFieldsToEntityIdMap[$row[$linkField]];
$result[$entityId][$row['attribute_id']] = $row['value'];
}
}
return $result;
}
示例5: retrieveProducsByCachedSkus
/**
* Retrieve mapping between skus and products.
*
* @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
*/
protected function retrieveProducsByCachedSkus()
{
$this->_cachedSkuToProducts = $this->connection->fetchPairs($this->connection->select()->from($this->_resource->getTableName('catalog_product_entity'), ['sku', 'entity_id'])->where('sku IN (?)', $this->_cachedSkus));
return $this;
}