1
我試圖編寫一個在數據庫中添加產品的腳本。它是一個magento網站。我試圖創建一個獨立的頁面(example.com/import.php)幷包含magento框架,以便我可以使用magento目錄模型來添加產品。到目前爲止,我試過這個,並得到了致命的錯誤:在magento中創建獨立頁面
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
任何幫助,高度讚賞。謝謝!
已更新:
這就是我最後的結果。完美的作品。感謝Ram Sharma。
error_reporting(E_ALL^E_NOTICE);
include 'app/Mage.php';
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('default');
Mage::register('isSecureArea', 1);
$product = new Mage_Catalog_Model_Product();
$product->setSku('some-sku-value-here');
$product->setAttributeSetId('9');# 9 is for default
$product->setTypeId('simple');
$product->setName('Some cool product name');
$product->setCategoryIds(array(42)); # some cat id's,
$product->setWebsiteIDs(array(1)); # Website id, 1 is default
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');
$product->setPrice(39.99); # Set some price
$product->setWeight(4.0000);
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$product->setStatus(1);
$product->setTaxClassId(0); # default tax class
$product->setStockData(array(
'is_in_stock' => 1,
'qty' => 99999
));
$product->setCreatedAt(strtotime('now'));
try {
$product->save();
}
catch (Exception $ex) {
}
感謝更新ininial崗位。這很有幫助。 (我想強調默認屬性設置ID是4,而不是9) –