您好我在magento中添加了一个名为附件的新产品关系。
就像我有一个主要产品A和我附加B c和d一样 饰品
现在在前端,我需要将此系列展示为相同的设计 在列表.phtml
所以我决定在列表.phtml上呈现自定义集合
为此我已在_getProductCollection()
以下代码
if($_GET['product_id'])
{
$productid=$_GET['product_id'];
$product = Mage::getModel('catalog/product_link')
->getCollection()
->addFieldToFilter('link_type_id', 6)
->addFieldToFilter('product_id',$productid)
->load();
$LinkedProduct=$product->getData();
foreach($LinkedProduct as $LinkedProducts)
{
$LinkedProductId[]= $LinkedProducts['linked_product_id'];
}
$productIds = array_values($LinkedProductId);
$_productCollection=Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $productIds))
->load();
$this->_productCollection=$_productCollection;
}else{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
}
return $this->_productCollection;
}
The collection is working fine
但问题是排序和工具栏无法正常工作
。你能否建议我如何使用我的自定义集合进行排序和寻呼机
答案 0 :(得分:1)
好的我已经通过在集合中添加排序函数来解决这个问题,如下面的代码
$productid=$_GET['product_id'];
$product = Mage::getModel('catalog/product_link')
->getCollection()
->addFieldToFilter('link_type_id', 6)
->addFieldToFilter('product_id',$productid)
->load();
$LinkedProduct=$product->getData();
foreach($LinkedProduct as $LinkedProducts)
{
$LinkedProductId[]= $LinkedProducts['linked_product_id'];
}
$productIds = array_values($LinkedProductId);
$_productCollection=Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $productIds))
->addAttributeToSort($_GET['order'],$_GET['dir'] )
->setPageSize($_GET['limit'])
->load();
echo $_productCollection->getSelect() ;
$this->_productCollection=$_productCollection;
排序无效,因为在集合中没有添加排序功能
->addAttributeToSort($_GET['order'],$_GET['dir'] )
->setPageSize($_GET['limit'])
现在它工作正常。
感谢