【问题标题】:Magento add price and color in meta descriptionMagento 在元描述中添加价格和颜色
【发布时间】:2014-03-10 02:05:50
【问题描述】:

我想在产品的元描述中添加产品价格。我不在产品选项中编写元描述,magento 从产品描述中获取它。 (对我来说没关系)

$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

?

【问题讨论】:

  • 你想在后台显示还是在前端显示???
  • 你想从管理员管理

标签: magento meta


【解决方案1】:

请复制文件 view.php app\code\core\Mage\Catalog\Block\Product 到 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) ;

【讨论】:

    【解决方案2】:

    所以我做到了:

    //$headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255)); $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/string')->substr($product->getDescription(),
            0, (255-$strlen-5));
            $meta= $metaTmp2.''.$metaTmp1;
            $headBlock->setDescription( $meta) ;                   }
    

    在 HTML 代码中,在 Meta desc 中,我只看到 f ex“只有 123”——所以只有价格。

    不,我不需要从管理员管理它。

    【讨论】:

      猜你喜欢
      • 2017-02-14
      • 1970-01-01
      • 2023-03-16
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多