<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
    <!-- API Preference - Maps interface to implementation -->
    <preference for="PortalPeople\ShippingFields\Api\ShippingFieldsInterface" type="PortalPeople\ShippingFields\Model\ShippingFieldsManagement"/>
    
    <!-- Quote Repository Plugin -->
    <type name="Magento\Quote\Model\QuoteRepository">
        <plugin name="shipping_fields_quote_repository" type="PortalPeople\ShippingFields\Plugin\QuoteRepositoryPlugin" sortOrder="1"/>
    </type>
    
    <!-- Cart Repository Plugin -->
    <type name="Magento\Quote\Model\CartRepository">
        <plugin name="shipping_fields_cart_repository" type="PortalPeople\ShippingFields\Plugin\CartRepositoryPlugin" sortOrder="1"/>
    </type>
    
    <!-- Order Repository Plugin -->
    <type name="Magento\Sales\Model\OrderRepository">
        <plugin name="shipping_fields_order_repository" type="PortalPeople\ShippingFields\Plugin\OrderRepositoryPlugin" sortOrder="1"/>
    </type>
    
    <!-- Quote to Order Plugin -->
    <type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
        <plugin name="shipping_fields_quote_to_order" type="PortalPeople\ShippingFields\Plugin\QuoteToOrderPlugin" sortOrder="1"/>
    </type>
    
    <!-- Payment Information Management Plugin -->
    <type name="Magento\Checkout\Model\PaymentInformationManagement">
        <plugin name="shipping_fields_payment_information" type="PortalPeople\ShippingFields\Plugin\PaymentInformationManagementPlugin" sortOrder="1"/>
    </type>
    
    <!-- Shipping Information Management Plugin - CAPTURES DATA FROM SHIPPING STEP -->
    <type name="Magento\Checkout\Model\ShippingInformationManagement">
        <plugin name="shipping_fields_shipping_information" type="PortalPeople\ShippingFields\Plugin\ShippingInformationManagementPlugin" sortOrder="1"/>
    </type>
    
</config>
