當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。