2011-06-20 89 views
0

我用下面的代碼來顯示類,有產品。點擊專利類別:產品網址問題?

<?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> 

但是當點擊同類產品的形象,產品的網址:HTTP://purelygourmets.com/test/index。 php/catalog/product/view/id/189/s/ormeaux-et-tacaud-120-g/category/4/

我想要正確的網址,例如:http://purelygourmets.com/test/index。 php/caviar /魚子醬配件/ ormeaux-et-tacaud-120-g.html

網址:http://purelygourmets.com/test/index.php/

謝謝

回答

0

我還在學習Magento自己,但你有沒有嘗試過$ product-> getUrlPath();?

+0

感謝jmspldnl其工作正常 –

0

嘗試從後端系統 - > Condifuration->基於Web>搜索引擎優化SEO使URL,並從系統 - >配置 - >目錄 - >搜索引擎優化

0
// Store root cat 
$root_cat = Mage::app()->getStore()->getRootCategoryId(); 
$category_model = Mage::getModel('catalog/category'); 
$_category = $category_model->load($root_cat); // Load category model 
$all_child_categories = $category_model->getResource()->getAllChildren($_category); // Get all children IDs 
// Search product category IDS (all stores) for only current store IDs 
$prod_cat_result = array_intersect($all_child_categories, $_product->getCategoryIds()); 
$prod_cat_result = array_values($prod_cat_result); // Reset array index 
$_category = Mage::getModel('catalog/category')->load($prod_cat_result[0]); 
echo "/".$_product->getUrlPath($_category); 

此配置的產品和類別網址將返回完整商品網址,但請注意,如果您的商品分配給了多個類別,它將返回上面的類別/商品數組搜索中匹配的第一個商品的類別網址。

希望這會有所幫助。 乾杯