本文整理汇总了PHP中Magento\Catalog\Model\Resource\Product\Collection::setOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setOrder方法的具体用法?PHP Collection::setOrder怎么用?PHP Collection::setOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Resource\Product\Collection
的用法示例。
在下文中一共展示了Collection::setOrder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.');
}
}
示例2: 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;
}
示例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 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;
}
示例5: setOrder
/**
* Set Order field
*
* @param string $attribute
* @param string $dir
* @return $this
*/
public function setOrder($attribute, $dir = 'desc')
{
if ($attribute == 'relevance') {
$this->getSelect()->order("relevance {$dir}");
} else {
parent::setOrder($attribute, $dir);
}
return $this;
}
示例6: 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;
}
示例7: 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);
}