本文整理汇总了PHP中Magento\Catalog\Model\ResourceModel\Product\Collection::addAttributeToSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::addAttributeToSelect方法的具体用法?PHP Collection::addAttributeToSelect怎么用?PHP Collection::addAttributeToSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\ResourceModel\Product\Collection
的用法示例。
在下文中一共展示了Collection::addAttributeToSelect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductIdBySku
/**
* Retrieve product ID by sku
*
* @param string $sku
* @return int|null
*/
protected function getProductIdBySku($sku)
{
if (empty($this->productIds)) {
$this->productCollection->addAttributeToSelect('sku');
foreach ($this->productCollection as $product) {
$this->productIds[$product->getSku()] = $product->getId();
}
}
if (isset($this->productIds[$sku])) {
return $this->productIds[$sku];
}
return null;
}
示例2: getItems
/**
* @return array|\Magento\Framework\Data\Collection\AbstractDb
*/
public function getItems()
{
$order = $this->getOrder();
if (!$order) {
return [];
}
$items = $order->getAllVisibleItems();
$productIds = [];
//get the product ids for the collection
foreach ($items as $item) {
$productIds[] = $item->getProductId();
}
$items = $this->productCollection->addAttributeToSelect('*')->addFieldToFilter('entity_id', ['in' => $productIds]);
return $items;
}
示例3: addGlobalAttribute
/**
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @return $this
*/
protected function addGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\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 . '.value';
return $this;
}
示例4: collectValidatedAttributes
/**
* Collect validated attributes
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
* @return $this
*/
public function collectValidatedAttributes($productCollection)
{
$attribute = $this->getAttribute();
if ('category_ids' != $attribute) {
$productCollection->addAttributeToSelect($attribute, 'left');
if ($this->getAttributeObject()->isScopeGlobal()) {
$attributes = $this->getRule()->getCollectedAttributes();
$attributes[$attribute] = true;
$this->getRule()->setCollectedAttributes($attributes);
} else {
$this->_entityAttributeValues = $productCollection->getAllAttributeValues($attribute);
}
}
return $this;
}
示例5: filter
/**
* Filter product collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param \Magento\Catalog\Model\Category $category
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function filter($collection, \Magento\Catalog\Model\Category $category)
{
$collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->setStore($this->storeManager->getStore())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addStoreFilter()->addUrlRewrite()->setVisibility($this->productVisibility->getVisibleInSearchIds())->setOrder('relevance', Select::SQL_DESC);
}
示例6: filter
/**
* Filter product collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param \Magento\Catalog\Model\Category $category
* @return void
*/
public function filter($collection, \Magento\Catalog\Model\Category $category)
{
$collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($category->getId())->setVisibility($this->productVisibility->getVisibleInCatalogIds());
}