令我完全沮丧的是,我似乎无法获得以下代码来提供我正在寻找的结果。
以下代码提供的网址如下所示......
mywebsite.co.uk/catalog/product/view/id/5980/s/classic-army-ca063m-stoner-lmg-aeg/category/263 /
我寻求的理想结果将与此更加协调......
mywebsite.co.uk/classic-army-ca063m-stoner-lmg-aeg.html
或者这......
mywebsite.co.uk/aegs/classic-army-ca063m-stoner-lmg-aeg.html
我花了不少时间,我不敢说,阅读和尝试替代代码建议,但这个疲惫不堪的老山羊只是无法弄明白。因此,如果有人能伸出善意之手并向我展示我的方式的错误,我将非常感激。
public function _construct() {
parent::_construct();
$this->_init('pticker/pticker');
}
public function fetchProducts() {
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addFieldToFilter(array
(array('attribute' => 'Status', 'eq' => '1'),
));
$_productCollection->addFieldToFilter(array
(array('attribute' => 'appearinticker', 'eq' => '1'),
));
$product = array();
$linkText= Mage::getStoreConfig('pticker/color/linktext');
if($linkText == ''){$linkText = 100;}
if (count($_productCollection) > 0) {
$count = 0;
$i = 0;
foreach ($_productCollection as $_product) {
$model = Mage::getModel('catalog/product');
$_product = $model->load($_product->getId());
$title= $_product->getTickertitle();
if($title == ''){$title = $_product->getName();}
if(strlen($title) > $linkText){
$title = substr($title,0, $linkText);
$title .= '...';
}
$product[$i]['title'] = htmlspecialchars($title);
$product[$i]['link'] = $model->getProductUrl();
$i++;
}
}
// print_r($product);
return $product;
}
答案 0 :(得分:0)
<?php
$_productCollection->addFieldToFilter(array
(array('attribute' => 'appearinticker', 'eq' => '1'),
));
//add below line after product collection filter to rewrite URL .
$_productCollection->addUrlRewrite();