mardi 31 mars 2015

Magento random item on homepage

i am new at Magento, and i encountered my first problem. That items will show randomly on homepage.


I have this code:



<?php

$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_items = $_productCollection->getItems();
?>

<?php if ($_collectionSize && $tmpHtml = $this->getChildHtml('block_category_above_collection')): ?>
<div class="block_category_above_collection std"><?php echo $tmpHtml; ?></div>
<?php endif; ?>

<?php if(!$_collectionSize): ?>
<?php if ($tmpHtml = $this->getChildHtml('block_category_above_empty_collection')): ?>
<div class="block_category_above_empty_collection std"><?php echo $tmpHtml; ?></div>
<?php else: ?>


And when is change it to



<?php
$_productCollection=$this->getLoadedProductCollection();
$_collectionSize = $_productCollection->count();
shuffle($_productCollection);


?>


it's showing me fatal error.


I even tried this



<?php
// $_productCollection = $this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setVisibility(array(2,3,4));
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 4);

?>


But nothing helped. What am i doing wrong ?





Aucun commentaire:

Enregistrer un commentaire