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


PHP Resource::getConnection方法代码示例

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


在下文中一共展示了Resource::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConnection

 /**
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 protected function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection('sales_write');
     }
     return $this->connection;
 }
开发者ID:nja78,项目名称:magento2,代码行数:10,代码来源:Attribute.php

示例2: getConnection

 /**
  * Returns connection
  *
  * @return AdapterInterface
  */
 protected function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection($this->connectionName);
     }
     return $this->connection;
 }
开发者ID:nja78,项目名称:magento2,代码行数:12,代码来源:SubSelect.php

示例3: _getWriteConnection

 /**
  * Retrieve write connection instance
  *
  * @return bool|\Magento\Framework\DB\Adapter\AdapterInterface
  */
 protected function _getWriteConnection()
 {
     if (null === $this->_connection) {
         $this->_connection = $this->_resource->getConnection('write');
     }
     return $this->_connection;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:12,代码来源:Observer.php

示例4: loadLogData

 /**
  * Load customer log data by customer id
  *
  * @param int $customerId
  * @return array
  */
 protected function loadLogData($customerId)
 {
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('read');
     $select = $adapter->select()->from(['cl' => $this->resource->getTableName('customer_log')])->joinLeft(['cv' => $this->resource->getTableName('customer_visitor')], 'cv.customer_id = cl.customer_id', ['last_visit_at'])->where('cl.customer_id = ?', $customerId)->order('cv.visitor_id DESC')->limit(1);
     return $adapter->fetchRow($select);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Logger.php

示例5: getConnection

 /**
  * Get connection object
  *
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getConnection()
 {
     if (null === $this->connection) {
         $this->connection = $this->resourceModel->getConnection($this->connectionName);
     }
     return $this->connection;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Setup.php

示例6: buildFilter

 /**
  * {@inheritdoc}
  */
 public function buildFilter(\Magento\Framework\Search\Request\FilterInterface $filter)
 {
     $adapter = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
     /** @var \Magento\Framework\Search\Request\Filter\Term $filter */
     $condition = sprintf('%s = %s', $filter->getField(), $adapter->quote($filter->getValue()));
     return $condition;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:10,代码来源:Term.php

示例7: setUp

 /**
  * @return void
  */
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\Resource');
     $this->adapter = $this->resource->getConnection('core_read');
     $this->reviewCollection = $this->objectManager->create('Magento\\Review\\Model\\Resource\\Review\\Collection');
     $this->reviewResource = $this->objectManager->create('Magento\\Review\\Model\\Resource\\Review');
 }
开发者ID:nja78,项目名称:magento2,代码行数:11,代码来源:ReviewTest.php

示例8: setUp

 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full indexer */
     $this->indexer = $this->objectManager->create('Magento\\CatalogSearch\\Model\\Indexer\\Fulltext\\Action\\Full');
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\Resource');
     $this->adapter = $this->resource->getConnection('core_read');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:8,代码来源:TypeTest.php

示例9: setUp

 public function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\Resource');
     $this->connection = $this->resource->getConnection('core_write');
     $this->model = $this->objectManager->create('Magento\\Framework\\Mview\\View\\Changelog', ['resource' => $this->resource]);
     $this->model->setViewId('test_view_id_1');
     $this->model->create();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:9,代码来源:ChangelogTest.php

示例10: setUp

 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Indexer\Model\IndexerRegistry $indexerRegistry */
     $indexerRegistry = $this->objectManager->create('\\Magento\\Indexer\\Model\\IndexerRegistry');
     $this->indexer = $indexerRegistry->get('catalogsearch_fulltext');
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\Resource');
     $this->adapter = $this->resource->getConnection('core_read');
 }
开发者ID:nja78,项目名称:magento2,代码行数:9,代码来源:TypeTest.php

示例11: move

 /**
  * Move data from temporary tables to flat
  *
  * @param string $flatTable
  * @param string $flatDropName
  * @param string $temporaryFlatTableName
  * @return void
  */
 public function move($flatTable, $flatDropName, $temporaryFlatTableName)
 {
     $connection = $this->_resource->getConnection('write');
     $renameTables = [];
     if ($connection->isTableExists($flatTable)) {
         $renameTables[] = ['oldName' => $flatTable, 'newName' => $flatDropName];
     }
     $renameTables[] = ['oldName' => $temporaryFlatTableName, 'newName' => $flatTable];
     $connection->dropTable($flatDropName);
     $connection->renameTablesBatch($renameTables);
     $connection->dropTable($flatDropName);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:TableData.php

示例12: generateSequences

 /**
  * @param int $n
  * @return void
  */
 public function generateSequences($n = 10)
 {
     $connection = $this->appResource->getConnection('write');
     for ($i = 0; $i < $n; $i++) {
         foreach ($this->entities as $entityName) {
             $sequenceName = $this->appResource->getTableName(sprintf('sequence_%s_%s', $entityName, $i));
             if (!$connection->isTableExists($sequenceName)) {
                 $connection->query($this->ddlSequence->getCreateSequenceDdl($sequenceName));
             }
         }
     }
 }
开发者ID:opexsw,项目名称:magento2,代码行数:16,代码来源:Sequence.php

示例13: storeImage

 /**
  * Save image information to DB.
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $images
  * @return void
  */
 protected function storeImage($product, $images)
 {
     $baseImage = '';
     $i = 1;
     foreach ($images as $image) {
         if (empty($image)) {
             $this->errors[] = $product->getSku();
             continue;
         }
         if (strpos($image, '_main') !== false) {
             $baseImage = $image;
         }
         $id = $this->galleryAttribute->insertGallery(['attribute_id' => $this->mediaAttribute->getAttributeId(), 'entity_id' => $product->getId(), 'value' => $image]);
         $this->galleryAttribute->insertGalleryValueInStore(['value_id' => $id, 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'entity_id' => $product->getId(), 'label' => 'Image', 'position' => $i, 'disables' => 0]);
         $i++;
     }
     if (empty($baseImage)) {
         $baseImage = $images[0];
     }
     if ($baseImage) {
         $imageAttribute = $product->getResource()->getAttribute('image');
         $smallImageAttribute = $product->getResource()->getAttribute('small_image');
         $thumbnailAttribute = $product->getResource()->getAttribute('thumbnail');
         $adapter = $this->resource->getConnection('core');
         foreach ([$imageAttribute, $smallImageAttribute, $thumbnailAttribute] as $attribute) {
             $table = $imageAttribute->getBackend()->getTable();
             /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter*/
             $data = [$attribute->getBackend()->getEntityIdField() => $product->getId(), 'attribute_id' => $attribute->getId(), 'value' => $baseImage];
             $adapter->insertOnDuplicate($table, $data, ['value']);
         }
     }
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:39,代码来源:Gallery.php

示例14: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Tablerate:');
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
     $connection = $this->resource->getConnection('core');
     $fixtureFile = 'OfflineShipping/tablerate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     $regions = $this->loadDirectoryRegions();
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
         try {
             $connection->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
         } catch (\Zend_Db_Statement_Exception $e) {
             if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) {
                 // In case if Sample data was already installed we just skip duplicated records installation
                 continue;
             } else {
                 throw $e;
             }
         }
         $this->logger->logInline('.');
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:31,代码来源:Tablerate.php

示例15: addMatchQueries

 /**
  * @param RequestInterface $request
  * @param MatchContainer[] $matchQueries
  * @param ScoreBuilder $scoreBuilder
  * @param Select $select
  * @param IndexBuilderInterface $indexBuilder
  * @return Select
  * @internal param QueryContainer $queryContainer
  */
 private function addMatchQueries(RequestInterface $request, array $matchQueries, ScoreBuilder $scoreBuilder, Select $select, IndexBuilderInterface $indexBuilder)
 {
     if (!$matchQueries) {
         $select->columns($scoreBuilder->build());
         $select = $this->createAroundSelect($select, $scoreBuilder);
     } elseif (count($matchQueries) === 1) {
         $matchContainer = reset($matchQueries);
         $this->matchBuilder->build($scoreBuilder, $select, $matchContainer->getRequest(), $matchContainer->getConditionType());
         $select->columns($scoreBuilder->build());
         $select = $this->createAroundSelect($select, $scoreBuilder);
     } elseif (count($matchQueries) > 1) {
         $select->columns($scoreBuilder->build());
         $select = $this->createAroundSelect($select, $scoreBuilder);
         $subSelect = $select;
         $select = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE)->select();
         $tables = array_merge(array_keys($matchQueries), ['main_select.relevance']);
         $relevance = implode('.relevance + ', $tables);
         $select->from(['main_select' => $subSelect], [$this->entityMetadata->getEntityId() => 'entity_id', 'relevance' => sprintf('(%s)', $relevance)]);
         foreach ($matchQueries as $matchName => $matchContainer) {
             $matchSelect = $indexBuilder->build($request);
             $matchScoreBuilder = $this->scoreBuilderFactory->create();
             $matchSelect = $this->matchBuilder->build($matchScoreBuilder, $matchSelect, $matchContainer->getRequest(), $matchContainer->getConditionType());
             $matchSelect->columns($matchScoreBuilder->build());
             $select->join([$matchName => $this->createAroundSelect($matchSelect, $scoreBuilder)], $matchName . '.entity_id = main_select.entity_id', []);
         }
     }
     return $select;
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:37,代码来源:Mapper.php


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