====== Home Page - Block Homepage ====== Aquest codi es troba extret de: [[http://www.magentocommerce.com/boards/viewthread/4454/| ways to show products at the home page]] i millorat a [[http://www.magentocommerce.com/boards/viewthread/4454/P165/#t73071/|Update code post Dan_w, joined: 2008-01-04. ]] ===== Els atributs ===== La gestió de productes si es troben al home o no, es gestionarà com a atributs. Per crear els atributs anem: Catalog -> Attributes -> Manage Attributes Crearem un nou atribut: * home_page_featured * Scope: Global Associarem aquest atribut a Catalog -> Attributes -> Manage Attribute Sets => default ===== Els fitxers ===== Agreguem el fitxer: * Homepage.php (app/code/core/Mage/Catalog/Block/Product/) * homepage.phtml (app/design/frontend/[your package]/[your theme]/template/catalog/product/) ==== Homepage.php ==== getStore()->getId(); $product = Mage::getModel('catalog/product'); Mage::register('product', $product); /* @var $product Mage_Catalog_Model_Product */ $todayDate = $product->getResource()->formatDate(time()); $products = $product->setStoreId($storeId)->getCollection() ->addAttributeToFilter('home_page_featured', array('yes'=>true)) ->addAttributeToSelect(array('name', 'price', 'small_image','short_description'), 'inner') ->addAttributeToSelect(array('special_price', 'special_from_date', 'special_to_date'), 'left') ; /* @var $products Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); $products->setOrder('hot_deals')->setPageSize(5)->setCurPage(1); $this->setProductCollection($products); } } ==== Homepage.phtml ==== getProductCollection()) && $_products->getSize()): ?>
getItems() as $_product): ?> 3): continue; endif; ?> "; if($row == 1) { $row = 0; echo ''; } else { $row = 1; echo ''; } $j = 0; } else { $j++; } ?>  "; ?>
<?php echo $this->htmlEscape($_product->getName()) ?>

getName() ?>

getShortDescription(); ?> getPriceHtml($_product, true) ?>