2013-04-17 75 views
0

要扭轉單選按鈕字段的值:
Magento的定製評分單選按鈕

現在在Magento缺省情況:
1星=> 6
2星級=> 7
3星=> 8
4星級=> 9
5星級=> 10

預期定製
5星級=> 10
4星級=> 9
3星級=> 8
2星級=> 7
1星=> 6

我試圖把arsort但在徒勞的。

Code : 

路徑:法師/審查/座/ form.php的

public function getRatings() 
    { 
     $ratingCollection = Mage::getModel('rating/rating') 
      ->getResourceCollection() 
      ->addEntityFilter('product') 
      ->setPositionOrder() 
      ->addRatingPerStoreName(Mage::app()->getStore()->getId()) 
      ->setStoreFilter(Mage::app()->getStore()->getId()) 
      ->load() 
      ->addOptionToItems(); 
     return $ratingCollection; 
    } 

路徑:form.phtml(模板文件的代碼)

<?php foreach ($this->getRatings() as $_rating): ?> 
         <tr> 
          <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th> 
         <?php foreach ($_rating->getOptions() as $_option): ?> 
          <td class="value"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></td> 
         <?php endforeach; ?> 
         </tr> 
        <?php endforeach; ?> 

自帶的價值單選按鈕:value="<?php echo $_option->getId() ?>" ie:按升序排列(默認):11,12,13,14,15
應該來:15,14,13,12,11。

+0

請貼出相關代碼 – billyonecan

+0

@billyonecan:添加了更新的部分。 –

回答

0

有一個PHP函數array_reverse()來反轉評級數組。 這將是你最後的結果:

<?php foreach ($this->getRatings() as $_rating): ?> 
    <tr> 
     <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th> 
     <?php foreach (array_reverse($_rating->getOptions()) as $_option): ?> 
      <td class="value"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></td> 
     <?php endforeach; ?> 
    </tr> 
<?php endforeach; ?> 

我也試着和做這項工作。