想要反转单选按钮栏的值:
现在是magento中的默认情况:
1星=> 6
2星=> 7
3星=> 8
4星=> 9
5星=> 10个
预期定制:
5星=> 10个
4星=> 9
3星=> 8
2星=> 7
1星=> 6个
我试图放arsort
但是徒劳无功。
Code :
路径:Mage / review / Block / 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() ?>"
即:按升序排列(默认):11,12,13,14,15
应该是:15,14,13,12,11。
答案 0 :(得分: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; ?>
我也尝试过这项工作。