<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="DJOGlobal\ProductInserts\Api\Data\ProductInsertsOptionInterface" type="DJOGlobal\ProductInserts\Model\ProductInsertsOption"/>

    <!-- prevent error when trying to insert into salesrule_customer since there is no real rule for the insert discounts -->
    <preference for="Magento\SalesRule\Model\Coupon\Usage\Processor" type="DJOGlobal\ProductInserts\Rewrite\Magento\SalesRule\Model\Coupon\Usage\Processor"/>

    <!-- convert/set from product option on PDP to quote item -->
    <preference for="Magento\Quote\Model\Quote\Item" type="DJOGlobal\ProductInserts\Rewrite\Magento\Quote\Model\Quote\Item"/>
    <type name="Magento\Catalog\Model\Product\Type\AbstractType">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToQuoteItem" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToQuoteItem" sortOrder="99"/>
    </type>

    <!-- add insert item to quote -->
    <type name="Magento\Quote\Api\CartRepositoryInterface">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToQuote" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToQuote" sortOrder="99"/>
    </type>

    <!-- set 0.00 price for free gel insert -->
    <type name="Magento\Quote\Model\Quote\Item">
        <plugin name="DJOGlobal_PatientInfo::SetPriceForInsertOnQuoteItem" type="DJOGlobal\ProductInserts\Plugin\SetPriceForInsertOnQuoteItem"/>
    </type>

    <!-- set/pre-populate product options for PDP from buy request for cart item edit -->
    <type name="Magento\Catalog\Model\Product">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsOptionToProductFromBuyRequestForEdit" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsOptionToProductFromBuyRequestForEdit"/>
    </type>

    <!-- show on cart item -->
    <type name="Magento\Checkout\Block\Cart\Item\Renderer">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToCartItemRenderer" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToCartItemRenderer"/>
    </type>
    <type name="Magento\Checkout\CustomerData\AbstractItem">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToMiniCartItemData" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToMiniCartItemData"/>
    </type>
    <type name="Magento\Catalog\Helper\Product\Configuration">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToCartItemOptions" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToCartItemOptions"/>
    </type>

    <!-- add to checkout config (for one step checkout review section) -->
    <type name="Magento\Checkout\Model\DefaultConfigProvider">
        <plugin name="DJOGlobal_PatientInfo::AddProductInsertsToCheckoutConfig" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToCheckoutConfig"/>
    </type>
    <type name="Magento\Quote\Model\Cart\Totals\ItemConverter">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToCheckoutTotalsItemData" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToCheckoutTotalsItemData"/>
    </type>

    <!-- convert/set to order item -->
    <type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToOrderItem" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToOrderItem"/>
    </type>

    <!-- show on order item -->
    <type name="\Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToOrderItemRenderer" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToOrderItemRenderer"/>
    </type>

    <!-- show on order item in admin -->
    <type name="\Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsToOrderItemRendererAdmin.php" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsToOrderItemRendererAdmin"/>
    </type>

    <!-- add to order item api object -->
    <type name="\Magento\Sales\Model\Order\ItemRepository">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsExtensionAttributesOrderItem" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsExtensionAttributesOrderItem"/>
    </type>

    <!-- add to cart/quote item api object so values can be set during a cart/order create from the api -->
    <!--
    <type name="\Magento\Quote\Model\Quote\Item\Repository">
        <plugin name="DJOGlobal_ProductInserts::AddProductInsertsExtensionAttributesCartItem" type="DJOGlobal\ProductInserts\Plugin\AddProductInsertsExtensionAttributesCartItem"/>
    </type>
    -->

    <!-- add to order item api object -->
    <type name="\Magento\Checkout\Model\Cart">
        <plugin name="DJOGlobal_ProductInserts::FilterOutProductInsertsOnReOrder" type="DJOGlobal\ProductInserts\Plugin\FilterOutProductInsertsOnReOrder"/>
    </type>
</config>
