Я использую следующий код, чтобы отобразить категорию и получить товар при нажатии на категорию патента:
<?php
$obj = new Mage_Catalog_Block_Navigation();
$cat = Mage::getModel('catalog/category')->load($obj->getCurrentCategory()->getId()); //get current cat
$subcats = $cat->getChildren(); // Get sub cats
// loop on it
<div class="page-title">
<h1><?php echo $cat['name'];?></h1>
</div>
<div id="accordion2">
<dl class="accordion2" id="slider2">
<?php
function sortCategories($a, $b) {
return strcmp($a['name'], $b['name']);
}
?>
<?php
$categoryArray = array();
foreach(explode(',',$subcats) as $subCatid){ // split up the mage data for use
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()){
$id = $_category->getId();
$caturl = $_category->getURL(); // get link to image
$catname = $_category->getName(); // get the name
$catdesc = $_category->getDescription(); // get the name
if($_category->getImageUrl()){
$catimg = $_category->getImageUrl(); // hey, we got image
}else{
$catimg=null;
continue;
} // this is the basic testing data, format as desired & good luck!
$catdescTwo = substr(strip_tags($catdesc), 0, 70);
$categoryArray[] = array(
'id' => $id,
'name' => $catname,
'url' => $caturl,
'desc' => $catdescTwo,
'img' => $catimg
);
}
}
usort($categoryArray, "sortCategories");
//echo $subcats = $cat->getChildren();
$i=0;
foreach ($categoryArray as $categoryItem) {
$i++;
//print_r($categoryItem);
$catid=$categoryItem['id'];
$catid=$catid;
echo '<dt><h2 class="productbg_'.$i.'">'.$categoryItem['name'].'<span></span></h2></dt>
<dd>';
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //My cat id is 10
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$productid = $product->getId();
$model = Mage::getModel('catalog/product');
$product = $model->load($productid);
//echo $name = $product->getName(); ///Store all th eproduct id in $prdIds array
//echo $product->getImageUrl();
$available = $product->getResource()->getAttribute('available')->getFrontend()->getValue($product);
?>
<ol class="products-list" id="products-list">
<li class="item<?php if( ++$_iterator == sizeof($productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<?php
$strImagePath = '';
$wtImageSize = '';
$wtProdouct = Mage::getModel('catalog/product')->load($product->getId());
$wtProductImages = $wtProdouct->getMediaGalleryImages();
// Loop through all of the images of the current product.
foreach($wtProductImages as $wtImage) {
// If we found one with the label of 'popup', thats the one we want.
if($wtImage->getLabel() == 'popup') {
// Get the image and resize it.
$strImagePath = '/media/catalog/product' . $wtImage->getFile();
$wtImageSize = getimagesize($_SERVER['DOCUMENT_ROOT'] . $strImagePath);
}} ?>
<a href="<?php echo $product->getProductUrl() ?>" class="product-image"><img id="wt-popup-<?php echo $product->getId() ?>" src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(113); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" /></a>
<?php if(!empty($strImagePath)) { ?>
<script defer="defer" type="text/javascript">WT.showPreview("<?php echo $this->htmlEscape($product->getName()) ?>"
, "<?php echo($strImagePath); ?>", "wt-popup-<?php echo $product->getId() ?>", <?php echo $wtImageSize[0] ?>,
<?php echo $wtImageSize[1] ?>);</script><?php } ?>
<?php // Product description ?>
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name"><a href="<?php echo $product->getProductUrl() ?>"><?php echo $name = $product->getName();?> <span> <?php if(isset($available) && $available!=""){?>- AVAILABLE IN <?php echo $available?><?php } ?></span> </a> </h2>
<?php if($product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($product) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($product, true) ?>
<?php if($product->isSaleable()): ?>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<div class="desc std">
<?php echo $product->getShortDescription(); ?>
<a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($product->getName(), null, true) ?>" class="link-more"><?php echo $this->__('Learn More') ?></a>
</div>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</div>
</li>
</ol>
<?php }?>
<?php }
?>
</dl>
</div>
<script type="text/javascript">
var slider2=new accordion.slider("slider2");
slider2.init("slider2","open");
</script>
но при нажатии на изображение товара, URL товара вроде: http://purelygourmets.com/test/index.php/catalog/product/view/id/189/s/ormeaux-et-tacaud-120-g/category/4/
Я хочу правильный URL, например: http://purelygourmets.com/test/index.php/caviar/caviar-accessories/ormeaux-et-tacaud-120-g.html
URL сайта: http://purelygourmets.com/test/index.php/
Спасибо