Php 向magento中的特色产品添加排序顺序
我使用下面的代码允许用户设置将显示在主页上的特色产品,但我需要扩展它,以便他们也可以指定项目的排序顺序。默认情况下,它按产品添加到Magento的顺序显示产品 为此,我创建了一个名为“sort_order”的属性,允许用户添加一个数值,当显示在主页上时,该数值将指示排序顺序。例如,如果我有4种产品,那么排序顺序可以如下所示 产品1-排序顺序3 产品2-排序顺序1 产品3-分类顺序2 产品4-排序顺序4 我整个上午都在努力让它工作。我假设我需要创建一个数组,它允许我按照属性“sort_order”的指示订购产品,但我什么也做不到 如果有人能给我一些建议,我将不胜感激Php 向magento中的特色产品添加排序顺序,php,magento,e-commerce,Php,Magento,E Commerce,我使用下面的代码允许用户设置将显示在主页上的特色产品,但我需要扩展它,以便他们也可以指定项目的排序顺序。默认情况下,它按产品添加到Magento的顺序显示产品 为此,我创建了一个名为“sort_order”的属性,允许用户添加一个数值,当显示在主页上时,该数值将指示排序顺序。例如,如果我有4种产品,那么排序顺序可以如下所示 产品1-排序顺序3 产品2-排序顺序1 产品3-分类顺序2 产品4-排序顺序4 我整个上午都在努力让它工作。我假设我需要创建一个数组,它允许我按照属性“sort_order”
<div id="home-featured">
<h2><?php echo $this->__('Featured') ?></h2>
<?php
// some helpers
$_helper = $this->helper('catalog/output');
$storeId = Mage::app()->getStore()->getId();
$catalog = $this->getLayout()->createBlock('catalog/product_list')->setStoreId($storeId);
// get all products that are marked as featured
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('featured_product');
$collection->addFieldToFilter(array(
array('attribute' => 'featured_product', 'eq' => true),
));
// if no products are currently featured, display some text
if (!$collection->count()) :
?>
<p class="note-msg"><?php echo $this->__('There are no featured products at the moment.') ?></p>
<?php else : ?>
<div class="category-products">
<?php
$_collectionSize = $collection->count();
$_columnCount = 4;
$i = 0;
foreach ($collection as $_product) :
$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($_product->getId());
?>
<article>
<div class="product-image"><a href="<?php echo Mage::helper('fullurl')->getFullProductUrl($_product); ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize(170); ?>" width="170" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a></div>
<div class="featured-info">
<h3><a href="<?php echo Mage::helper('fullurl')->getFullProductUrl($_product); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h3>
<p><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description ') ?></p>
<span class="link-dreambuilder"><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" ><?php echo $this->__('+ Add to Dream Builder') ?></a></span> </div>
</article>
<?php endforeach ?>
</div>
<?php endif ?>
</div>
无论如何,这里是属性排序函数
addAttributeToSort($attribute, $dir='asc');
无论如何,这里是属性排序函数
addAttributeToSort($attribute, $dir='asc');
您的排序功能在哪里?我在上面没有看到…你的排序函数在哪里?我在上面没有看到。。。