本文整理匯總了PHP中Magento\Catalog\Model\ResourceModel\Product\Collection::setOrder方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::setOrder方法的具體用法?PHP Collection::setOrder怎麽用?PHP Collection::setOrder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Catalog\Model\ResourceModel\Product\Collection
的用法示例。
在下文中一共展示了Collection::setOrder方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setOrder
/**
* Add sorting
*
* @param string $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
{
if ($attribute == 'purchases' || $attribute == 'downloads' || $attribute == 'link_title') {
$this->getSelect()->order($attribute . ' ' . $dir);
} else {
parent::setOrder($attribute, $dir);
}
return $this;
}
示例2: setOrder
/**
* Set Order field
*
* @param string $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = Select::SQL_DESC)
{
$this->order = ['field' => $attribute, 'dir' => $dir];
if ($attribute != 'relevance') {
parent::setOrder($attribute, $dir);
}
return $this;
}
示例3: setOrder
/**
* Set order
*
* @param string $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
{
if (in_array($attribute, ['carts'])) {
$this->getSelect()->order($attribute . ' ' . $dir);
} else {
parent::setOrder($attribute, $dir);
}
return $this;
}
示例4: setOrder
/**
* Set sorting order
*
* $attribute can also be an array of attributes
*
* @param string|array $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = self::SORT_ORDER_ASC)
{
if ($attribute == 'position') {
return $this->setPositionOrder($dir);
} elseif ($attribute == 'attribute_set_id') {
return $this->setAttributeSetIdOrder($dir);
}
return parent::setOrder($attribute, $dir);
}
示例5: setOrder
/**
* Set order to attribute
*
* @param string $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = 'DESC')
{
switch ($attribute) {
case 'rt.review_id':
case 'rt.created_at':
case 'rt.status_id':
case 'rdt.title':
case 'rdt.nickname':
case 'rdt.detail':
$this->getSelect()->order($attribute . ' ' . $dir);
break;
case 'stores':
// No way to sort
break;
case 'type':
$this->getSelect()->order('rdt.customer_id ' . $dir);
break;
default:
parent::setOrder($attribute, $dir);
break;
}
return $this;
}