2

I want to get product option from quote_item_options.

I want product option from item which is added to cart.

I just call event checkout_cart_product_add_after and in that observer i want product option

so which model is use to get that data in magento 2?

  • In which context? – MauroNigrele Feb 1 '16 at 5:25
  • @MauroNigrele sorry i didnt get you – Newbie Feb 1 '16 at 5:28
  • I'm asking you, in which context you need to get that model ie inside a controller or cron or wathever – MauroNigrele Feb 1 '16 at 5:36
5

EDIT 2 Based on the edited question

The event checkout_cart_product_add_after send 2 parameters.

  • quote_item
  • product

So I guess that you can get the options either from the QuoteItem or Product as well.

public function execute(EventObserver $observer)
{
    $quoteItem = $observer->getEvent()->getQuoteItem();
    $options = $quoteItem->getOptions();
    // Do something with options
}

EDIT

If you are trying to get the options from a loaded Quote / QuoteItem you can call:

$quoteItem->getOptions()

But if you need to load options outside a quote or an specific quote_item you can use Magento\Quote\ResourceModel\Item\Option\Collection to grab such data.

ORIGINAL ANSWER (Completely Wrong) but may be useful for someone.

Looking in the database seems like sales_order_item_options doesn't exists anymore but now there is a product_options text field in the sales_order_item so I guess that the product options should be saved (serialized) there.

Try to load Magento\Sales\Order\Item and getProductOptions();

Or if you have already loaded the Order Model try to get them by calling $order->getAllItems()

Hope my idea helps

  • I dont want from sales order i want it from cart – Newbie Feb 1 '16 at 5:42
  • Sorry i'm a kind of stupid in that case is like in M1 Magento\Quote\Item\Option (I need to sleep) – MauroNigrele Feb 1 '16 at 5:46
  • @Newbie check out my edited answer – MauroNigrele Feb 1 '16 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.