當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::getConnection方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\ResourceModel\Product\Collection::getConnection方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::getConnection方法的具體用法?PHP Collection::getConnection怎麽用?PHP Collection::getConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\ResourceModel\Product\Collection的用法示例。


在下文中一共展示了Collection::getConnection方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getProductData

 /**
  * Separate query for product and order data
  *
  * @param array $productIds
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function getProductData(array $productIds)
 {
     $productConnection = $this->productResource->getConnection();
     $productAttrName = $this->productResource->getAttribute('name');
     $productAttrNameId = (int) $productAttrName->getAttributeId();
     $productAttrPrice = $this->productResource->getAttribute('price');
     $productAttrPriceId = (int) $productAttrPrice->getAttributeId();
     $select = clone $this->productResource->getSelect();
     $select->reset();
     $select->from(['main_table' => $this->getTable('catalog_product_entity')])->useStraightJoin(true)->joinInner(['product_name' => $productAttrName->getBackend()->getTable()], 'product_name.entity_id = main_table.entity_id' . ' AND product_name.attribute_id = ' . $productAttrNameId . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, ['name' => 'product_name.value'])->joinInner(['product_price' => $productAttrPrice->getBackend()->getTable()], "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}", ['price' => new \Zend_Db_Expr('product_price.value')])->where('main_table.entity_id IN (?)', $productIds);
     $productData = $productConnection->fetchAssoc($select);
     return $productData;
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:20,代碼來源:Collection.php

示例2: aroundAddFilter

 /**
  * Replace WHERE-filtering by HAVING-filtering.
  *
  * @param \Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject
  * @param \Closure $proceed
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param $field
  * @param null $condition
  */
 public function aroundAddFilter(\Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject, \Closure $proceed, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, $field, $condition = null)
 {
     /* skip identical conditions () */
     $regKey = print_r($condition, true);
     if (!isset($this->_regCond[$regKey])) {
         $conn = $collection->getConnection();
         $select = $collection->getSelect();
         $equation = $this->_repoModifierProductGFrid->getEquationQty();
         $prepared = $conn->prepareSqlCondition($equation, $condition);
         $select->having($prepared);
         $this->_regCond[$regKey] = true;
     }
     return;
 }
開發者ID:praxigento,項目名稱:mobi_mod_mage2_warehouse,代碼行數:23,代碼來源:AddQuantityFilterToCollection.php


注:本文中的Magento\Catalog\Model\ResourceModel\Product\Collection::getConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。