开发者

Magento: how to load product along its all data as it is used in admin

I'm trying to get bundle options data. using this : $product->开发者_运维技巧getBundleOptionsData I need to use this, as I'm trying to change data programmatically and I would like to do it in a way that's as close as used in admin .

However, when I var_dump the result of the above function I get NULL while in admin side in bundle model product type I get correctly the data.

When I var_dump $product in my own file I get much shorter data than when I var_dump in bundle model product type save function.

what do I need to do to load all data of the product, so I can use getBundleOptionsData. I looked in several files and googled, but can't find an answer.


Finally I made it work to get bundle options data so I can manipulate it. I found the main code in magento's model bundle observer class duplicateProduct function: I needed however to add option_id (careful not to forget that)

here is the code in it's final stage.

$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

you can either now change on the raw data in optionsrawdata. or getBundleOptionsData. and same for the other one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜