当前位置: 首页>>代码示例>>PHP>>正文


PHP AdapterInterface::insertOnDuplicate方法代码示例

本文整理汇总了PHP中Magento\Framework\DB\Adapter\AdapterInterface::insertOnDuplicate方法的典型用法代码示例。如果您正苦于以下问题:PHP AdapterInterface::insertOnDuplicate方法的具体用法?PHP AdapterInterface::insertOnDuplicate怎么用?PHP AdapterInterface::insertOnDuplicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\DB\Adapter\AdapterInterface的用法示例。


在下文中一共展示了AdapterInterface::insertOnDuplicate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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']);
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:38,代码来源:Links.php

示例2: _prepareWebsiteDateTable

 /**
  * Prepare website current dates table
  *
  * @return \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction
  */
 protected function _prepareWebsiteDateTable()
 {
     $baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE);
     $select = $this->_connection->select()->from(['cw' => $this->_defaultIndexerResource->getTable('store_website')], ['website_id'])->join(['csg' => $this->_defaultIndexerResource->getTable('store_group')], 'cw.default_group_id = csg.group_id', ['store_id' => 'default_store_id'])->where('cw.website_id != 0');
     $data = [];
     foreach ($this->_connection->fetchAll($select) as $item) {
         /** @var $website \Magento\Store\Model\Website */
         $website = $this->_storeManager->getWebsite($item['website_id']);
         if ($website->getBaseCurrencyCode() != $baseCurrency) {
             $rate = $this->_currencyFactory->create()->load($baseCurrency)->getRate($website->getBaseCurrencyCode());
             if (!$rate) {
                 $rate = 1;
             }
         } else {
             $rate = 1;
         }
         /** @var $store \Magento\Store\Model\Store */
         $store = $this->_storeManager->getStore($item['store_id']);
         if ($store) {
             $timestamp = $this->_localeDate->scopeTimeStamp($store);
             $data[] = ['website_id' => $website->getId(), 'website_date' => $this->_dateTime->formatDate($timestamp, false), 'rate' => $rate];
         }
     }
     $table = $this->_defaultIndexerResource->getTable('catalog_product_index_website');
     $this->_emptyTable($table);
     if ($data) {
         foreach ($data as $row) {
             $this->_connection->insertOnDuplicate($table, $row, array_keys($row));
         }
     }
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:37,代码来源:AbstractAction.php

示例3: testReadEncoded

 /**
  * Assert that session data reads from DB correctly regardless of encoding
  *
  * @param string $sessionData
  *
  * @dataProvider readEncodedDataProvider
  */
 public function testReadEncoded($sessionData)
 {
     $sessionRecord = [self::COLUMN_SESSION_ID => self::SESSION_ID, self::COLUMN_SESSION_DATA => $sessionData];
     $this->_connection->insertOnDuplicate($this->_sessionTable, $sessionRecord, [self::COLUMN_SESSION_DATA]);
     $sessionData = $this->_model->read(self::SESSION_ID);
     $this->assertEquals($this->_sourceData[self::SESSION_NEW], unserialize($sessionData));
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:14,代码来源:DbTableTest.php

示例4: testInsertOnDuplicate

 /**
  * @dataProvider insertDataProvider
  */
 public function testInsertOnDuplicate($data)
 {
     $this->_connection->insertOnDuplicate($this->_tableName, $data);
     $select = $this->_connection->select()->from($this->_tableName);
     $result = $this->_connection->fetchRow($select);
     $this->assertEquals($data, $result);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:InterfaceTest.php

示例5: insertDocumentsForFilterable

 /**
  * @param array $documents
  * @param Dimension[] $dimensions
  * @return void
  */
 protected function insertDocumentsForFilterable(array $documents, array $dimensions)
 {
     $onDuplicate = [];
     foreach ($this->fields as $field) {
         if ($field['type'] === $this->dataTypes[1]) {
             $onDuplicate[] = $field['name'];
         }
     }
     $this->connection->insertOnDuplicate($this->getTableName($this->dataTypes[1], $dimensions), $this->prepareFilterableFields($documents), $onDuplicate);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:IndexerHandler.php

示例6: saveRuleProductPrices

 /**
  * @param array $arrData
  * @return $this
  * @throws \Exception
  */
 protected function saveRuleProductPrices($arrData)
 {
     if (empty($arrData)) {
         return $this;
     }
     $productIds = [];
     try {
         foreach ($arrData as $key => $data) {
             $productIds['product_id'] = $data['product_id'];
             $arrData[$key]['rule_date'] = $this->dateFormat->formatDate($data['rule_date'], false);
             $arrData[$key]['latest_start_date'] = $this->dateFormat->formatDate($data['latest_start_date'], false);
             $arrData[$key]['earliest_end_date'] = $this->dateFormat->formatDate($data['earliest_end_date'], false);
         }
         $this->connection->insertOnDuplicate($this->getTable('catalogrule_product_price'), $arrData);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:24,代码来源:IndexBuilder.php

示例7: insertSelections

 /**
  * Insert selections.
  *
  * @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
  */
 protected function insertSelections()
 {
     $selectionTable = $this->_resource->getTableName('catalog_product_bundle_selection');
     $selections = [];
     foreach ($this->_cachedOptions as $productId => $options) {
         foreach ($options as $option) {
             $index = 0;
             foreach ($option['selections'] as $selection) {
                 if (isset($selection['position'])) {
                     $index = $selection['position'];
                 }
                 if ($tmpArray = $this->populateSelectionTemplate($selection, $option['option_id'], $productId, $index)) {
                     $selections[] = $tmpArray;
                     $index++;
                 }
             }
         }
     }
     if (!empty($selections)) {
         $this->connection->insertOnDuplicate($selectionTable, $selections, ['selection_id', 'product_id', 'position', 'is_default', 'selection_price_type', 'selection_price_value', 'selection_qty', 'selection_can_change_qty']);
     }
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:28,代码来源:Bundle.php

示例8: _insertData

 /**
  *  Collected link data insertion.
  *
  * @return $this
  * @throws \Zend_Db_Exception
  */
 protected function _insertData()
 {
     $mainTable = $this->_resource->getTableName('catalog_product_super_attribute');
     $labelTable = $this->_resource->getTableName('catalog_product_super_attribute_label');
     $linkTable = $this->_resource->getTableName('catalog_product_super_link');
     $relationTable = $this->_resource->getTableName('catalog_product_relation');
     $mainData = [];
     foreach ($this->_superAttributesData['attributes'] as $productId => $attributesData) {
         foreach ($attributesData as $attrId => $row) {
             $row['product_id'] = $productId;
             $row['attribute_id'] = $attrId;
             $mainData[] = $row;
         }
     }
     if ($mainData) {
         $this->_connection->insertOnDuplicate($mainTable, $mainData);
     }
     if ($this->_superAttributesData['labels']) {
         $this->_connection->insertOnDuplicate($labelTable, $this->_superAttributesData['labels']);
     }
     if ($this->_superAttributesData['super_link']) {
         $this->_connection->insertOnDuplicate($linkTable, $this->_superAttributesData['super_link']);
     }
     if ($this->_superAttributesData['relation']) {
         $this->_connection->insertOnDuplicate($relationTable, $this->_superAttributesData['relation']);
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:Configurable.php

示例9: updateChangedRecords

 /**
  * @inheritdoc
  */
 public function updateChangedRecords($document, $data)
 {
     return $this->resourceAdapter->insertOnDuplicate($document, $data);
 }
开发者ID:victor-v-rad,项目名称:data-migration-tool,代码行数:7,代码来源:Mysql.php

示例10: _updateProducts

 /**
  * Update product data which related to custom options information
  *
  * @param array $data Product data which will be updated
  * @return $this
  */
 protected function _updateProducts(array $data)
 {
     if ($data) {
         $this->_connection->insertOnDuplicate($this->_tables['catalog_product_entity'], $data, array('has_options', 'required_options', 'updated_at'));
     }
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Option.php

示例11: write

 /**
  * Write single product into flat product table
  *
  * @param int $storeId
  * @param int $productId
  * @param string $valueFieldSuffix
  * @return \Magento\Catalog\Model\Indexer\Product\Flat
  */
 public function write($storeId, $productId, $valueFieldSuffix = '')
 {
     $flatTable = $this->_productIndexerHelper->getFlatTableName($storeId);
     $attributes = $this->_productIndexerHelper->getAttributes();
     $eavAttributes = $this->_productIndexerHelper->getTablesStructure($attributes);
     $updateData = array();
     $describe = $this->_connection->describeTable($flatTable);
     foreach ($eavAttributes as $tableName => $tableColumns) {
         $columnsChunks = array_chunk($tableColumns, self::ATTRIBUTES_CHUNK_SIZE, true);
         foreach ($columnsChunks as $columns) {
             $select = $this->_connection->select();
             $selectValue = $this->_connection->select();
             $keyColumns = array('entity_id' => 'e.entity_id', 'attribute_id' => 't.attribute_id', 'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'));
             if ($tableName != $this->_productIndexerHelper->getTable('catalog_product_entity')) {
                 $valueColumns = array();
                 $ids = array();
                 $select->from(array('e' => $this->_productIndexerHelper->getTable('catalog_product_entity')), $keyColumns);
                 $selectValue->from(array('e' => $this->_productIndexerHelper->getTable('catalog_product_entity')), $keyColumns);
                 /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
                 foreach ($columns as $columnName => $attribute) {
                     if (isset($describe[$columnName])) {
                         $ids[$attribute->getId()] = $columnName;
                     }
                 }
                 $select->joinLeft(array('t' => $tableName), 'e.entity_id = t.entity_id ' . $this->_connection->quoteInto(' AND t.attribute_id IN (?)', array_keys($ids)) . ' AND t.store_id = 0', array())->joinLeft(array('t2' => $tableName), 't.entity_id = t2.entity_id ' . ' AND t.attribute_id = t2.attribute_id  ' . $this->_connection->quoteInto(' AND t2.store_id = ?', $storeId), array())->where('e.entity_id = ' . $productId)->where('t.attribute_id IS NOT NULL');
                 $cursor = $this->_connection->query($select);
                 while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
                     $updateData[$ids[$row['attribute_id']]] = $row['value'];
                     $valueColumnName = $ids[$row['attribute_id']] . $valueFieldSuffix;
                     if (isset($describe[$valueColumnName])) {
                         $valueColumns[$row['value']] = $valueColumnName;
                     }
                 }
                 //Update not simple attributes (eg. dropdown)
                 if (!empty($valueColumns)) {
                     $valueIds = array_keys($valueColumns);
                     $select = $this->_connection->select()->from(array('t' => $this->_productIndexerHelper->getTable('eav_attribute_option_value')), array('t.option_id', 't.value'))->where($this->_connection->quoteInto('t.option_id IN (?)', $valueIds));
                     $cursor = $this->_connection->query($select);
                     while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
                         $valueColumnName = $valueColumns[$row['option_id']];
                         if (isset($describe[$valueColumnName])) {
                             $updateData[$valueColumnName] = $row['value'];
                         }
                     }
                 }
             } else {
                 $columnNames = array_keys($columns);
                 $columnNames[] = 'attribute_set_id';
                 $columnNames[] = 'type_id';
                 $select->from(array('e' => $this->_productIndexerHelper->getTable('catalog_product_entity')), $columnNames)->where('e.entity_id = ' . $productId);
                 $cursor = $this->_connection->query($select);
                 $row = $cursor->fetch(\Zend_Db::FETCH_ASSOC);
                 if (!empty($row)) {
                     foreach ($row as $columnName => $value) {
                         $updateData[$columnName] = $value;
                     }
                 }
             }
         }
     }
     if (!empty($updateData)) {
         $updateData += array('entity_id' => $productId);
         $updateFields = array();
         foreach ($updateData as $key => $value) {
             $updateFields[$key] = $key;
         }
         $this->_connection->insertOnDuplicate($flatTable, $updateData, $updateFields);
     }
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:78,代码来源:Indexer.php


注:本文中的Magento\Framework\DB\Adapter\AdapterInterface::insertOnDuplicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。