6

我在 Magento 中有一些简单的目录产品,所以我有他们的 SKU 和 ID。现在我想使用捆绑项目的数组元素“bundle_options”和“bundle_selections”创建一个捆绑产品,Magento Admin 编码在其观察者类中使用这些元素。

同样在 Observer 类中,有两个函数“ setBundleOptionsData()”和“ setBundleSelectionsData()”的方法调用,我无法找到任何函数定义。

请在此处发布任何专业帖子,因为我需要一些正确的方法来做这件事。如果需要,覆盖模块或使用事件,我会这样做,但我需要非常专业的帮助。提前致谢。

编辑:-
关于上面提到的“ setBundleOptionsData()”&“ setBundleSelectionsData()”这两种方法,我几乎可以肯定的是它们使用了某种PHP魔术方法,但我不知道这些魔术方法的主要逻辑写在哪里?

请任何人提供一些正确的答案。任何帮助是极大的赞赏。

4

3 回答 3

4

在这方面遇到了困难,但发现这让我克服了困难:

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

    ))
于 2010-12-11T07:57:02.337 回答
2
         $MyOptions[0] = array (
            'title' => 'My Bad','default_title' => 'My Bad',
            'delete' => '',
            'type' => 'radio',
            'required' => 0,
            'position' => 0
        );

或者

$optionModel = Mage::getModel('bundle/option') ->addSelection('op111') ->setTitle('op111') ->setDefaultTitle('op111') ->setParentId($product_id) ->setStoreId($产品->getStoreId()); $optionModel->save();

于 2010-07-08T11:53:37.927 回答
0

为此,我没有使用任何 Web 服务。我只是使用了以下专门用于捆绑产品的方法,它们是:-

  1. setBundleOptionsData()
  2. setBundleSelectionsData()
  3. setCanSaveBundleSelections(true)

对于第一种方法,Bundle Options 的详细信息以数组的形式作为参数提供给方法。类似地,对于第二种方法“setBundleSelectionsData()”,我们以数组的形式将Bundle Selections 的详细信息作为参数提供给该方法。

这是在 Magento 中添加任何捆绑产品的主要逻辑。希望对新手有所帮助!!!


请检查此链接以获取有关以适当方式创建捆绑产品的更多详细信息。

于 2010-06-28T06:50:44.473 回答