2012-04-26 16 views
3

Magento 1.5.1で次のコードを使って製品を作成しようとしました。製品はデータベースに保存されていますが、バックエンド製品のグリッドには表示されません。商品ビューのURLを呼び出すと、名前、説明(NOKを参照)のように、一部のフィールドが入力されません。Magento - プログラムで保存された製品がバックエンドに表示されない

$product = Mage::getModel('catalog/product'); 

$product->setSku("ABC123") // OK 
    ->setName("Type 7 Widget") // NOK 
    ->setDescription("This widget will give you years of trouble-free widgeting.") // NOK 
    ->setShortDescription("High-end widget.") // NOK 
    ->setPrice(70.50) // OK 
    ->setTypeId('simple') // OK 
    ->setAttributeSetId('14') // need to look this up // OK 
    ->setCategoryIds("3,7") // need to look these up // OK 
    ->setWeight(1.0) // OK 
    ->setTaxClassId(1) //taxable goods // ? 
    ->setVisibility(4) // catalog, search // NOK 
    ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED); // enabled // NOK 

$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); 

$product->save(); 

これは、すべてのヘルプは素晴らしいことだprint_r($product->debug());

[type_id] => simple 
[sku] => ABC123 
[has_options] => 0 
[required_options] => 0 
[created_at] => 2012-04-26 12:57:22 
[updated_at] => 2012-04-26 12:57:22 
[weight] => 1 
[url_path] => .html 
[price] => 70.5000 
[enable_googlecheckout] => 1 
[name] => Type 7 Widget 
[meta_title] => Type 7 Widget 
[meta_description] => Type 7 Widget, Fotos 
[url_key] => type-7-widget 
[options_container] => container2 
[delivery_time] => 2-3 Tage 
[generate_meta] => 0 
[status] => 1 
[tax_class_id] => 1 
[visibility] => 4 
[description] => This widget will give you years of trouble-free widgeting. 
[short_description] => High-end widget. 
[meta_keyword] => Type 7 Widget, Fotos 
[media_gallery] => Array 
    (
     [images] => Array 
      (
      ) 

     [values] => Array 
      (
      ) 

    ) 

[tier_price] => Array 
    (
    ) 

[tier_price_changed] => 0 
[stock_item (Mage_CatalogInventory_Model_Stock_Item)] => Array 
    (
     [product_id] => 158 
     [product_name] => Type 7 Widget 
     [store_id] => 1 
     [product_type_id] => simple 
     [product_status_changed] => 1 
    ) 

[is_in_stock] => 1 
[is_salable] => 1 
) 

データベースに保存され、製品です!


ソリューション

次のコードでのための製品を保存したい店舗を指定します。

Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); 

答えて

3

は多店舗のセットアップの場合はウェブサイトを設定することを忘れないでください。

+0

'$ product-> setWebsiteIds(array( '1'));'を意味しますか?私もそれを忘れてしまった。上記のコードは完全ではありません。 – tecmec

+0

ここで、Mage :: app() - > setCurrentStore(Mage :: getModel( 'core/store') - > load(Mage_Core_Model_App :: ADMIN_STORE_ID));すべてがうまくいきました。ありがとう! – tecmec

3

あなたが製品を保存しないでください。

追加:

try{ 
    $product->save(); 
} catch (Exception $e) { 
    echo $e->getMessage(); 
} 
+1

私はちょうどそれをコピーすることを忘れて、thx。 – tecmec

関連する問題