我有一些magento产品,产品描述不正确。
示例:"This text has some mistakes."
如您所见,文本使用
作为占位符。我想用真正的占位符替换每个
。
我想写一个php脚本,它将从数据库加载描述,修复文本然后保存。
你知道我怎么做吗?
谢谢!
答案 0 :(得分:0)
您可以使用str_replace
。
在magento根文件夹中创建一个文件Updatedesc.php
,然后在该文件中写下以下代码,然后使用以下网址http://www.yourdomain.com/Updatedesc.php
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$_productCollection = Mage::getModel('catalog/product')
->getCollection()->addAttributeToSelect('*');
foreach($_productCollection as $_product)
{
try
{
$description = $_product->getDescription();
$newDescription = str_replace(" ","|", $description);
$_productCollection->setDescription($newDescription);
$_productCollection->save();
}
catch(Exception $e){
echo $e->getMessage();
}
}
答案 1 :(得分:0)
谢谢你的帮助!我不明白这是做什么的:$_productCollection->setStoreId(2);
我想更改每个产品的描述,所以我需要添加一个foreach。
我想出了这个:
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product){
$description = $_product->getDescription();
$newDescription = str_replace(" ","|", $description);
$_productCollection->setDescription($newDescription);
$_productCollection->save();
}