在哪里可以找到在 PHP 中创建 BundleProducts 的完整且有效的示例?我正在使用 Magento 1.7
谷歌只给我片段
编辑:
直到现在我在这段代码中,但保存抛出
致命错误:在第 73 行的 \app\code\core\Mage\Bundle\Model\Selection.php 中的非对象上调用成员函数 getStoreId()
-
---删除了旧代码--
编辑 2 好的,注册产品后异常已经消失,我的捆绑包出现在后端,但捆绑包项目没有出现在管理面板中
$items = array();
$selections = array ();
$items[] = array(
'title' => '',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 'true',
'position' => 0,
);
$items[] = array(
'title' => '',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 'true',
'position' => 0,
);
$selection = array();
$selection[] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => '2',
'delete' => '',
'selection_price_value' => '',
'selection_price_type' => '0',
'selection_qty' => '1',
'selection_can_change_qty' => '0',
'position' => '0',
'is_default' => '1',
);
$selections[] = $selection;
$selection = array();
$selection[] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => '3',
'delete' => '',
'selection_price_value' => '',
'selection_price_type' => '0',
'selection_qty' => '1',
'selection_can_change_qty' => '0',
'position' => '0',
'is_default' => '1',
);
$selections[] = $selection;
$storeID = 1;
$websiteIDs = array(1);
$product = Mage::getModel('catalog/product');
$p = array(
'sku_type' => 0,
'sku' => '123321',
'name' => "BarProduct",
'description' => 'Foo',
'short_description' => 'Bar',
'type_id' => 'bundle',
'attribute_set_id' => 4,
'weight_type' => 0,
'visibility' => 4,
'price_type' => 0,
'price_view' => 0,
'status' => 1,
'created_at' => strtotime('now'),
'category_ids' => $cats,
'store_id' => $storeID,
'website_ids' => $websiteIDs
);
$product->setData($p);
Mage::register('product', $product);
Mage::register('current_product', $product);
$product->setBundleOptionsData($items);
$product->setBundleSelectionsData($selections);
$product->setCanSaveBundleSelections(true);
$product->setCanSaveConfigurableAttributes(false);
$product->setAffectBundleProductSelections(true);
$product->setCanSaveCustomOptions(true);
$product->save();