我寫了一個代碼來添加sku的產品說明。現在腳本工作正常,但所有格式似乎都丟失了,因爲在csv中,添加到產品的描述是部分的(似乎它在任何特殊字符後刪除字符串)。將說明添加到產品表單csv文件
我的代碼:
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if (($handle = fopen("Witedescriptions.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$desc =$data[1];
$sku = $data[2];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$product->setDescription($desc);
$product->save();
}
fclose($handle);
}
的CSV文件struture
Sno. , Description , Sku
上描述
Test this is dummy data abd’s base is of a slim yellow gold halo that easily fits on a finger.
list here
• list 1
• list 2
當我運行的腳本樣本數據,產品具有以下唯一的數據:
Test this is dummy data abd
它似乎有逃避一些字符我試圖用我的descrition設置爲「黃金的價格在美國」,但在管理產品,我剛剛拿到「金牌」
我測試你的代碼,並解析CSV文件,並獲取值時,有沒有問題。問題應該在這裏:'$ product-> setDescription($ desc);',所以看看這個函數。我想你需要從描述中刪除/替換有問題的字符,然後將其存儲到數據庫中。 –
它只是的東西無法找到爲什麼即使添加addslahes不起作用 – gaurav