문제

Is there a valuable way of getting the data of an configured Bundle product before adding it to the quote. Here the scenario:

  • User configured the bundle product in the product view
  • Add to cart
  • I catch the process of adding the product to cart with an event (sales_quote_add_item or sales_quote_product_add_after)
  • get the data of the configured bundle product

What data is in the $item. Is this the hole user based and configured Product data

$item = $observer->getEvent()->getQuoteItem();

Is this the associated Product with the item, and if yes what is the difference

$product = $item->getProduct();

So far I understand is this the user selection

    $infoBuyRequest = $item->getBuyRequest()->toArray();
    $bundleOption = $infoBuyRequest['bundle_option'];

Here are a few things I don't understand:

How can i get the Options and Selections of the configured Bundle? If I var_dumb the item or product variables I get a lot of data. Not the total Options&Colections, just the ones the user has chosen.

The next question is: is the $item the actual object which will be stored in the database (sales_flat_quote_item), so the configured one?

What do I get through $item->getProduct(). Is this the associated product data?

How can I get the custom options (stored in different arrays:bundle_selection_attributes, bundle_option_ids, etc..)?

도움이 되었습니까?

해결책

If bundleproduct is added to the card, following is passed through the observer of the sales_quote_add_item event:

  1. The bundleproduct.
  2. All the underlying simple product one after another.

So if you e.g. have a bundle product, with 4 options to choose a product and quantity, the observer is called 5 times.

In the database, a quote item is stored with the added bundle product and its selected underlying products.

$item->getProduct() does return the object of the current quote item.

You can use functions like $product->getName() and $product->getId(), $product->getAttributeText('attribute_code'), etc and all the logical stuff on it in the observer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top