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


PHP Collection::getSelect方法代码示例

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


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

示例1: testSetOrder

 /**
  * @dataProvider setOrderDataProvider
  */
 public function testSetOrder($order, $expectedOrder)
 {
     $this->_collection->setOrder($order);
     $this->_collection->load();
     // perform real SQL query
     $selectOrder = $this->_collection->getSelect()->getPart(\Zend_Db_Select::ORDER);
     foreach ($expectedOrder as $field) {
         $orderBy = array_shift($selectOrder);
         $this->assertArrayHasKey(0, $orderBy);
         $this->assertTrue(false !== strpos($orderBy[0], $field), 'Ordering by same column more than once is restricted by multiple RDBMS requirements.');
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:CollectionTest.php

示例2: addExcludeProductFilter

 /**
  * Make collection not to load products that are in specified quote
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $quoteId
  * @return $this
  */
 public function addExcludeProductFilter($collection, $quoteId)
 {
     $adapter = $this->_getReadAdapter();
     $exclusionSelect = $adapter->select()->from($this->getTable('sales_flat_quote_item'), array('product_id'))->where('quote_id = ?', $quoteId);
     $condition = $adapter->prepareSqlCondition('e.entity_id', array('nin' => $exclusionSelect));
     $collection->getSelect()->where($condition);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:Cart.php

示例3: 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('read');
     $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:nja78,项目名称:magento2,代码行数:20,代码来源:Collection.php

示例4: addIsInStockFilterToCollection

 /**
  * Add only is in stock products filter to product collection
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @return $this
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = $this->_storeManager->getStore($collection->getStoreId())->getWebsiteId();
     $joinCondition = $this->_getReadAdapter()->quoteInto('e.entity_id = stock_status_index.product_id' . ' AND stock_status_index.website_id = ?', $websiteId);
     $joinCondition .= $this->_getReadAdapter()->quoteInto(' AND stock_status_index.stock_id = ?', Stock::DEFAULT_STOCK_ID);
     $collection->getSelect()->join(array('stock_status_index' => $this->getMainTable()), $joinCondition, array())->where('stock_status_index.stock_status=?', Stock\Status::STATUS_IN_STOCK);
     return $this;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:14,代码来源:Status.php

示例5: addLowStockFilter

 /**
  * Add low stock filter to product collection
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param array $fields
  * @return $this
  */
 public function addLowStockFilter(\Magento\Catalog\Model\Resource\Product\Collection $collection, $fields)
 {
     $this->_initConfig();
     $adapter = $collection->getSelect()->getAdapter();
     $qtyIf = $adapter->getCheckSql('invtr.use_config_notify_stock_qty > 0', $this->_configNotifyStockQty, 'invtr.notify_stock_qty');
     $conditions = [[$adapter->prepareSqlCondition('invtr.use_config_manage_stock', 1), $adapter->prepareSqlCondition($this->_isConfigManageStock, 1), $adapter->prepareSqlCondition('invtr.qty', ['lt' => $qtyIf])], [$adapter->prepareSqlCondition('invtr.use_config_manage_stock', 0), $adapter->prepareSqlCondition('invtr.manage_stock', 1)]];
     $where = [];
     foreach ($conditions as $k => $part) {
         $where[$k] = join(' ' . \Zend_Db_Select::SQL_AND . ' ', $part);
     }
     $where = $adapter->prepareSqlCondition('invtr.low_stock_date', ['notnull' => true]) . ' ' . \Zend_Db_Select::SQL_AND . ' ((' . join(') ' . \Zend_Db_Select::SQL_OR . ' (', $where) . '))';
     $collection->joinTable(['invtr' => 'cataloginventory_stock_item'], 'product_id = entity_id', $fields, $where);
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:Stock.php

示例6: addGlobalAttribute

 /**
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @return $this
  */
 protected function addGlobalAttribute(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Resource\Product\Collection $collection)
 {
     $storeId = $this->storeManager->getStore()->getId();
     switch ($attribute->getBackendType()) {
         case 'decimal':
         case 'datetime':
         case 'int':
             $alias = 'at_' . $attribute->getAttributeCode();
             $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
             break;
         default:
             $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
             $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []);
     }
     $this->joinedAttributes[$attribute->getAttributeCode()] = $alias;
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:22,代码来源:Product.php


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