Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Quote Item object - how can I load item's options?

Tags:

php

magento

While I know that I can just load Quote Item Options collection and filter it by item_id, I just can't wrap my mind around that Magento folks haven't added any _afterLoad or _loadOptions method to easily assign the options to an item, since there's already a _options, _optionsByCode properties...

to provide some example of what I'm doing:

// updated (forgot to actually load object
$item = Mage::getModel('sales/quote_item')->load($itemId);
$buyRequest = $item->getBuyRequest(); // almost empty, only qty is set

I want to know if there's some $item->loadOptions() method... or other native way to load options into an item

UPDATE

What I want to do: I want to load item object and use some native way to add its options to this loaded object.

like image 382
Slayer Birden Avatar asked Dec 20 '22 18:12

Slayer Birden


1 Answers

I ended up using next piece of code

/** @var Mage_Sales_Model_Resource_Quote_Item_Option_Collection $options */
$options = Mage::getResourceModel('sales/quote_item_option_collection');
$options->addItemFilter($item->getId());
foreach ($options as $option) {
    $item->addOption($option);
}

While I understand that it doesn't answer my question directly, I think there's just no method of loading options inside quote item. So maybe someone will find the above piece of code useful.

like image 184
Slayer Birden Avatar answered Dec 24 '22 01:12

Slayer Birden