Magento:如何在管理员中使用的所有数据中加载产品

Dre*_*lon 2 php magento

我正在尝试获取捆绑选项数据.使用这个:$product->getBundleOptionsData 我需要使用它,因为我正在尝试以编程方式更改数据,并且我希望以与admin中使用的方式一样的方式进行.

但是,当我NULL 在bundle模型产品类型的管理端获取上面函数的结果时,我得到了正确的数据.

当我$product在我自己的文件中使用var_dump时,我获得的数据比在bundle model product type save函数中的var_dump要短得多.

我需要做什么来加载产品的所有数据,所以我可以使用getBundleOptionsData.我查看了几个文件并用Google搜索,但找不到答案.

Dre*_*lon 5

最后我努力获取捆绑选项数据,以便我可以操作它.我在magento的模型包观察者类duplicateProduct函数中找到了主代码:但是我需要添加option_id(小心不要忘记)

这是它最后阶段的代码.

$product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
    $product->getTypeInstance(true)->getOptionsIds($product),
    $product
);
$optionCollection->appendSelections($selectionCollection);

$optionRawData = array();
$selectionRawData = array();

$i = 0;
foreach ($optionCollection as $option) {
    $optionRawData[$i] = array(
            'option_id' => $option->getOptionId(), //my addition. important otherwise, options going to be duplicated
            'required' => $option->getData('required'),
            'position' => $option->getData('position'),
            'type' => $option->getData('type'),
            'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
            'delete' => ''
        );
    foreach ($option->getSelections() as $selection) {
        $selectionRawData[$i][] = array(
            'product_id' => $selection->getProductId(),
            'position' => $selection->getPosition(),
            'is_default' => $selection->getIsDefault(),
            'selection_price_type' => $selection->getSelectionPriceType(),
            'selection_price_value' => $selection->getSelectionPriceValue(),
            'selection_qty' => $selection->getSelectionQty(),
            'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
            'delete' => ''
        );
    }
    $i++;
}

$product->setBundleOptionsData($optionRawData);   //changed it to $product
$product->setBundleSelectionsData($selectionRawData);  //changed it to $product
Run Code Online (Sandbox Code Playgroud)

您现在可以更改optionsrawdata中的原始数据.或getBundleOptionsData.和另一个相同.