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


PHP Collection::getAttribute方法代码示例

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


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

示例1: prepareForProductsInCarts

 /**
  * Prepare select query for products in carts report
  *
  * @return $this
  */
 public function prepareForProductsInCarts()
 {
     $productAttrName = $this->_productResource->getAttribute('name');
     $productAttrNameId = (int) $productAttrName->getAttributeId();
     $productAttrNameTable = $productAttrName->getBackend()->getTable();
     $productAttrPrice = $this->_productResource->getAttribute('price');
     $productAttrPriceId = (int) $productAttrPrice->getAttributeId();
     $productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
     $this->getSelect()->useStraightJoin(true)->reset(\Zend_Db_Select::COLUMNS)->joinInner(['quote_items' => $this->getTable('quote_item')], 'quote_items.quote_id = main_table.entity_id', null)->joinInner(['e' => $this->getTable('catalog_product_entity')], 'e.entity_id = quote_items.product_id', null)->joinInner(['product_name' => $productAttrNameTable], 'product_name.entity_id = e.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' => $productAttrPriceTable], "product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}", ['price' => new \Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')])->joinLeft(['order_items' => new \Zend_Db_Expr(sprintf('(%s)', $this->getOrdersSubSelect()))], 'order_items.product_id = e.entity_id', [])->columns('e.*')->columns(['carts' => new \Zend_Db_Expr('COUNT(quote_items.item_id)')])->columns('order_items.orders')->where('main_table.is_active = ?', 1)->group('quote_items.product_id');
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:Collection.php

示例2: 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


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