我想在产品的元描述中添加产品价格。我没有在产品选项中编写meta desc,magento从产品desc中获取它。 (对我来说没问题)
$description = $product->getMetaDescription();
if ($description) {
$headBlock->setDescription( ($description) );
} else {
$headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
如何使Meta desc看起来像= ProductDesc Color Only FinalPrice
答案 0 :(得分:0)
请求copyfile view.php app \ code \ core \ Mage \ Catalog \ Block \ Product to app \ code \ local \ Mage \ Catalog \ Block \ Product 在这里找到受保护的函数_prepareLayout() 找到代码并发表评论
$description = $product->getMetaDescription();
if ($description) {
$headBlock->setDescription( ($description) );
} else {
$headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
}
And try below
$Color=$product->getAttributeText('color');
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$currencySymbol = Mage::app()->getLocale()->currency($currentCurrencyCode)->getSymbol();
$price=$currentCurrencyCode .' '.Mage::helper('core')->currency($product->getFinalPrice(),false,true);
$metaTmp1=$Color.' only '. $price;
$strlen=strlen($metaTmp);
$metaTmp2==Mage::helper('core/stri;ng')->substr($product->getDescription(), 0, (255-$strlen-5));
$meta= $metaTmp2.''.$metaTmp1;
$headBlock->setDescription( $meta) ;
答案 1 :(得分:0)
所以我做了:
// $ headBlock-> setDescription(法师::助手( '核心/字符串') - > SUBSTR($产品 - > getDescription(), 0,255)); $颜色= $产品 - > getAttributeText( '颜色'); $ baseCurrencyCode = Mage :: app() - > getStore() - > getBaseCurrencyCode(); $ currentCurrencyCode = Mage :: app() - > getStore() - > getCurrentCurrencyCode(); $ currencySymbol = Mage :: app() - > getLocale() - > currency($ currentCurrencyCode) - > getSymbol(); $ price = $ currentCurrencyCode。' ” .Mage ::助手( '核心') - >货币($产品 - > getFinalPrice(),FALSE,TRUE);
$metaTmp1=$Color.' only '. $price; $strlen=strlen($metaTmp); $metaTmp2==Mage::helper('core/string')->substr($product->getDescription(), 0, (255-$strlen-5)); $meta= $metaTmp2.''.$metaTmp1; $headBlock->setDescription( $meta) ; }
在HTML代码中,在Meta desc中,我只看到f ex“仅123” - 所以仅限价格。
不,我不需要从管理员那里管理它。