當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::setOrder方法代碼示例

本文整理匯總了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.');
     }
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:15,代碼來源:CollectionTest.php

示例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;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:16,代碼來源:Collection.php

示例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;
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:16,代碼來源:Collection.php

示例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;
 }
開發者ID:zhangjiachao,項目名稱:magento2,代碼行數:30,代碼來源:Collection.php

示例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;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:16,代碼來源:Collection.php

示例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;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:15,代碼來源:Collection.php

示例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);
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:18,代碼來源:Collection.php


注:本文中的Magento\Catalog\Model\Resource\Product\Collection::setOrder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。