使用简单项目的SKU/ID以编程方式在Magento中添加Bundle产品
我在Magento中有一些简单的目录产品,所以我有他们的SKU & ID。现在我想使用捆绑项目的数组元素“bundle_options”&“bundle_selections”来创建一个Bundle产品,它在其Observer类中被Magento Admin编码使用。使用简单项目的SKU/ID以编程方式在Magento中添加Bundle产品
同样在Observer类中,有两个函数“setBundleOptionsData()
”&“setBundleSelectionsData()
”的方法调用,我无法找到任何函数定义。
请任何专业的职位在这里,因为我需要一些正确的方式来做这件事。如果需要,覆盖模块或使用事件,我会这样做,但我需要非常专业的帮助。 在此先感谢。
编辑: -
关于上面提到的两种方法“setBundleOptionsData()
” &“setBundleSelectionsData()
”,有什么我几乎可以肯定的是,他们正在使用某种形式的PHP魔术方法,但我不知道在哪里这些魔术方法的主要逻辑是写成的?
请有人提供一些正确的答案。任何帮助是极大的赞赏。
我没有使用任何Web服务。我已经简单地采用下述方法专门用于捆绑的产品,这是指: -
- setBundleOptionsData()
- setBundleSelectionsData()
- setCanSaveBundleSelections(真)
对于第一种方法,Bundle选项的细节作为数组形式的参数提供给方法。同样,对于第二种方法“setBundleSelectionsData()”,我们将以数组形式的参数的方式将Bundle Selections的细节提供给此方法。
这是在Magento中添加任何捆绑产品的主要逻辑。 希望这有助于任何新手!
请检查this link了解更多有关捆绑产品创建的更多信息。
$MyOptions[0] = array (
'title' => 'My Bad','default_title' => 'My Bad',
'delete' => '',
'type' => 'radio',
'required' => 0,
'position' => 0
);
或
$ optionModel =法师:: getModel( '束/选项') - > addSelection( 'op111') - >的setTitle( 'op111') - > setDefaultTitle(” ($ product-> getStoreId()); - > setStoreId($ product-> getStoreId()); $ optionModel-> save();
感谢哥们,你的第二个解决方案为我工作。 – 2012-12-06 04:15:08
正吃力的时间与此,却发现这个让我渡过了难关:
$items[] = array(
'title' => 'test title',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 1,
'position' => 0);
$selections = array();
$selectionRawData[] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => '159',
'delete' => '',
'selection_price_value' => '10',
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0);
$selections[] = $selectionRawData;
$productId = 182;
$product = Mage::getModel('catalog/product')
->setStoreId(0);
if ($productId) {
$product->load($productId);
}
Mage::register('product', $product);
Mage::register('current_product', $product);
$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);
$product->setBundleOptionsData($items);
$product->setBundleSelectionsData($selections);
$product->setCanSaveCustomOptions(true);
$product->setCanSaveBundleSelections(true);
$product->save();
具体来说,
Mage::register('product', $product);
Mage::register('current_product', $product);
是关键
编辑:: 在尝试添加多个选项/选项时,看起来还有一点特殊之处。该setBundleOptionsData需要一个阵列的选择,即
Array(
[1] => Array
(
[title] => Option 2
[option_id] =>
[delete] =>
[type] => select
[required] => 1
[position] =>
)
[0] => Array
(
[title] => Option 1
[option_id] =>
[delete] =>
[type] => select
[required] => 1
[position] =>
))
然后是选择将与对应的选项数组的索引选择一个数组的数组:
Array(
[1] => Array
(
[2] => Array
(
[selection_id] =>
[option_id] =>
[product_id] => 133
[delete] =>
[selection_price_value] => 0.00
[selection_price_type] => 0
[selection_qty] => 1
[selection_can_change_qty] => 1
[position] => 0
)
[3] => Array
(
[selection_id] =>
[option_id] =>
[product_id] => 132
[delete] =>
[selection_price_value] => 0.00
[selection_price_type] => 0
[selection_qty] => 1
[selection_can_change_qty] => 1
[position] => 0
)
)
[0] => Array
(
[0] => Array
(
[selection_id] =>
[option_id] =>
[product_id] => 206
[delete] =>
[selection_price_value] => 0.00
[selection_price_type] => 0
[selection_qty] => 1
[selection_can_change_qty] => 1
[position] => 0
)
[1] => Array
(
[selection_id] =>
[option_id] =>
[product_id] => 159
[delete] =>
[selection_price_value] => 0.00
[selection_price_type] => 0
[selection_qty] => 1
[selection_can_change_qty] => 1
[position] => 0
)
))
谢谢TON亲爱的,你救了我一个巨大的混乱。特别是多种选择和产品的代码是生命的救星。非常感谢。 – 2012-12-06 07:39:20
我仍然在等待某些机构提供一些更有用的信息。 – 2010-06-29 09:28:06
请检查此链接以获取有关如何以正确方式以编程方式添加Bundle产品的更多有价值的信息。 http://stackoverflow.com/questions/6161128/magento-programatically-added-bundle-product-isnt-showing-up-in-frontend/6161246#6161246 – 2011-05-28 11:48:30