gpt4 book ai didi

Magento - 以编程方式保存的产品在后端不可见

转载 作者:行者123 更新时间:2023-12-04 10:53:22 25 4
gpt4 key购买 nike

我尝试在 Magento 1.5.1 上使用以下代码创建产品。该产品已保存在数据库中,但未出现在后端产品网格中。如果我调用产品 View url,某些字段未填写,例如:名称、说明(请参阅:NOK)。

$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));

最佳答案

不要忘记在多商店设置的情况下设置网站。

关于Magento - 以编程方式保存的产品在后端不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com