diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnConfigurationPageCustomStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnConfigurationPageCustomStockTest.xml index dde2a233a4ad..ae78a3940135 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnConfigurationPageCustomStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnConfigurationPageCustomStockTest.xml @@ -18,7 +18,7 @@ - + @@ -47,7 +47,6 @@ - @@ -57,6 +56,7 @@ + @@ -95,7 +95,7 @@ - + @@ -103,7 +103,7 @@ - + diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnProductPageCustomStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnProductPageCustomStockTest.xml index c065628c1c7f..15c586ce5d99 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnProductPageCustomStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminBundleProductDisabledManageStockOnProductPageCustomStockTest.xml @@ -18,7 +18,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -101,7 +101,7 @@ - + diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCancelOrderBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCancelOrderBundleProductCustomStock.xml index 61a05eaf0c00..cafe65f6b0a1 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCancelOrderBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCancelOrderBundleProductCustomStock.xml @@ -8,7 +8,7 @@ - + @@ -17,50 +17,106 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> - <remove keyForRemoval="assignMainWebsiteToDefaultStock"/> - <remove keyForRemoval="customStock"/> - <createData entity="BasicMsiStockWithMainWebsite1" stepKey="customStock"/> + <!--Create additional source and stock.--> + <createData entity="BasicMsiStockWithMainWebsite1" stepKey="additionalStock"/> + <createData entity="FullSource1" stepKey="additionalSource"/> + <createData entity="SourceStockLinked1" stepKey="sourceStockLink"> + <requiredEntity createDataKey="additionalStock"/> + <requiredEntity createDataKey="additionalSource"/> + </createData> + <!--Create bundle and simple products.--> + <createData entity="_defaultCategory" stepKey="category"/> + <createData entity="ApiBundleProduct" stepKey="bundleProduct"/> + <createData entity="SimpleProduct" stepKey="product1"> + <requiredEntity createDataKey="category"/> + </createData> + <createData entity="SimpleProduct" stepKey="product2"> + <requiredEntity createDataKey="category"/> + </createData> + <createData entity="DropDownBundleOption" stepKey="bundleOption"> + <requiredEntity createDataKey="bundleProduct"/> + </createData> + <createData entity="ApiBundleLink" stepKey="bundleLink1"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="bundleOption"/> + <requiredEntity createDataKey="product1"/> + </createData> + <createData entity="ApiBundleLink" stepKey="bundleLink2"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="bundleOption"/> + <requiredEntity createDataKey="product2"/> + </createData> + <!--Create customer.--> + <createData entity="MsiCustomer1" stepKey="customer"/> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + <!--Assign simple products to additional source.--> + <amOnPage url="{{AdminProductEditPage.url($product1.id$)}}" stepKey="openSimple1ProductEditPage"/> + <actionGroup ref="UnassignSourceFromProductActionGroup" stepKey="unassignDefaultSourceFromProduct1"> + <argument name="sourceCode" value="{{_defaultSource.name}}"/> + </actionGroup> + <actionGroup ref="AdminAssignSourceToProductAndSetSourceQuantityActionGroup" stepKey="assignSourceAndSetQtyForProduct1"> + <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> + </actionGroup> + <actionGroup ref="AdminFormSaveAndClose" stepKey="saveSimpleProduct1"/> + <amOnPage url="{{AdminProductEditPage.url($product2.id$)}}" stepKey="openSimple2ProductEditPage"/> + <actionGroup ref="UnassignSourceFromProductActionGroup" stepKey="unassignDefaultSourceFromProduct2"> + <argument name="sourceCode" value="{{_defaultSource.name}}"/> + </actionGroup> + <actionGroup ref="AdminAssignSourceToProductAndSetSourceQuantityActionGroup" stepKey="assignSourceAndSetQtyForProduct2"> + <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> + </actionGroup> + <actionGroup ref="AdminFormSaveAndClose" stepKey="saveSimpleProduct2"/> </before> <after> + <deleteData createDataKey="customer" stepKey="deleteCustomer"/> + <deleteData createDataKey="category" stepKey="deleteCategory"/> + <deleteData createDataKey="product1" stepKey="deleteSimpleProduct1"/> + <deleteData createDataKey="product2" stepKey="deleteSimpleProduct2"/> + <deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/> <!--Assign Default Stock to Default Website.--> - <actionGroup ref="AssignWebsiteToStockActionGroup" stepKey="assignMainWebsiteToDefaultStock" after="disableCreatedCustomSource"> + <actionGroup ref="AssignWebsiteToStockActionGroup" stepKey="assignMainWebsiteToDefaultStock"> <argument name="stockName" value="{{_defaultStock.name}}"/> <argument name="websiteName" value="{{_defaultWebsite.name}}"/> </actionGroup> + <deleteData createDataKey="additionalStock" stepKey="deleteStock"/> + <actionGroup ref="DisableAllSourcesActionGroup" stepKey="disableAllSources"/> + <actionGroup ref="logout" stepKey="logoutOfAdmin"/> </after> - <!--Assign additional source to simple product.--> - <amOnPage url="{{AdminProductEditPage.url($$simpleProduct.id$$)}}" stepKey="openProductEditPageToAssignSource" before="assignSourceToProduct"/> - <actionGroup ref="AssignSourceToProductActionGroup" stepKey="assignSourceToProduct" before="setProductQuantity"> - <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> + <!--Login To storefront as Customer--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefront"> + <argument name="Customer" value="$$customer$$"/> + </actionGroup> + <!--Add product to cart.--> + <amOnPage url="{{StorefrontProductPage.url($bundleProduct.custom_attributes[url_key]$)}}" stepKey="navigateToBundlePDP"/> + <actionGroup ref="StorefrontAddBundleProductToTheCartActionGroup" stepKey="addBundleProductToCart"> + <argument name="productName" value="$product1.name$"/> + <argument name="quantity" value="{{tenPiecesAddToCart.value}}"/> </actionGroup> - <fillField selector="{{AdminProductSourcesGrid.rowQty('1')}}" userInput="1000" stepKey="setProductQuantity" before="saveSimpleProduct"/> - <click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveSimpleProduct" before="waitForProductSave"/> - <waitForPageLoad stepKey="waitForProductSave" before="visitAdminProductPageBundle"/> - <!--Get order Id.--> - <grabTextFrom selector="|Order # (\d+)|" stepKey="orderId" after="clickSubmitOrder" /> - <!--Cancel order.--> - <actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder" after="checkSimpleProductSalableQtyAfterPlaceOrder"> - <argument name="orderId" value="{$orderId}"/> + <!--Place order.--> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="navigateToCheckout"/> + <click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder"/> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="orderNumber"/> + <!--Cancel Order.--> + <actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder"> + <argument name="orderId" value="{$orderNumber}"/> </actionGroup> - <click selector="{{AdminOrderDetailsMainActionsSection.cancel}}" stepKey="clickCancelOrder"/> - <waitForElement selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForCancelConfirmation"/> - <see selector="{{AdminConfirmationModalSection.message}}" userInput="Are you sure you want to cancel this order?" stepKey="seeConfirmationMessage"/> - <click selector="{{AdminConfirmationModalSection.ok}}" stepKey="confirmOrderCancel"/> - <see selector="{{AdminMessagesSection.success}}" userInput="You canceled the order." stepKey="seeCancelSuccessMessage"/> - <!--Verify product quantity after order cancellation.--> - <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductGrid"/> - <actionGroup ref="AdminGridFilterSearchResultsByInput" stepKey="findProduct"> + <actionGroup ref="CancelPendingOrderActionGroup" stepKey="cancelOrder"/> + <!--Admin Area Check quantities after Credit Memo--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndexPageForCheckProductQtyAfterCreditMemo"/> + <actionGroup ref="AdminGridFilterSearchResultsByInput" stepKey="findProductBySkuToCheckQtyAfterCreditMemo"> <argument name="selector" value="AdminProductGridFilterSection.skuFilter"/> - <argument name="value" value="$$simpleProduct.sku$$"/> + <argument name="value" value="$product1.sku$"/> + </actionGroup> + <actionGroup ref="AssertAdminSalableProductQtyActionGroup" stepKey="verifyProductQuantity"> + <argument name="sourceName" value="$$additionalSource.source[name]$$"/> + <argument name="sourceQty" value="{{defaultProductQty.value}}"/> + <argument name="stockName" value="$$additionalStock.stock[name]$$"/> + <argument name="stockQty" value="{{defaultProductQty.value}}"/> </actionGroup> - <see selector="{{AdminProductGridSection.productQtyPerSource('1', $$customSource.source[name]$$)}}" userInput="1000" stepKey="verifySourceQuantity"/> - <see selector="{{AdminProductGridSection.productSalableQty('1', $$customStock.stock[name]$$)}}" userInput="1000" stepKey="verifyStockQuantity"/> </test> </tests> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateBundleProductAdditionalStockAdditionalWebsiteTest.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateBundleProductAdditionalStockAdditionalWebsiteTest.xml index 06af491a2fe1..56984da4e220 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateBundleProductAdditionalStockAdditionalWebsiteTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateBundleProductAdditionalStockAdditionalWebsiteTest.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundBundleProductCustomStock.xml index 86ff83e83aa5..c221811d45ee 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentBundleProductCustomStock.xml index 4873b6285511..c519439a963d 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentPartialInvoiceBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentPartialInvoiceBundleProductCustomStock.xml index 9c5dc6be62e2..f5e04378fc2a 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentPartialInvoiceBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoPartialRefundPartialShipmentPartialInvoiceBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundBundleProductCustomStock.xml index 356dce054767..fc9638f7430d 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> @@ -30,7 +27,7 @@ <requiredEntity createDataKey="additionalStock"/> <requiredEntity createDataKey="additionalSource"/> </createData> - <!--Create grouped and virtual product.--> + <!--Create bundle and virtual product.--> <createData entity="_defaultCategory" stepKey="category"/> <createData entity="ApiBundleProduct" stepKey="bundleProduct"/> <createData entity="VirtualProduct" stepKey="product"/> @@ -39,20 +36,18 @@ <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> </before> <after> + <deleteData createDataKey="customer" stepKey="deleteCustomer"/> + <deleteData createDataKey="category" stepKey="deleteCategory"/> + <deleteData createDataKey="product" stepKey="deleteProduct"/> + <deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/> <!--Assign Default Stock to Default Website.--> <actionGroup ref="AssignWebsiteToStockActionGroup" stepKey="assignMainWebsiteToDefaultStock"> <argument name="stockName" value="{{_defaultStock.name}}"/> <argument name="websiteName" value="{{_defaultWebsite.name}}"/> </actionGroup> - <actionGroup ref="DisableSourceActionGroup" stepKey="disableSource"> - <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> - </actionGroup> - <actionGroup ref="logout" stepKey="logoutOfAdmin"/> - <deleteData createDataKey="customer" stepKey="deleteCustomer"/> - <deleteData createDataKey="category" stepKey="deleteCategory"/> - <deleteData createDataKey="product" stepKey="deleteProduct"/> - <deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/> <deleteData createDataKey="additionalStock" stepKey="deleteStock"/> + <actionGroup ref="DisableAllSourcesActionGroup" stepKey="disableAllSources"/> + <actionGroup ref="logout" stepKey="logoutOfAdmin"/> </after> <!--Assign virtual product to additional source.--> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock.xml index 8946aa3f2aca..cfb0e994e01c 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock.xml @@ -8,7 +8,7 @@ <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> - <test name="AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock" extends="AdminCreateCreditMemoTotalRefundBundleProductCustomStock"> + <test name="AdminCreateCreditMemoTotalRefundPartialShipmentBundleProductCustomStock"> <annotations> <stories value="Bundle Product Custom Stock."/> <title value="Create Credit Memo with Partial Shipment, Bundle product on Custom stock."/> @@ -17,29 +17,115 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> - <remove keyForRemoval="product"/> - <createData entity="SimpleProduct" stepKey="product" after="category"> + <!--Create additional source and stock.--> + <createData entity="BasicMsiStockWithMainWebsite1" stepKey="additionalStock"/> + <createData entity="FullSource1" stepKey="additionalSource"/> + <createData entity="SourceStockLinked1" stepKey="sourceStockLink"> + <requiredEntity createDataKey="additionalStock"/> + <requiredEntity createDataKey="additionalSource"/> + </createData> + <!--Create bundle and simple products.--> + <createData entity="_defaultCategory" stepKey="category"/> + <createData entity="ApiBundleProduct" stepKey="bundleProduct"/> + <createData entity="SimpleProduct" stepKey="product1"> + <requiredEntity createDataKey="category"/> + </createData> + <createData entity="SimpleProduct" stepKey="product2"> <requiredEntity createDataKey="category"/> </createData> + <createData entity="DropDownBundleOption" stepKey="bundleOption"> + <requiredEntity createDataKey="bundleProduct"/> + </createData> + <createData entity="ApiBundleLink" stepKey="bundleLink1"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="bundleOption"/> + <requiredEntity createDataKey="product1"/> + </createData> + <createData entity="ApiBundleLink" stepKey="bundleLink2"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="bundleOption"/> + <requiredEntity createDataKey="product2"/> + </createData> + <!--Create customer.--> + <createData entity="MsiCustomer1" stepKey="customer"/> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + <!--Assign simple products to additional source.--> + <amOnPage url="{{AdminProductEditPage.url($product1.id$)}}" stepKey="openSimple1ProductEditPage"/> + <actionGroup ref="UnassignSourceFromProductActionGroup" stepKey="unassignDefaultSourceFromProduct1"> + <argument name="sourceCode" value="{{_defaultSource.name}}"/> + </actionGroup> + <actionGroup ref="AdminAssignSourceToProductAndSetSourceQuantityActionGroup" stepKey="assignSourceAndSetQtyForProduct1"> + <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> + </actionGroup> + <actionGroup ref="AdminFormSaveAndClose" stepKey="saveSimpleProduct1"/> + <amOnPage url="{{AdminProductEditPage.url($product2.id$)}}" stepKey="openSimple2ProductEditPage"/> + <actionGroup ref="UnassignSourceFromProductActionGroup" stepKey="unassignDefaultSourceFromProduct2"> + <argument name="sourceCode" value="{{_defaultSource.name}}"/> + </actionGroup> + <actionGroup ref="AdminAssignSourceToProductAndSetSourceQuantityActionGroup" stepKey="assignSourceAndSetQtyForProduct2"> + <argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/> + </actionGroup> + <actionGroup ref="AdminFormSaveAndClose" stepKey="saveSimpleProduct2"/> </before> + <after> + <deleteData createDataKey="customer" stepKey="deleteCustomer"/> + <deleteData createDataKey="category" stepKey="deleteCategory"/> + <deleteData createDataKey="product1" stepKey="deleteSimpleProduct1"/> + <deleteData createDataKey="product2" stepKey="deleteSimpleProduct2"/> + <deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/> + <!--Assign Default Stock to Default Website.--> + <actionGroup ref="AssignWebsiteToStockActionGroup" stepKey="assignMainWebsiteToDefaultStock"> + <argument name="stockName" value="{{_defaultStock.name}}"/> + <argument name="websiteName" value="{{_defaultWebsite.name}}"/> + </actionGroup> + <deleteData createDataKey="additionalStock" stepKey="deleteStock"/> + <actionGroup ref="DisableAllSourcesActionGroup" stepKey="disableAllSources"/> + <actionGroup ref="logout" stepKey="logoutOfAdmin"/> + </after> - <click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext" after="waitForCheckoutPage"/> - <waitForElement selector="{{CheckoutPaymentSection.placeOrder}}" time="30" stepKey="waitForPlaceOrderButton" after="clickNext"/> - <!--Admin Area Process Partial Shipment.--> - <click selector="{{AdminOrderDetailsMainActionsSection.ship}}" stepKey="clickShipAction" after="checkSuccessMessage"/> - <fillField selector=".order-shipment-table tbody:nth-of-type(1) .col-qty input" userInput="1" stepKey="shipOneItem" after="clickShipAction"/> - <click selector="{{AdminShipmentMainActionsSection.submitShipment}}" stepKey="clickSubmitShipment" after="shipOneItem"/> - <see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="The shipment has been created." stepKey="checkShipmentSuccessMessage" after="clickSubmitShipment"/> - <!--Verify product quantity.--> - <remove keyForRemoval="checkProductSourceQtyAfterCreditMemo"/> - <remove keyForRemoval="checkSalableQtyAfterCreditMemo"/> - <see selector="{{AdminProductGridSection.productQtyPerSource('1', $$additionalSource.source[name]$$)}}" userInput="95" stepKey="checkProductSourceQtyAfterCreditMemo" after="findProductBySkuToCheckQtyAfterCreditMemo"/> - <see selector="{{AdminProductGridSection.productSalableQty('1', $$additionalStock.stock[name]$$)}}" userInput="90" stepKey="checkSalableQtyAfterCreditMemo" after="checkProductSourceQtyAfterCreditMemo"/> + <!--Login To storefront as Customer--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefront"> + <argument name="Customer" value="$$customer$$"/> + </actionGroup> + <!--Add product to cart.--> + <amOnPage url="{{StorefrontProductPage.url($bundleProduct.custom_attributes[url_key]$)}}" stepKey="navigateToBundlePDP"/> + <actionGroup ref="StorefrontAddBundleProductToTheCartActionGroup" stepKey="addBundleProductToCart"> + <argument name="productName" value="$product1.name$"/> + <argument name="quantity" value="{{tenPiecesAddToCart.value}}"/> + </actionGroup> + <!--Place order.--> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="navigateToCheckout"/> + <click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder"/> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="orderNumber"/> + <!--Process full invoice and partial shipment.--> + <actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder"> + <argument name="orderId" value="{$orderNumber}"/> + </actionGroup> + <actionGroup ref="AdminCreateInvoiceActionGroup" stepKey="createInvoice"/> + <click selector="{{AdminOrderDetailsMainActionsSection.ship}}" stepKey="clickShipAction"/> + <fillField selector=".order-shipment-table tbody:nth-of-type(1) .col-qty input" userInput="{{fivePiecesAddToCart.value}}" stepKey="shipFiveItems"/> + <click selector="{{AdminShipmentMainActionsSection.submitShipment}}" stepKey="clickSubmitShipment"/> + <!--Admin Area Total Refund Credit Memo--> + <actionGroup ref="StartToCreateCreditMemoActionGroup" stepKey="startToCreateCreditMemo"> + <argument name="orderId" value="{$orderNumber}"/> + </actionGroup> + <click selector="{{AdminCreditMemoItemsSection.itemReturnToStock('1')}}" stepKey="returnToStockCheckbox"/> + <actionGroup ref="SubmitCreditMemoActionGroup" stepKey="submitCreditMemo"/> + <!--Admin Area Check quantities after Credit Memo--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndexPageForCheckProductQtyAfterCreditMemo"/> + <actionGroup ref="AdminGridFilterSearchResultsByInput" stepKey="findProductBySkuToCheckQtyAfterCreditMemo"> + <argument name="selector" value="AdminProductGridFilterSection.skuFilter"/> + <argument name="value" value="$product1.sku$"/> + </actionGroup> + <actionGroup ref="AssertAdminSalableProductQtyActionGroup" stepKey="verifyProductQuantity"> + <argument name="sourceName" value="$$additionalSource.source[name]$$"/> + <argument name="sourceQty" value="{{defaultProductQty.value}}"/> + <argument name="stockName" value="$$additionalStock.stock[name]$$"/> + <argument name="stockQty" value="{{defaultProductQty.value}}"/> + </actionGroup> </test> </tests> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreatePartialShipmentBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreatePartialShipmentBundleProductCustomStock.xml index bd3becfa9fd1..36b31b3cbbd4 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreatePartialShipmentBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreatePartialShipmentBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateScheduledPermanentUpdateBundleProductCustomStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateScheduledPermanentUpdateBundleProductCustomStockTest.xml index 9b207a7cd49a..04b2a886b4ef 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateScheduledPermanentUpdateBundleProductCustomStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateScheduledPermanentUpdateBundleProductCustomStockTest.xml @@ -17,9 +17,6 @@ <testCaseId value="https://app.hiptest.com/projects/69435/test-plan/folders/566629/scenarios/1936221"/> <group value="msi_ee"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> <!--Create stock and source.--> diff --git a/InventoryAdminUi/Test/Mftf/Test/AdminCreateShipmentBundleProductCustomStock.xml b/InventoryAdminUi/Test/Mftf/Test/AdminCreateShipmentBundleProductCustomStock.xml index 1de1cf1daa9f..ba094d03486a 100644 --- a/InventoryAdminUi/Test/Mftf/Test/AdminCreateShipmentBundleProductCustomStock.xml +++ b/InventoryAdminUi/Test/Mftf/Test/AdminCreateShipmentBundleProductCustomStock.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/CatalogPriceRuleBundleProductAdditionalStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/CatalogPriceRuleBundleProductAdditionalStockTest.xml index e6b396d1ad2d..716c08682838 100644 --- a/InventoryAdminUi/Test/Mftf/Test/CatalogPriceRuleBundleProductAdditionalStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/CatalogPriceRuleBundleProductAdditionalStockTest.xml @@ -17,9 +17,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/SimpleProductWithZeroQtyAndInStockStatusOnTestSourceVisibleOnHomePageIfBackordersEnabledOnConfigurationPageTest.xml b/InventoryAdminUi/Test/Mftf/Test/SimpleProductWithZeroQtyAndInStockStatusOnTestSourceVisibleOnHomePageIfBackordersEnabledOnConfigurationPageTest.xml index a1583f68d15e..8a447927e226 100644 --- a/InventoryAdminUi/Test/Mftf/Test/SimpleProductWithZeroQtyAndInStockStatusOnTestSourceVisibleOnHomePageIfBackordersEnabledOnConfigurationPageTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/SimpleProductWithZeroQtyAndInStockStatusOnTestSourceVisibleOnHomePageIfBackordersEnabledOnConfigurationPageTest.xml @@ -42,6 +42,7 @@ </actionGroup> <fillField selector="{{AdminProductSourcesGrid.rowQty('0')}}" userInput="0" stepKey="setProductQuantity" after="assignTestSourceToCreatedProduct"/> <actionGroup ref="AdminFormSaveAndClose" stepKey="saveAndClose" after="setProductQuantity"/> - + <magentoCLI command="indexer:reindex" stepKey="reindex" after="saveAndClose"/> + <magentoCLI command="cache:flush" stepKey="flushCache" after="reindex"/> </test> </tests> diff --git a/InventoryAdminUi/Test/Mftf/Test/StorefrontAdvancedSearchBundleProductCustomStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/StorefrontAdvancedSearchBundleProductCustomStockTest.xml index c1ecfcbc181a..618bd9cd3f3f 100644 --- a/InventoryAdminUi/Test/Mftf/Test/StorefrontAdvancedSearchBundleProductCustomStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/StorefrontAdvancedSearchBundleProductCustomStockTest.xml @@ -16,9 +16,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryAdminUi/Test/Mftf/Test/StorefrontQuickSearchBundleProductCustomStockTest.xml b/InventoryAdminUi/Test/Mftf/Test/StorefrontQuickSearchBundleProductCustomStockTest.xml index 60a44a5e7544..e0e4b30147ea 100644 --- a/InventoryAdminUi/Test/Mftf/Test/StorefrontQuickSearchBundleProductCustomStockTest.xml +++ b/InventoryAdminUi/Test/Mftf/Test/StorefrontQuickSearchBundleProductCustomStockTest.xml @@ -16,9 +16,6 @@ <severity value="CRITICAL"/> <group value="msi"/> <group value="multi_mode"/> - <skip> - <issueId value="https://github.com/magento/inventory/issues/522"/> - </skip> </annotations> <before> diff --git a/InventoryBundleProduct/Model/GetBundleProductStockStatus.php b/InventoryBundleProduct/Model/GetBundleProductStockStatus.php new file mode 100644 index 000000000000..6eef19e2fc0b --- /dev/null +++ b/InventoryBundleProduct/Model/GetBundleProductStockStatus.php @@ -0,0 +1,86 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProduct\Model; + +use Magento\Bundle\Api\Data\OptionInterface; +use Magento\Bundle\Model\OptionRepository; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\InventorySalesApi\Api\IsProductSalableInterface; + +/** + * Get bundle product stock status service. + */ +class GetBundleProductStockStatus +{ + /** + * @var OptionRepository + */ + private $optionRepository; + + /** + * @var GetProductSelection + */ + private $getProductSelection; + + /** + * @var IsProductSalableInterface + */ + private $isProductSalable; + + /** + * GetBundleProductStockStatus constructor + * + * @param OptionRepository $optionRepository + * @param GetProductSelection $getProductSelection + * @param IsProductSalableInterface $isProductSalable + */ + public function __construct( + OptionRepository $optionRepository, + GetProductSelection $getProductSelection, + IsProductSalableInterface $isProductSalable + ) { + $this->optionRepository = $optionRepository; + $this->getProductSelection = $getProductSelection; + $this->isProductSalable = $isProductSalable; + } + + /** + * Provides bundle product stock status. + * + * @param ProductInterface $product + * @param OptionInterface[] $bundleOptions + * @param int $stockId + * + * @return bool + */ + public function execute(ProductInterface $product, array $bundleOptions, int $stockId): bool + { + $isSalable = false; + foreach ($bundleOptions as $option) { + $hasSalable = false; + $bundleSelections = $this->getProductSelection->execute($product, $option); + foreach ($bundleSelections as $selection) { + if ($this->isProductSalable->execute((string)$selection->getSku(), $stockId)) { + $hasSalable = true; + break; + } + } + + if ($hasSalable) { + $isSalable = true; + } + + if (!$hasSalable && $option->getRequired()) { + $isSalable = false; + break; + } + } + + return $isSalable; + } +} diff --git a/InventoryBundleProduct/Model/GetProductSelection.php b/InventoryBundleProduct/Model/GetProductSelection.php new file mode 100644 index 000000000000..18ff7efe2a06 --- /dev/null +++ b/InventoryBundleProduct/Model/GetProductSelection.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProduct\Model; + +use Magento\Bundle\Model\Option; +use Magento\Bundle\Model\ResourceModel\Selection\Collection; +use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier; +use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\EntityManager\MetadataPool; + +/** + * Retrieve bundle product selection service. + */ +class GetProductSelection +{ + /** + * @var CollectionFactory + */ + private $collectionFactory; + + /** + * @var MetadataPool + */ + private $metadataPool; + + /** + * @var FilterApplier + */ + private $selectionCollectionFilterApplier; + + /** + * @param CollectionFactory $collectionFactory + * @param MetadataPool $metadataPool + * @param FilterApplier $selectionCollectionFilterApplier + */ + public function __construct( + CollectionFactory $collectionFactory, + MetadataPool $metadataPool, + FilterApplier $selectionCollectionFilterApplier + ) { + $this->collectionFactory = $collectionFactory; + $this->metadataPool = $metadataPool; + $this->selectionCollectionFilterApplier = $selectionCollectionFilterApplier; + } + + /** + * Retrieve bundle product selection for given bundle product and option. + * + * @param ProductInterface $product + * @param Option $option + * @return Collection + * @throws \Exception + */ + public function execute(ProductInterface $product, Option $option): Collection + { + $metadata = $this->metadataPool->getMetadata(ProductInterface::class); + $selectionsCollection = $this->collectionFactory->create(); + $selectionsCollection->addAttributeToSelect('status'); + $selectionsCollection->setFlag('product_children', true); + $selectionsCollection->addFilterByRequiredOptions(); + $selectionsCollection->setOptionIdsFilter([$option->getId()]); + + $this->selectionCollectionFilterApplier->apply( + $selectionsCollection, + 'parent_product_id', + $product->getData($metadata->getLinkField()) + ); + + return $selectionsCollection; + } +} diff --git a/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php b/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php new file mode 100644 index 000000000000..cc55064f3b01 --- /dev/null +++ b/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php @@ -0,0 +1,105 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProduct\Plugin\Bundle\Model\Product\Type; + +use Magento\Bundle\Model\Product\Type; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\Catalog\Model\Product\Type as ProductType; +use Magento\InventoryBundleProduct\Model\GetBundleProductStockStatus; +use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; +use Magento\InventorySalesApi\Api\IsProductSalableInterface; +use Magento\InventorySalesApi\Model\StockByWebsiteIdResolverInterface; +use Magento\Store\Model\StoreManagerInterface; + +/** + * Adapt 'Is Salable' for bundle product for multi stock environment plugin. + */ +class AdaptIsSalablePlugin +{ + /** + * @var IsProductSalableInterface + */ + private $isProductSalable; + + /** + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @var StockByWebsiteIdResolverInterface + */ + private $stockByWebsiteIdResolver; + + /** + * @var GetBundleProductStockStatus + */ + private $getBundleProductStockStatus; + + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + /** + * @param IsProductSalableInterface $isProductSalable + * @param StoreManagerInterface $storeManager + * @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver + * @param GetBundleProductStockStatus $getBundleProductStockStatus + * @param DefaultStockProviderInterface $defaultStockProvider + */ + public function __construct( + IsProductSalableInterface $isProductSalable, + StoreManagerInterface $storeManager, + StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver, + GetBundleProductStockStatus $getBundleProductStockStatus, + DefaultStockProviderInterface $defaultStockProvider + ) { + $this->isProductSalable = $isProductSalable; + $this->storeManager = $storeManager; + $this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver; + $this->getBundleProductStockStatus = $getBundleProductStockStatus; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * Verify, is product salable in multi stock environment. + * + * @param Type $subject + * @param \Closure $proceed + * @param Product $product + * @return bool + */ + public function aroundIsSalable(Type $subject, \Closure $proceed, $product): bool + { + $salable = $product->getStatus() == Status::STATUS_ENABLED; + if ($salable && $product->hasData('is_salable')) { + $salable = $product->getData('is_salable'); + } + + if (!(bool)(int)$salable) { + return false; + } + + if ($product->hasData('all_items_salable')) { + return $product->getData('all_items_salable'); + } + + $website = $this->storeManager->getWebsite(); + $stock = $this->stockByWebsiteIdResolver->execute((int)$website->getId()); + if ($this->defaultStockProvider->getId() === $stock->getStockId()) { + return $proceed($product); + } + $options = $subject->getOptionsCollection($product); + $isSalable = $this->getBundleProductStockStatus->execute($product, $options->getItems(), $stock->getStockId()); + $product->setData('all_items_salable', $isSalable); + + return $isSalable; + } +} diff --git a/InventoryBundleProduct/Plugin/Bundle/Model/ResourceModel/Selection/Collection/AdaptAddQuantityFilterPlugin.php b/InventoryBundleProduct/Plugin/Bundle/Model/ResourceModel/Selection/Collection/AdaptAddQuantityFilterPlugin.php new file mode 100644 index 000000000000..46f40f237ee0 --- /dev/null +++ b/InventoryBundleProduct/Plugin/Bundle/Model/ResourceModel/Selection/Collection/AdaptAddQuantityFilterPlugin.php @@ -0,0 +1,88 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProduct\Plugin\Bundle\Model\ResourceModel\Selection\Collection; + +use Magento\Bundle\Model\ResourceModel\Selection\Collection; +use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; +use Magento\InventorySalesApi\Api\IsProductSalableInterface; +use Magento\InventorySalesApi\Model\StockByWebsiteIdResolverInterface; +use Magento\Store\Model\StoreManagerInterface; + +/** + * Adapt add quantity filter to bundle selection in multi stock environment plugin. + */ +class AdaptAddQuantityFilterPlugin +{ + /** + * @var IsProductSalableInterface + */ + private $isProductSalable; + + /** + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @var StockByWebsiteIdResolverInterface + */ + private $stockByWebsiteIdResolver; + + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + /** + * @param IsProductSalableInterface $isProductSalable + * @param StoreManagerInterface $storeManager + * @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver + * @param DefaultStockProviderInterface $defaultStockProvider + */ + public function __construct( + IsProductSalableInterface $isProductSalable, + StoreManagerInterface $storeManager, + StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver, + DefaultStockProviderInterface $defaultStockProvider + ) { + $this->isProductSalable = $isProductSalable; + $this->storeManager = $storeManager; + $this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * Adapt quantity filter for multi stock environment. + * + * @param Collection $subject + * @param \Closure $proceed + * @return Collection + */ + public function aroundAddQuantityFilter( + Collection $subject, + \Closure $proceed + ): Collection { + $website = $this->storeManager->getWebsite(); + $stock = $this->stockByWebsiteIdResolver->execute((int)$website->getId()); + if ($this->defaultStockProvider->getId() === $stock->getStockId()) { + return $proceed(); + } + $skusToExclude = []; + foreach ($subject->getData() as $item) { + if (!$this->isProductSalable->execute((string)$item['sku'], $stock->getStockId())) { + $skusToExclude[] = (string)$item['sku']; + } + } + if ($skusToExclude) { + $subject->getSelect()->where('e.sku NOT IN(?)', implode(',', $skusToExclude)); + } + $subject->resetData(); + + return $subject; + } +} diff --git a/InventoryBundleProduct/Plugin/InventorySalesApi/Model/GetSkuFromOrderItem/AdaptGetSkuFromOrderItemPlugin.php b/InventoryBundleProduct/Plugin/InventorySalesApi/Model/GetSkuFromOrderItem/AdaptGetSkuFromOrderItemPlugin.php new file mode 100644 index 000000000000..961f6b7e59d5 --- /dev/null +++ b/InventoryBundleProduct/Plugin/InventorySalesApi/Model/GetSkuFromOrderItem/AdaptGetSkuFromOrderItemPlugin.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProduct\Plugin\InventorySalesApi\Model\GetSkuFromOrderItem; + +use Magento\Bundle\Model\Product\Type; +use Magento\InventorySalesApi\Model\GetSkuFromOrderItemInterface; +use Magento\Sales\Api\Data\OrderItemInterface; + +/** + * Get simple product SKU from bundle order item plugin. + */ +class AdaptGetSkuFromOrderItemPlugin +{ + /** + * Retrieve bundle selection sku from order item. + * + * @param GetSkuFromOrderItemInterface $subject + * @param callable $proceed + * @param OrderItemInterface $orderItem + * @return string + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundExecute( + GetSkuFromOrderItemInterface $subject, + callable $proceed, + OrderItemInterface $orderItem + ): string { + if ($orderItem->getProductType() !== Type::TYPE_CODE) { + return $proceed($orderItem); + } + + $orderItemOptions = $orderItem->getProductOptions(); + $value = reset($orderItemOptions['bundle_options']); + $value = reset($value['value']); + + return $value['title']; + } +} diff --git a/InventoryBundleProduct/composer.json b/InventoryBundleProduct/composer.json index 02ccf4fd9f2b..06c7b81675f3 100644 --- a/InventoryBundleProduct/composer.json +++ b/InventoryBundleProduct/composer.json @@ -4,7 +4,12 @@ "require": { "php": "~7.1.3||~7.2.0||~7.3.0", "magento/framework": "*", - "magento/module-bundle": "*" + "magento/module-bundle": "*", + "magento/module-catalog": "*", + "magento/module-inventory-catalog-api": "*", + "magento/module-inventory-sales-api": "*", + "magento/module-sales": "*", + "magento/module-store": "*" }, "suggest": { "magento/module-inventory-configuration-api": "*" diff --git a/InventoryBundleProduct/etc/di.xml b/InventoryBundleProduct/etc/di.xml index b49148159d7f..361c83ab8392 100644 --- a/InventoryBundleProduct/etc/di.xml +++ b/InventoryBundleProduct/etc/di.xml @@ -7,7 +7,15 @@ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface"> - <plugin name="disable_bundle_type" - type="Magento\InventoryBundleProduct\Plugin\InventoryConfigurationApi\IsSourceItemManagementAllowedForProductType\DisableBundleTypePlugin"/> + <plugin name="disable_bundle_type" type="Magento\InventoryBundleProduct\Plugin\InventoryConfigurationApi\IsSourceItemManagementAllowedForProductType\DisableBundleTypePlugin"/> + </type> + <type name="Magento\Bundle\Model\Product\Type"> + <plugin name="adapt_is_product_salable" type="Magento\InventoryBundleProduct\Plugin\Bundle\Model\Product\Type\AdaptIsSalablePlugin"/> + </type> + <type name="Magento\Bundle\Model\ResourceModel\Selection\Collection"> + <plugin name="adapt_add_quantity_filter" type="Magento\InventoryBundleProduct\Plugin\Bundle\Model\ResourceModel\Selection\Collection\AdaptAddQuantityFilterPlugin"/> + </type> + <type name="Magento\InventorySalesApi\Model\GetSkuFromOrderItemInterface"> + <plugin name="get_bundle_selection_sku_from_order" type="Magento\InventoryBundleProduct\Plugin\InventorySalesApi\Model\GetSkuFromOrderItem\AdaptGetSkuFromOrderItemPlugin"/> </type> </config> diff --git a/InventoryBundleProductAdminUi/Model/ProcessSourceItemsForSku.php b/InventoryBundleProductAdminUi/Model/ProcessSourceItemsForSku.php new file mode 100644 index 000000000000..8775f0185929 --- /dev/null +++ b/InventoryBundleProductAdminUi/Model/ProcessSourceItemsForSku.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Model; + +use Magento\Framework\Exception\InputException; +use Magento\InventoryApi\Api\Data\SourceItemInterface; +use Magento\InventoryApi\Api\GetSourceItemsBySkuInterface; +use Magento\InventoryCatalogAdminUi\Observer\SourceItemsProcessor; +use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface; + +/** + * Process source items for given bundle selection service. + */ +class ProcessSourceItemsForSku +{ + /** + * @var GetSourceItemsBySkuInterface + */ + private $getSourceItemsBySku; + + /** + * @var SourceItemsProcessor + */ + private $sourceItemsProcessor; + + /** + * @var DefaultSourceProviderInterface + */ + private $defaultSourceProvider; + + /** + * @param GetSourceItemsBySkuInterface $getSourceItemsBySku + * @param SourceItemsProcessor $sourceItemsProcessor + * @param DefaultSourceProviderInterface $defaultSourceProvider + */ + public function __construct( + GetSourceItemsBySkuInterface $getSourceItemsBySku, + SourceItemsProcessor $sourceItemsProcessor, + DefaultSourceProviderInterface $defaultSourceProvider + ) { + $this->getSourceItemsBySku = $getSourceItemsBySku; + $this->sourceItemsProcessor = $sourceItemsProcessor; + $this->defaultSourceProvider = $defaultSourceProvider; + } + + /** + * Process source items for given bundle selection sku. + * + * @param string $sku + * @throws InputException + */ + public function execute(string $sku) + { + $processData = []; + + foreach ($this->getSourceItemsBySku->execute($sku) as $sourceItem) { + if ($sourceItem->getSourceCode() === $this->defaultSourceProvider->getCode()) { + continue; + } + $processData[] = [ + SourceItemInterface::SOURCE_CODE => $sourceItem->getSourceCode(), + SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), + SourceItemInterface::STATUS => $sourceItem->getStatus(), + ]; + } + + if (!empty($processData)) { + $this->sourceItemsProcessor->process($sku, $processData); + } + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionBySkuPlugin.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionBySkuPlugin.php new file mode 100644 index 000000000000..819a0cc8588e --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionBySkuPlugin.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement; + +use Magento\Bundle\Api\Data\LinkInterface; +use Magento\Bundle\Api\ProductLinkManagementInterface; +use Magento\Framework\Exception\InputException; +use Magento\InventoryBundleProductAdminUi\Model\ProcessSourceItemsForSku; + +/** + * Process source items after bundle link has been added by product sku plugin. + */ +class ProcessSourceItemsAfterAddBundleSelectionBySkuPlugin +{ + /** + * @var ProcessSourceItemsForSku + */ + private $processSourceItemsForSku; + + /** + * @param ProcessSourceItemsForSku $processSourceItemsForSku + */ + public function __construct(ProcessSourceItemsForSku $processSourceItemsForSku) + { + $this->processSourceItemsForSku = $processSourceItemsForSku; + } + + /** + * Process source items after bundle selection has been added by product sku. + * + * @param ProductLinkManagementInterface $subject + * @param int $result + * @param string $sku + * @param int $optionId + * @param LinkInterface $linkedProduct + * @return int + * @throws InputException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterAddChildByProductSku( + ProductLinkManagementInterface $subject, + int $result, + $sku, + $optionId, + LinkInterface $linkedProduct + ): int { + $this->processSourceItemsForSku->execute((string)$linkedProduct->getSku()); + + return $result; + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionPlugin.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionPlugin.php new file mode 100644 index 000000000000..da395ffa6f44 --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterAddBundleSelectionPlugin.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement; + +use Magento\Bundle\Api\Data\LinkInterface; +use Magento\Bundle\Api\ProductLinkManagementInterface; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\Exception\InputException; +use Magento\InventoryBundleProductAdminUi\Model\ProcessSourceItemsForSku; + +/** + * Process source items after bundle link has been added plugin. + */ +class ProcessSourceItemsAfterAddBundleSelectionPlugin +{ + /** + * @var ProcessSourceItemsForSku + */ + private $processSourceItemsForSku; + + /** + * @param ProcessSourceItemsForSku $processSourceItemsForSku + */ + public function __construct(ProcessSourceItemsForSku $processSourceItemsForSku) + { + $this->processSourceItemsForSku = $processSourceItemsForSku; + } + + /** + * Process source items after selection has been added to bundle product. + * + * @param ProductLinkManagementInterface $subject + * @param int $result + * @param ProductInterface $product + * @param int $optionId + * @param LinkInterface $linkedProduct + * @return int + * @throws InputException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterAddChild( + ProductLinkManagementInterface $subject, + int $result, + ProductInterface $product, + $optionId, + LinkInterface $linkedProduct + ): int { + $this->processSourceItemsForSku->execute((string)$linkedProduct->getSku()); + + return $result; + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterRemoveBundleSelectionPlugin.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterRemoveBundleSelectionPlugin.php new file mode 100644 index 000000000000..d83b865cc405 --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterRemoveBundleSelectionPlugin.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement; + +use Magento\Bundle\Api\ProductLinkManagementInterface; +use Magento\Framework\Exception\InputException; +use Magento\InventoryBundleProductAdminUi\Model\ProcessSourceItemsForSku; + +/** + * Process source items after bundle link has been removed plugin. + */ +class ProcessSourceItemsAfterRemoveBundleSelectionPlugin +{ + /** + * @var ProcessSourceItemsForSku + */ + private $processSourceItemsForSku; + + /** + * @param ProcessSourceItemsForSku $processSourceItemsForSku + */ + public function __construct(ProcessSourceItemsForSku $processSourceItemsForSku) + { + $this->processSourceItemsForSku = $processSourceItemsForSku; + } + + /** + * Process source items after bundle selection has been removed. + * + * @param ProductLinkManagementInterface $subject + * @param bool $result + * @param string $sku + * @param string $optionId + * @param string $childSku + * @return bool + * @throws InputException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterRemoveChild( + ProductLinkManagementInterface $subject, + bool $result, + $sku, + $optionId, + $childSku + ): bool { + $this->processSourceItemsForSku->execute((string)$childSku); + + return $result; + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterSaveBundleSelectionPlugin.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterSaveBundleSelectionPlugin.php new file mode 100644 index 000000000000..280681d67439 --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Model/LinkManagement/ProcessSourceItemsAfterSaveBundleSelectionPlugin.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement; + +use Magento\Bundle\Api\Data\LinkInterface; +use Magento\Bundle\Api\ProductLinkManagementInterface; +use Magento\Framework\Exception\InputException; +use Magento\InventoryBundleProductAdminUi\Model\ProcessSourceItemsForSku; + +/** + * Process source items after bundle link has been saved plugin. + */ +class ProcessSourceItemsAfterSaveBundleSelectionPlugin +{ + /** + * @var ProcessSourceItemsForSku + */ + private $processSourceItemsForSku; + + /** + * @param ProcessSourceItemsForSku $processSourceItemsForSku + */ + public function __construct(ProcessSourceItemsForSku $processSourceItemsForSku) + { + $this->processSourceItemsForSku = $processSourceItemsForSku; + } + + /** + * Process source items after bundle selection has been updated. + * + * @param ProductLinkManagementInterface $subject + * @param bool $result + * @param string $sku + * @param LinkInterface $linkedProduct + * @return bool + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws InputException + */ + public function afterSaveChild( + ProductLinkManagementInterface $subject, + bool $result, + $sku, + LinkInterface $linkedProduct + ): bool { + $this->processSourceItemsForSku->execute((string)$linkedProduct->getSku()); + + return $result; + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddColumnQuantityPerSource.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddColumnQuantityPerSource.php new file mode 100644 index 000000000000..657e010c45a7 --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddColumnQuantityPerSource.php @@ -0,0 +1,85 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Ui\DataProvider\Product\Form; + +use Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider; +use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface; +use Magento\Ui\Component\Form\Element\DataType\Text; +use Magento\Ui\Component\Listing\Columns\Column; + +/** + * In multi source mode add column "Quantity Per Source". + */ +class AddColumnQuantityPerSource +{ + /** + * @var IsSingleSourceModeInterface + */ + private $isSingleSourceMode; + + /** + * @param IsSingleSourceModeInterface $isSingleSourceMode + */ + public function __construct( + IsSingleSourceModeInterface $isSingleSourceMode + ) { + $this->isSingleSourceMode = $isSingleSourceMode; + } + + /** + * Add column "Quantity Per Source" to modal window for multi source mode. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @param BundleDataProvider $subject + * @param array $result + * @return array + */ + public function afterGetMeta(BundleDataProvider $subject, array $result): array + { + if (!$this->isSingleSourceMode->execute()) { + $result = array_replace_recursive($result, [ + 'product_columns' => [ + 'children' => [ + 'quantity_per_source' => $this->getQuantityPerSourceMeta(), + 'qty' => [ + 'arguments' => null, + ], + ], + ], + ]); + } + + return $result; + } + + /** + * Config for column "Quantity Per Source". + * + * @return array + */ + private function getQuantityPerSourceMeta(): array + { + $jsComponent = 'Magento_InventoryBundleProductAdminUi/js/form/element/grid-column-quantity-per-source'; + + return [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'filter' => false, + 'sortable' => false, + 'label' => __('Quantity per Source'), + 'dataType' => Text::NAME, + 'componentType' => Column::NAME, + 'component' => $jsComponent, + ] + ], + ], + ]; + } +} diff --git a/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php b/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php new file mode 100644 index 000000000000..a6372158174b --- /dev/null +++ b/InventoryBundleProductAdminUi/Plugin/Bundle/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Ui\DataProvider\Product\Form; + +use Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\InventoryCatalogAdminUi\Model\GetQuantityInformationPerSourceBySkus; +use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface; + +/** + * On multi source mode add data "Quantity Per Source" to loaded items for modal window. + */ +class AddQuantityPerSourceToProductsData +{ + /** + * @var IsSingleSourceModeInterface + */ + private $isSingleSourceMode; + + /** + * @var GetQuantityInformationPerSourceBySkus + */ + private $getQuantityInformationPerSourceBySkus; + + /** + * @param IsSingleSourceModeInterface $isSingleSourceMode + * @param GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus + */ + public function __construct( + IsSingleSourceModeInterface $isSingleSourceMode, + GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus + ) { + $this->isSingleSourceMode = $isSingleSourceMode; + $this->getQuantityInformationPerSourceBySkus = $getQuantityInformationPerSourceBySkus; + } + + /** + * Add data "Quantity Per Source" to items on modal window for multi source mode. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @param BundleDataProvider $subject + * @param array $result + * @return array + * @throws NoSuchEntityException + */ + public function afterGetData(BundleDataProvider $subject, array $result): array + { + if ($this->isSingleSourceMode->execute()) { + return $result; + } + + $skus = []; + foreach ($result['items'] as $itemData) { + $skus[] = $itemData['sku']; + } + + $sourceItemsData = $this->getQuantityInformationPerSourceBySkus->execute($skus); + + foreach ($result['items'] as &$productLinkData) { + $productLinkData['quantity_per_source'] = $sourceItemsData[$productLinkData['sku']] ?? []; + } + + return $result; + } +} diff --git a/InventoryBundleProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryBundlePanel.php b/InventoryBundleProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryBundlePanel.php new file mode 100644 index 000000000000..5146f088c79f --- /dev/null +++ b/InventoryBundleProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryBundlePanel.php @@ -0,0 +1,179 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductAdminUi\Ui\DataProvider\Product\Form\Modifier; + +use Magento\Bundle\Model\Product\Type; +use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel; +use Magento\Catalog\Model\Locator\LocatorInterface; +use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Stdlib\ArrayManager; +use Magento\InventoryCatalogAdminUi\Model\GetQuantityInformationPerSourceBySkus; +use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface; +use Magento\Ui\Component\Form\Element\Input; + +/** + * Add column "Quantity Per Source" and sources data to bundle product options grid. + */ +class InventoryBundlePanel extends AbstractModifier +{ + /** + * @var IsSingleSourceModeInterface + */ + private $isSingleSourceMode; + + /** + * @var LocatorInterface + */ + private $locator; + + /** + * @var GetQuantityInformationPerSourceBySkus + */ + private $getQuantityInformationPerSourceBySkus; + + /** + * @var ArrayManager + */ + private $arrayManager; + + /** + * @param IsSingleSourceModeInterface $isSingleSourceMode + * @param LocatorInterface $locator + * @param GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus + * @param ArrayManager $arrayManager + */ + public function __construct( + IsSingleSourceModeInterface $isSingleSourceMode, + LocatorInterface $locator, + GetQuantityInformationPerSourceBySkus $getQuantityInformationPerSourceBySkus, + ArrayManager $arrayManager + ) { + $this->isSingleSourceMode = $isSingleSourceMode; + $this->locator = $locator; + $this->getQuantityInformationPerSourceBySkus = $getQuantityInformationPerSourceBySkus; + $this->arrayManager = $arrayManager; + } + + /** + * Add source data to linked to bundle product items only for multi source mode. + * + * @param array $data + * @return array + * @throws NoSuchEntityException + */ + public function modifyData(array $data) + { + $product = $this->locator->getProduct(); + $modelId = (int)$product->getId(); + if ($product->getTypeId() === Type::TYPE_CODE + && $modelId + && isset($data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]) + && !$this->isSingleSourceMode->execute() + ) { + $data = $this->addQuantityPerSource($data, $modelId); + } + + return $data; + } + + /** + * Add column "Quantity Per Source" to bundle selections. + * + * @param array $meta + * @return array + */ + public function modifyMeta(array $meta): array + { + if ($this->locator->getProduct()->getTypeId() === Type::TYPE_CODE + && !$this->isSingleSourceMode->execute() + ) { + $path = $this->arrayManager->findPath('bundle_selections', $meta, null); + $meta = $this->arrayManager->merge( + $path, + $meta, + [ + 'children' => [ + 'record' => [ + 'children' => [ + 'source_code' => [ + 'arguments' => [ + 'data' => [ + 'config' => $this->getQtyPerSourceConfig(), + ], + ], + ], + ], + + ], + ], + 'arguments' => [ + 'data' => [ + 'config' => [ + 'map' => [ + 'quantity_per_source' => 'quantity_per_source', + ], + ], + ], + ], + ] + ); + } + + return $meta; + } + + /** + * Config for field "Quantity Per Source" on dynamic rows. + * + * @return array + */ + private function getQtyPerSourceConfig(): array + { + return [ + 'componentType' => 'text', + 'component' => 'Magento_InventoryBundleProductAdminUi/js/form/element/quantity-per-source', + 'template' => 'ui/form/field', + 'dataScope' => 'quantity_per_source', + 'label' => __('Quantity Per Source'), + 'formElement' => Input::NAME, + 'sortOrder' => 95, + ]; + } + + /** + * Add quantity per source to data. + * + * @param array $data + * @param int $modelId + * @return array + * @throws NoSuchEntityException + */ + private function addQuantityPerSource(array $data, int $modelId): array + { + $selectionSkus = []; + $bundleOptions = &$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS]; + foreach ($bundleOptions as $option) { + if (isset($option['bundle_selections'])) { + foreach ($option['bundle_selections'] as $selection) { + $selectionSkus[] = $selection['sku']; + } + } + } + $sourceItemsData = $this->getQuantityInformationPerSourceBySkus->execute($selectionSkus); + foreach ($bundleOptions as &$option) { + if (isset($option['bundle_selections'])) { + foreach ($option['bundle_selections'] as &$selection) { + $selection['quantity_per_source'] = $sourceItemsData[$selection['sku']] ?? []; + } + } + } + + return $data; + } +} diff --git a/InventoryBundleProductAdminUi/composer.json b/InventoryBundleProductAdminUi/composer.json index f0d66d0076b9..ffd217a80b2c 100644 --- a/InventoryBundleProductAdminUi/composer.json +++ b/InventoryBundleProductAdminUi/composer.json @@ -3,7 +3,13 @@ "description": "N/A", "require": { "php": "~7.1.3||~7.2.0||~7.3.0", - "magento/framework": "*" + "magento/framework": "*", + "magento/module-bundle": "*", + "magento/module-catalog": "*", + "magento/module-ui": "*", + "magento/module-inventory-api": "*", + "magento/module-inventory-catalog-api": "*", + "magento/module-inventory-catalog-admin-ui": "*" }, "suggest": { "magento/module-inventory-configuration-api": "*" diff --git a/InventoryBundleProductAdminUi/etc/adminhtml/di.xml b/InventoryBundleProductAdminUi/etc/adminhtml/di.xml new file mode 100644 index 000000000000..872be0339588 --- /dev/null +++ b/InventoryBundleProductAdminUi/etc/adminhtml/di.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool"> + <arguments> + <argument name="modifiers" xsi:type="array"> + <item name="inventoryBundlePanel" xsi:type="array"> + <item name="class" xsi:type="string">Magento\InventoryBundleProductAdminUi\Ui\DataProvider\Product\Form\Modifier\InventoryBundlePanel</item> + <item name="sortOrder" xsi:type="number">310</item> + </item> + </argument> + </arguments> + </virtualType> + <type name="Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider"> + <plugin name="append_quantity_per_source" type="Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Ui\DataProvider\Product\Form\AddQuantityPerSourceToProductsData" /> + <plugin name="append_column_quantity_per_source" type="Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Ui\DataProvider\Product\Form\AddColumnQuantityPerSource" /> + </type> + <type name="Magento\Bundle\Api\ProductLinkManagementInterface"> + <plugin name="process_source_items_after_add_bundle_selection" type="Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement\ProcessSourceItemsAfterAddBundleSelectionPlugin"/> + <plugin name="process_source_items_after_save_bundle_selection" type="Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement\ProcessSourceItemsAfterSaveBundleSelectionPlugin"/> + <plugin name="process_source_items_after_remove_bundle_selection" type="Magento\InventoryBundleProductAdminUi\Plugin\Bundle\Model\LinkManagement\ProcessSourceItemsAfterRemoveBundleSelectionPlugin"/> + </type> +</config> diff --git a/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/grid-column-quantity-per-source.js b/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/grid-column-quantity-per-source.js new file mode 100644 index 000000000000..2c9afa092c05 --- /dev/null +++ b/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/grid-column-quantity-per-source.js @@ -0,0 +1,28 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + 'mage/translate', + 'Magento_Ui/js/grid/columns/column' +], function ($t, Column) { + 'use strict'; + + return Column.extend({ + defaults: { + bodyTmpl: 'Magento_InventoryBundleProductAdminUi/grid/column/quantity-per-source', + itemsToDisplay: 3, + showFullListDescription: $t('Show more...') + }, + + /** + * Get source items from product data. + * + * @param {Object} rowData + * @returns {Array} + */ + getSourceItemsData: function (rowData) { + return rowData['quantity_per_source']; + } + }); +}); diff --git a/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/quantity-per-source.js b/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/quantity-per-source.js new file mode 100644 index 000000000000..f4e5aba75e97 --- /dev/null +++ b/InventoryBundleProductAdminUi/view/adminhtml/web/js/form/element/quantity-per-source.js @@ -0,0 +1,45 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + 'mage/translate', + 'Magento_Ui/js/form/element/abstract' +], function ($t, Abstract) { + 'use strict'; + + return Abstract.extend({ + defaults: { + elementTmpl: 'Magento_InventoryBundleProductAdminUi/dynamic-rows/cells/cell-source', + itemsToDisplay: 3, + isFullList: true, + showFullListDescription: $t('Show more...'), + listens: { + value: 'updateItems' + } + }, + + /** + * Observe elements. + * + * @returns {exports} + */ + initObservable: function () { + this._super() + .observe(['items', 'isFullList']); + + return this; + }, + + /** + * Prepare data to use. + * + * @param {Object} data + * @private + */ + updateItems: function (data) { + this.isFullList(data.length > this.itemsToDisplay); + this.isFullList() ? this.items(data.slice(0, this.itemsToDisplay)) : this.items(data); + } + }); +}); diff --git a/InventoryBundleProductAdminUi/view/adminhtml/web/template/dynamic-rows/cells/cell-source.html b/InventoryBundleProductAdminUi/view/adminhtml/web/template/dynamic-rows/cells/cell-source.html new file mode 100644 index 000000000000..db174ecb9349 --- /dev/null +++ b/InventoryBundleProductAdminUi/view/adminhtml/web/template/dynamic-rows/cells/cell-source.html @@ -0,0 +1,37 @@ +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<div class="control-table-text" attr="'data-tooltip-trigger': ++ko.uid"> + <!-- ko foreach: { data: $data.items, as: 'item' } --> + <div> + <span visible="false" text="item.source_code"></span> + <strong text="item.source_name"></strong>: + <span text="item.quantity"></span> + </div> + <!-- /ko --> + <div if="$data.isFullList()"> + <a href="#" attr="'data-tooltip-trigger': ++ko.uid" text="$data.showFullListDescription"/> + </div> +</div> +<div tooltip=" + trigger: '[data-tooltip-trigger=' + ko.uid + ']', + action: 'click', + closeOnScroll: false, + delay: 0, + position: 'top', + step: 30, + track: false, + strict: true, + closeButton: true"> + <div> + <div class="data-tooltip-title">Sources</div> + <div class="data-tooltip-content"> + <!-- ko foreach: { data: value, as: 'item' } --> + <div><strong text="item.source_name"></strong>: <span text="item.quantity"></span></div> + <!-- /ko --> + </div> + </div> +</div> diff --git a/InventoryBundleProductAdminUi/view/adminhtml/web/template/grid/column/quantity-per-source.html b/InventoryBundleProductAdminUi/view/adminhtml/web/template/grid/column/quantity-per-source.html new file mode 100644 index 000000000000..905974e0ea8a --- /dev/null +++ b/InventoryBundleProductAdminUi/view/adminhtml/web/template/grid/column/quantity-per-source.html @@ -0,0 +1,15 @@ +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<div class="control-table-text" attr="'data-tooltip-trigger': ++ko.uid"> + <!-- ko foreach: { data: $col.getSourceItemsData($row()), as: 'item' } --> + <div> + <span visible="false" text="item.source_code"></span> + <strong text="item.source_name"></strong>: + <span text="item.quantity"></span> + </div> + <!-- /ko --> +</div> diff --git a/InventoryBundleProductIndexer/Indexer/SelectBuilder.php b/InventoryBundleProductIndexer/Indexer/SelectBuilder.php new file mode 100644 index 000000000000..dc78c4bfdb8b --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/SelectBuilder.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer; + +use Exception; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Select; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\InventoryIndexer\Indexer\IndexStructure; +use Magento\InventoryIndexer\Indexer\InventoryIndexer; +use Magento\InventoryMultiDimensionalIndexerApi\Model\Alias; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexNameBuilder; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexNameResolverInterface; + +/** + * Get bundle product for given stock select builder. + */ +class SelectBuilder +{ + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @var IndexNameBuilder + */ + private $indexNameBuilder; + + /** + * @var IndexNameResolverInterface + */ + private $indexNameResolver; + + /** + * @var MetadataPool + */ + private $metadataPool; + + /** + * @param ResourceConnection $resourceConnection + * @param IndexNameBuilder $indexNameBuilder + * @param IndexNameResolverInterface $indexNameResolver + * @param MetadataPool $metadataPool + */ + public function __construct( + ResourceConnection $resourceConnection, + IndexNameBuilder $indexNameBuilder, + IndexNameResolverInterface $indexNameResolver, + MetadataPool $metadataPool + ) { + $this->resourceConnection = $resourceConnection; + $this->indexNameBuilder = $indexNameBuilder; + $this->indexNameResolver = $indexNameResolver; + $this->metadataPool = $metadataPool; + } + + /** + * Prepare select for getting bundle products on given stock. + * + * @param int $stockId + * @return Select + * @throws Exception + */ + public function execute(int $stockId): Select + { + $connection = $this->resourceConnection->getConnection(); + + $indexName = $this->indexNameBuilder + ->setIndexId(InventoryIndexer::INDEXER_ID) + ->addDimension('stock_', (string)$stockId) + ->setAlias(Alias::ALIAS_MAIN) + ->build(); + + $indexTableName = $this->indexNameResolver->resolveName($indexName); + + $metadata = $this->metadataPool->getMetadata(ProductInterface::class); + $linkField = $metadata->getLinkField(); + + $select = $connection->select() + ->from( + ['stock' => $indexTableName], + [ + IndexStructure::SKU => 'parent_product_entity.sku', + IndexStructure::QUANTITY => 'SUM(stock.quantity)', + IndexStructure::IS_SALABLE => 'MAX(stock.is_salable)', + ] + )->joinInner( + ['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], + 'product_entity.sku = stock.sku', + [] + )->joinInner( + ['parent_link' => $this->resourceConnection->getTableName('catalog_product_bundle_selection')], + 'parent_link.product_id = product_entity.entity_id', + [] + )->joinInner( + ['parent_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], + 'parent_product_entity.' . $linkField . ' = parent_link.parent_product_id', + [] + ) + ->group(['parent_product_entity.sku']); + + return $select; + } +} diff --git a/InventoryBundleProductIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php b/InventoryBundleProductIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php new file mode 100644 index 000000000000..c6b83c5a22bd --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer\SourceItem; + +use Magento\Framework\App\ResourceConnection; +use Magento\InventoryBundleProductIndexer\Indexer\SelectBuilder; +use Magento\InventoryIndexer\Indexer\IndexStructure; + +/** + * Returns all data for the index by source item list condition. + */ +class IndexDataBySkuListProvider +{ + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @var SelectBuilder + */ + private $selectBuilder; + + /** + * @param ResourceConnection $resourceConnection + * @param SelectBuilder $selectBuilder + */ + public function __construct( + ResourceConnection $resourceConnection, + SelectBuilder $selectBuilder + ) { + $this->resourceConnection = $resourceConnection; + $this->selectBuilder = $selectBuilder; + } + + /** + * Get index data by stock id and sku list. + * + * @param int $stockId + * @param array $skuList + * @return \ArrayIterator + * @throws \Exception + */ + public function execute(int $stockId, array $skuList): \ArrayIterator + { + $select = $this->selectBuilder->execute($stockId); + if (count($skuList)) { + $select->where('stock.' . IndexStructure::SKU . ' IN (?)', $skuList); + } + $connection = $this->resourceConnection->getConnection(); + + return new \ArrayIterator($connection->fetchAll($select)); + } +} diff --git a/InventoryBundleProductIndexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php b/InventoryBundleProductIndexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php new file mode 100644 index 000000000000..2f138b7ac29a --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php @@ -0,0 +1,143 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer\SourceItem; + +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\InventoryApi\Api\Data\SourceItemInterface; +use Magento\InventoryApi\Api\Data\StockSourceLinkInterface; +use Magento\InventoryIndexer\Indexer\SourceItem\SkuListInStock; +use Magento\InventoryIndexer\Indexer\SourceItem\SkuListInStockFactory; + +/** + * Returns relations between stock and sku list + */ +class SiblingSkuListInStockProvider +{ + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @var SkuListInStockFactory + */ + private $skuListInStockFactory; + + /** + * @var MetadataPool + */ + private $metadataPool; + + /** + * @var string + */ + private $tableNameSourceItem; + + /** + * @var string + */ + private $tableNameStockSourceLink; + + /** + * @param ResourceConnection $resourceConnection + * @param SkuListInStockFactory $skuListInStockFactory + * @param MetadataPool $metadataPool + * @param string $tableNameSourceItem + * @param string $tableNameStockSourceLink + */ + public function __construct( + ResourceConnection $resourceConnection, + SkuListInStockFactory $skuListInStockFactory, + MetadataPool $metadataPool, + $tableNameSourceItem, + $tableNameStockSourceLink + ) { + $this->resourceConnection = $resourceConnection; + $this->skuListInStockFactory = $skuListInStockFactory; + $this->metadataPool = $metadataPool; + $this->tableNameSourceItem = $tableNameSourceItem; + $this->tableNameStockSourceLink = $tableNameStockSourceLink; + } + + /** + * Returns all assigned Stock ids by given Source Item ids + * + * @param int[] $sourceItemIds + * @return SkuListInStock[] List of stock id to sku1,sku2 assignment + * @throws \Exception + */ + public function execute(array $sourceItemIds): array + { + $connection = $this->resourceConnection->getConnection(); + $sourceStockLinkTable = $this->resourceConnection->getTableName($this->tableNameStockSourceLink); + $sourceItemTable = $this->resourceConnection->getTableName($this->tableNameSourceItem); + + $metadata = $this->metadataPool->getMetadata(ProductInterface::class); + $linkField = $metadata->getIdentifierField(); + $items = []; + + $select = $connection + ->select() + ->from( + ['source_item' => $sourceItemTable], + [SourceItemInterface::SKU => 'sibling_product_entity.' . SourceItemInterface::SKU] + )->joinInner( + ['stock_source_link' => $sourceStockLinkTable], + sprintf( + 'source_item.%s = stock_source_link.%s', + SourceItemInterface::SOURCE_CODE, + StockSourceLinkInterface::SOURCE_CODE + ), + [StockSourceLinkInterface::STOCK_ID] + )->joinInner( + ['child_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], + 'child_product_entity.sku = source_item.sku', + [] + )->joinInner( + ['sibling_link' => $this->resourceConnection->getTableName('catalog_product_bundle_selection')], + 'sibling_link.product_id = child_product_entity.' . $linkField, + [] + )->joinInner( + ['sibling_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], + 'sibling_product_entity.' . $linkField . ' = sibling_link.product_id', + [] + )->where( + 'source_item.source_item_id IN (?)', + $sourceItemIds + ); + + $dbStatement = $connection->query($select); + while ($item = $dbStatement->fetch()) { + $items[$item[StockSourceLinkInterface::STOCK_ID]][$item[SourceItemInterface::SKU]] = + $item[SourceItemInterface::SKU]; + } + + return $this->getStockIdToSkuList($items); + } + + /** + * Return the assigned stock id to sku list. + * + * @param array $items + * @return SkuListInStock[] + */ + private function getStockIdToSkuList(array $items): array + { + $skuListInStockList = []; + foreach ($items as $stockId => $skuList) { + $skuListInStock = $this->skuListInStockFactory->create(); + $skuListInStock->setStockId((int)$stockId); + $skuListInStock->setSkuList($skuList); + $skuListInStockList[] = $skuListInStock; + } + + return $skuListInStockList; + } +} diff --git a/InventoryBundleProductIndexer/Indexer/SourceItem/SourceItemIndexer.php b/InventoryBundleProductIndexer/Indexer/SourceItem/SourceItemIndexer.php new file mode 100644 index 000000000000..2c0d805ec8f9 --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/SourceItem/SourceItemIndexer.php @@ -0,0 +1,131 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer\SourceItem; + +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\Exception\StateException; +use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; +use Magento\InventoryIndexer\Indexer\InventoryIndexer; +use Magento\InventoryMultiDimensionalIndexerApi\Model\Alias; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexHandlerInterface; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexNameBuilder; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexStructureInterface; + +/** + * Bundle source items indexer. + */ +class SourceItemIndexer +{ + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @var IndexNameBuilder + */ + private $indexNameBuilder; + + /** + * @var IndexHandlerInterface + */ + private $indexHandler; + + /** + * @var IndexDataBySkuListProvider + */ + private $indexDataBySkuListProvider; + + /** + * @var IndexStructureInterface + */ + private $indexStructure; + + /** + * @var SiblingSkuListInStockProvider + */ + private $siblingSkuListInStockProvider; + + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + /** + * @param ResourceConnection $resourceConnection + * @param IndexNameBuilder $indexNameBuilder + * @param IndexHandlerInterface $indexHandler + * @param IndexStructureInterface $indexStructure + * @param IndexDataBySkuListProvider $indexDataBySkuListProvider + * @param SiblingSkuListInStockProvider $siblingSkuListInStockProvider + * @param DefaultStockProviderInterface $defaultStockProvider + */ + public function __construct( + ResourceConnection $resourceConnection, + IndexNameBuilder $indexNameBuilder, + IndexHandlerInterface $indexHandler, + IndexStructureInterface $indexStructure, + IndexDataBySkuListProvider $indexDataBySkuListProvider, + SiblingSkuListInStockProvider $siblingSkuListInStockProvider, + DefaultStockProviderInterface $defaultStockProvider + ) { + $this->resourceConnection = $resourceConnection; + $this->indexNameBuilder = $indexNameBuilder; + $this->indexHandler = $indexHandler; + $this->indexDataBySkuListProvider = $indexDataBySkuListProvider; + $this->indexStructure = $indexStructure; + $this->siblingSkuListInStockProvider = $siblingSkuListInStockProvider; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * Reindex list of bundle source items. + * + * @param array $sourceItemIds + * @return void + * @throws StateException + * @throws \Exception + */ + public function executeList(array $sourceItemIds): void + { + $skuListInStockList = $this->siblingSkuListInStockProvider->execute($sourceItemIds); + + foreach ($skuListInStockList as $skuListInStock) { + $stockId = $skuListInStock->getStockId(); + + if ($this->defaultStockProvider->getId() === $stockId) { + continue; + } + $skuList = $skuListInStock->getSkuList(); + + $mainIndexName = $this->indexNameBuilder + ->setIndexId(InventoryIndexer::INDEXER_ID) + ->addDimension('stock_', (string)$stockId) + ->setAlias(Alias::ALIAS_MAIN) + ->build(); + + if (!$this->indexStructure->isExist($mainIndexName, ResourceConnection::DEFAULT_CONNECTION)) { + $this->indexStructure->create($mainIndexName, ResourceConnection::DEFAULT_CONNECTION); + } + + $indexData = $this->indexDataBySkuListProvider->execute($stockId, $skuList); + + $this->indexHandler->cleanIndex( + $mainIndexName, + $indexData, + ResourceConnection::DEFAULT_CONNECTION + ); + + $this->indexHandler->saveIndex( + $mainIndexName, + $indexData, + ResourceConnection::DEFAULT_CONNECTION + ); + } + } +} diff --git a/InventoryBundleProductIndexer/Indexer/Stock/IndexDataByStockIdProvider.php b/InventoryBundleProductIndexer/Indexer/Stock/IndexDataByStockIdProvider.php new file mode 100644 index 000000000000..f2c35d9f2f72 --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/Stock/IndexDataByStockIdProvider.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer\Stock; + +use Magento\Framework\App\ResourceConnection; +use Magento\InventoryBundleProductIndexer\Indexer\SelectBuilder; + +/** + * Bundle products for given stock provider. + */ +class IndexDataByStockIdProvider +{ + /** + * @var SelectBuilder + */ + private $selectBuilder; + + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @param SelectBuilder $selectBuilder + * @param ResourceConnection $resourceConnection + */ + public function __construct(SelectBuilder $selectBuilder, ResourceConnection $resourceConnection) + { + $this->selectBuilder = $selectBuilder; + $this->resourceConnection = $resourceConnection; + } + + /** + * Get bundle products for given stock id. + * + * @param int $stockId + * + * @return \ArrayIterator + * @throws \Exception + */ + public function execute(int $stockId): \ArrayIterator + { + $select = $this->selectBuilder->execute($stockId); + $connection = $this->resourceConnection->getConnection(); + + return new \ArrayIterator($connection->fetchAll($select)); + } +} diff --git a/InventoryBundleProductIndexer/Indexer/StockIndexer.php b/InventoryBundleProductIndexer/Indexer/StockIndexer.php new file mode 100644 index 000000000000..9ffc7e3145e6 --- /dev/null +++ b/InventoryBundleProductIndexer/Indexer/StockIndexer.php @@ -0,0 +1,163 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Indexer; + +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\Exception\StateException; +use Magento\InventoryBundleProductIndexer\Indexer\Stock\IndexDataByStockIdProvider; +use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; +use Magento\InventoryIndexer\Indexer\InventoryIndexer; +use Magento\InventoryIndexer\Indexer\Stock\GetAllStockIds; +use Magento\InventoryIndexer\Indexer\Stock\PrepareIndexDataForClearingIndex; +use Magento\InventoryMultiDimensionalIndexerApi\Model\Alias; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexHandlerInterface; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexNameBuilder; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexStructureInterface; +use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexTableSwitcherInterface; + +/** + * Index bundle products for given stocks. + */ +class StockIndexer +{ + /** + * @var GetAllStockIds + */ + private $getAllStockIds; + + /** + * @var IndexStructureInterface + */ + private $indexStructure; + + /** + * @var IndexHandlerInterface + */ + private $indexHandler; + + /** + * @var IndexNameBuilder + */ + private $indexNameBuilder; + + /** + * @var IndexDataByStockIdProvider + */ + private $indexDataByStockIdProvider; + + /** + * @var IndexTableSwitcherInterface + */ + private $indexTableSwitcher; + + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + /** + * @var PrepareIndexDataForClearingIndex + */ + private $prepareIndexDataForClearingIndex; + + /** + * $indexStructure is reserved name for construct variable in index internal mechanism. + * + * @param GetAllStockIds $getAllStockIds + * @param IndexStructureInterface $indexStructure + * @param IndexHandlerInterface $indexHandler + * @param IndexNameBuilder $indexNameBuilder + * @param IndexDataByStockIdProvider $indexDataByStockIdProvider + * @param IndexTableSwitcherInterface $indexTableSwitcher + * @param DefaultStockProviderInterface $defaultStockProvider + * @param PrepareIndexDataForClearingIndex $prepareIndexDataForClearingIndex + */ + public function __construct( + GetAllStockIds $getAllStockIds, + IndexStructureInterface $indexStructure, + IndexHandlerInterface $indexHandler, + IndexNameBuilder $indexNameBuilder, + IndexDataByStockIdProvider $indexDataByStockIdProvider, + IndexTableSwitcherInterface $indexTableSwitcher, + DefaultStockProviderInterface $defaultStockProvider, + PrepareIndexDataForClearingIndex $prepareIndexDataForClearingIndex + ) { + $this->getAllStockIds = $getAllStockIds; + $this->indexStructure = $indexStructure; + $this->indexHandler = $indexHandler; + $this->indexNameBuilder = $indexNameBuilder; + $this->indexDataByStockIdProvider = $indexDataByStockIdProvider; + $this->indexTableSwitcher = $indexTableSwitcher; + $this->defaultStockProvider = $defaultStockProvider; + $this->prepareIndexDataForClearingIndex = $prepareIndexDataForClearingIndex; + } + + /** + * Index bundle products for all stocks. + * + * @return void + * @throws StateException + */ + public function executeFull() + { + $stockIds = $this->getAllStockIds->execute(); + $this->executeList($stockIds); + } + + /** + * Index bundle products for given stock. + * + * @param int $stockId + * @return void + * @throws StateException + */ + public function executeRow(int $stockId) + { + $this->executeList([$stockId]); + } + + /** + * Index bundle products for given stocks. + * + * @param array $stockIds + * @return void + * @throws StateException + */ + public function executeList(array $stockIds) + { + foreach ($stockIds as $stockId) { + if ($this->defaultStockProvider->getId() === $stockId) { + continue; + } + + $mainIndexName = $this->indexNameBuilder + ->setIndexId(InventoryIndexer::INDEXER_ID) + ->addDimension('stock_', (string)$stockId) + ->setAlias(Alias::ALIAS_MAIN) + ->build(); + + if (!$this->indexStructure->isExist($mainIndexName, ResourceConnection::DEFAULT_CONNECTION)) { + $this->indexStructure->create($mainIndexName, ResourceConnection::DEFAULT_CONNECTION); + } + + $indexData = $this->indexDataByStockIdProvider->execute($stockId); + + $this->indexHandler->cleanIndex( + $mainIndexName, + $this->prepareIndexDataForClearingIndex->execute($indexData), + ResourceConnection::DEFAULT_CONNECTION + ); + + $this->indexHandler->saveIndex( + $mainIndexName, + $indexData, + ResourceConnection::DEFAULT_CONNECTION + ); + } + } +} diff --git a/InventoryBundleProductIndexer/LICENSE.txt b/InventoryBundleProductIndexer/LICENSE.txt new file mode 100644 index 000000000000..36b2459f6aa6 --- /dev/null +++ b/InventoryBundleProductIndexer/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/InventoryBundleProductIndexer/LICENSE_AFL.txt b/InventoryBundleProductIndexer/LICENSE_AFL.txt new file mode 100644 index 000000000000..f39d641b18a1 --- /dev/null +++ b/InventoryBundleProductIndexer/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/InventoryBundleProductIndexer/Plugin/InventoryIndexer/SourceItemIndexerPlugin.php b/InventoryBundleProductIndexer/Plugin/InventoryIndexer/SourceItemIndexerPlugin.php new file mode 100644 index 000000000000..ed664742d8de --- /dev/null +++ b/InventoryBundleProductIndexer/Plugin/InventoryIndexer/SourceItemIndexerPlugin.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer; + +use Magento\Framework\Exception\StateException; +use Magento\InventoryBundleProductIndexer\Indexer\SourceItem\SourceItemIndexer as BundleProductsSourceItemIndexer; +use Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer; + +/** + * Reindex bundle product source items. + */ +class SourceItemIndexerPlugin +{ + /** + * @var BundleProductsSourceItemIndexer + */ + private $bundleProductsSourceItemIndexer; + + /** + * @param BundleProductsSourceItemIndexer $configurableProductsSourceItemIndexer + */ + public function __construct( + BundleProductsSourceItemIndexer $configurableProductsSourceItemIndexer + ) { + $this->bundleProductsSourceItemIndexer = $configurableProductsSourceItemIndexer; + } + + /** + * Reindex source items list for bundle products. + * + * @param SourceItemIndexer $subject + * @param void $result + * @param array $sourceItemIds + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws StateException + */ + public function afterExecuteList( + SourceItemIndexer $subject, + $result, + array $sourceItemIds + ) { + $this->bundleProductsSourceItemIndexer->executeList($sourceItemIds); + } +} diff --git a/InventoryBundleProductIndexer/Plugin/InventoryIndexer/StockIndexerPlugin.php b/InventoryBundleProductIndexer/Plugin/InventoryIndexer/StockIndexerPlugin.php new file mode 100644 index 000000000000..1bd641eaaed7 --- /dev/null +++ b/InventoryBundleProductIndexer/Plugin/InventoryIndexer/StockIndexerPlugin.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer; + +use Magento\Framework\Exception\StateException; +use Magento\InventoryBundleProductIndexer\Indexer\StockIndexer as BundleProductsStockIndexer; +use Magento\InventoryIndexer\Indexer\Stock\StockIndexer; + +/** + * Index bundle products for given stocks plugin. + */ +class StockIndexerPlugin +{ + /** + * @var BundleProductsStockIndexer + */ + private $bundleProductsStockIndexer; + + /** + * @param BundleProductsStockIndexer $bundleProductsStockIndexer + */ + public function __construct( + BundleProductsStockIndexer $bundleProductsStockIndexer + ) { + $this->bundleProductsStockIndexer = $bundleProductsStockIndexer; + } + + /** + * Index bundle products for given stocks. + * + * @param StockIndexer $subject + * @param void $result + * @param array $stockIds + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws StateException + */ + public function afterExecuteList( + StockIndexer $subject, + $result, + array $stockIds + ) { + $this->bundleProductsStockIndexer->executeList($stockIds); + } +} diff --git a/InventoryBundleProductIndexer/README.md b/InventoryBundleProductIndexer/README.md new file mode 100644 index 000000000000..293e89693876 --- /dev/null +++ b/InventoryBundleProductIndexer/README.md @@ -0,0 +1,15 @@ +# InventoryBundleProductIndexer module + +The `InventoryBundleProductIndexer` module integrates inventory management business logic into Magento's indexation logic for bundle products. + +This module is part of the new inventory infrastructure. The +[Inventory Management overview](https://devdocs.magento.com/guides/v2.3/inventory/index.html) +describes the MSI (Multi-Source Inventory) project in more detail. + +## Installation details + +This module is installed as part of Magento Open Source. It cannot be deleted or disabled. + +## Extension points and service contracts + +There are no extension points or service contracts for this module. diff --git a/InventoryBundleProductIndexer/composer.json b/InventoryBundleProductIndexer/composer.json new file mode 100644 index 000000000000..ad2b14142197 --- /dev/null +++ b/InventoryBundleProductIndexer/composer.json @@ -0,0 +1,29 @@ +{ + "name": "magento/module-inventory-bundle-product-indexer", + "description": "N/A", + "require": { + "php": "~7.1.3||~7.2.0||~7.3.0", + "magento/framework": "*", + "magento/module-catalog": "*", + "magento/module-inventory-api": "*", + "magento/module-inventory-catalog-api": "*", + "magento/module-inventory-indexer": "*", + "magento/module-inventory-multi-dimensional-indexer-api": "*" + }, + "suggest": { + "magento/module-inventory": "*" + }, + "type": "magento2-module", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\InventoryBundleProductIndexer\\": "" + } + } +} diff --git a/InventoryBundleProductIndexer/etc/di.xml b/InventoryBundleProductIndexer/etc/di.xml new file mode 100644 index 000000000000..09166a2f440d --- /dev/null +++ b/InventoryBundleProductIndexer/etc/di.xml @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <type name="Magento\InventoryIndexer\Indexer\Stock\StockIndexer"> + <plugin name="bundle_product_index" type="Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\StockIndexerPlugin"/> + </type> + <type name="Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer"> + <plugin name="bundle_product_index" type="Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\SourceItemIndexerPlugin"/> + </type> + <type name="Magento\InventoryBundleProductIndexer\Indexer\Stock\StockIndexer"> + <arguments> + <argument name="indexHandler" xsi:type="object">Magento\InventoryIndexer\Indexer\IndexHandler</argument> + <argument name="indexStructure" xsi:type="object">Magento\InventoryIndexer\Indexer\IndexStructure</argument> + </arguments> + </type> + <type name="Magento\InventoryBundleProductIndexer\Indexer\SourceItem\SourceItemIndexer"> + <arguments> + <argument name="indexHandler" xsi:type="object">Magento\InventoryIndexer\Indexer\IndexHandler</argument> + <argument name="indexStructure" xsi:type="object">Magento\InventoryIndexer\Indexer\IndexStructure</argument> + </arguments> + </type> + <type name="Magento\InventoryBundleProductIndexer\Indexer\SourceItem\SiblingSkuListInStockProvider"> + <arguments> + <argument name="tableNameSourceItem" + xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM</argument> + <argument name="tableNameStockSourceLink" + xsi:type="const">Magento\Inventory\Model\ResourceModel\StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK</argument> + </arguments> + </type> +</config> diff --git a/InventoryBundleProductIndexer/etc/module.xml b/InventoryBundleProductIndexer/etc/module.xml new file mode 100644 index 000000000000..aa84c748e2a2 --- /dev/null +++ b/InventoryBundleProductIndexer/etc/module.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> + <module name="Magento_InventoryBundleProductIndexer"/> +</config> diff --git a/InventoryBundleProductIndexer/registration.php b/InventoryBundleProductIndexer/registration.php new file mode 100644 index 000000000000..a50aff5ea9ef --- /dev/null +++ b/InventoryBundleProductIndexer/registration.php @@ -0,0 +1,12 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +\Magento\Framework\Component\ComponentRegistrar::register( + \Magento\Framework\Component\ComponentRegistrar::MODULE, + 'Magento_InventoryBundleProductIndexer', + __DIR__ +); diff --git a/InventoryCatalog/etc/di.xml b/InventoryCatalog/etc/di.xml index 384bb0713645..dbd9ce4533a3 100644 --- a/InventoryCatalog/etc/di.xml +++ b/InventoryCatalog/etc/di.xml @@ -21,7 +21,7 @@ type="Magento\InventoryCatalog\Plugin\InventoryApi\SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin"/> </type> <type name="Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer"> - <plugin name="priceIndexUpdater" type="Magento\InventoryCatalog\Plugin\InventoryIndexer\Indexer\SourceItem\PriceIndexUpdater" sortOrder="20"/> + <plugin name="priceIndexUpdater" type="Magento\InventoryCatalog\Plugin\InventoryIndexer\Indexer\SourceItem\PriceIndexUpdater"/> </type> <type name="Magento\CatalogInventory\Model\Indexer\ProductPriceIndexFilter"> <plugin name="change_select_for_price_modifier" type="Magento\InventoryCatalog\Plugin\CatalogInventory\Model\Indexer\ModifySelectInProductPriceIndexFilter"/> diff --git a/InventoryCatalogAdminUi/Model/GetQuantityInformationPerSourceBySkus.php b/InventoryCatalogAdminUi/Model/GetQuantityInformationPerSourceBySkus.php new file mode 100644 index 000000000000..4307d8f635fa --- /dev/null +++ b/InventoryCatalogAdminUi/Model/GetQuantityInformationPerSourceBySkus.php @@ -0,0 +1,78 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\InventoryCatalogAdminUi\Model; + +use Magento\Framework\Api\SearchCriteriaBuilderFactory; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\InventoryApi\Api\Data\SourceItemInterface; +use Magento\InventoryApi\Api\SourceItemRepositoryInterface; +use Magento\InventoryApi\Api\SourceRepositoryInterface; + +/** + * Load product source items data by skus. + */ +class GetQuantityInformationPerSourceBySkus +{ + /** + * @var SourceItemRepositoryInterface + */ + private $sourceItemRepository; + + /** + * @var SearchCriteriaBuilderFactory + */ + private $searchCriteriaBuilderFactory; + + /** + * @var SourceRepositoryInterface + */ + private $sourceRepository; + + /** + * @param SourceItemRepositoryInterface $sourceItemRepository + * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory + * @param SourceRepositoryInterface $sourceRepository + */ + public function __construct( + SourceItemRepositoryInterface $sourceItemRepository, + SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory, + SourceRepositoryInterface $sourceRepository + ) { + $this->sourceItemRepository = $sourceItemRepository; + $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory; + $this->sourceRepository = $sourceRepository; + } + + /** + * Get products source items by skus. + * + * @param array $skus + * @return array + * @throws NoSuchEntityException + */ + public function execute(array $skus): array + { + $sourceItemsInformation = []; + + $searchCriteriaBuilder = $this->searchCriteriaBuilderFactory->create(); + $searchCriteria = $searchCriteriaBuilder->addFilter(SourceItemInterface::SKU, $skus, 'in')->create(); + $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); + + foreach ($sourceItems as $sourceItem) { + $source = $this->sourceRepository->get($sourceItem->getSourceCode()); + $sourceItemsInformation[$sourceItem['sku']][] = [ + SourceItemInterface::SOURCE_CODE => $sourceItem->getSourceCode(), + SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), + 'source_name' => $source->getName(), + SourceItemInterface::STATUS => $sourceItem->getStatus(), + ]; + } + + return $sourceItemsInformation; + } +} diff --git a/InventoryGroupedProductAdminUi/Plugin/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php b/InventoryGroupedProductAdminUi/Plugin/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php index e6de2e7166f8..82e00c10f571 100644 --- a/InventoryGroupedProductAdminUi/Plugin/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php +++ b/InventoryGroupedProductAdminUi/Plugin/Ui/DataProvider/Product/Form/AddQuantityPerSourceToProductsData.php @@ -8,8 +8,8 @@ namespace Magento\InventoryGroupedProductAdminUi\Plugin\Ui\DataProvider\Product\Form; use Magento\GroupedProduct\Ui\DataProvider\Product\GroupedProductDataProvider; +use Magento\InventoryCatalogAdminUi\Model\GetQuantityInformationPerSourceBySkus; use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface; -use Magento\InventoryGroupedProductAdminUi\Model\GetQuantityInformationPerSourceBySkus; /** * On multi source mode add data "Quantity Per Source" to loaded items for modal window. diff --git a/InventoryGroupedProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryGroupedPanel.php b/InventoryGroupedProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryGroupedPanel.php index 7f5ce2cd4c9a..7d8e61a51134 100644 --- a/InventoryGroupedProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryGroupedPanel.php +++ b/InventoryGroupedProductAdminUi/Ui/DataProvider/Product/Form/Modifier/InventoryGroupedPanel.php @@ -11,8 +11,8 @@ use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedProductType; use Magento\GroupedProduct\Ui\DataProvider\Product\Form\Modifier\Grouped; +use Magento\InventoryCatalogAdminUi\Model\GetQuantityInformationPerSourceBySkus; use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface; -use Magento\InventoryGroupedProductAdminUi\Model\GetQuantityInformationPerSourceBySkus; use Magento\Ui\Component\Form\Element\Input; /** @@ -93,36 +93,39 @@ public function modifyMeta(array $meta): array if ($this->locator->getProduct()->getTypeId() === GroupedProductType::TYPE_CODE && !$this->isSingleSourceMode->execute() ) { - $meta = array_replace_recursive($meta, [ - 'grouped' => [ - 'children' => [ - 'associated' => [ - 'children' => [ - 'record' => [ - 'children' => [ - 'source_code' => [ - 'arguments' => [ - 'data' => [ - 'config' => $this->getQuantityPerSourceConfig() - ] - ] - ] - ] - ] + $meta = array_replace_recursive( + $meta, + [ + 'grouped' => [ + 'children' => [ + 'associated' => [ + 'children' => [ + 'record' => [ + 'children' => [ + 'source_code' => [ + 'arguments' => [ + 'data' => [ + 'config' => $this->getQuantityPerSourceConfig(), + ], + ], + ], + ], + ], + ], + 'arguments' => [ + 'data' => [ + 'config' => [ + 'map' => [ + 'quantity_per_source' => 'quantity_per_source', + ], + ], + ], + ], ], - 'arguments' => [ - 'data' => [ - 'config' => [ - 'map' => [ - 'quantity_per_source' => 'quantity_per_source' - ] - ] - ] - ] - ] - ] + ], + ], ] - ]); + ); } return $meta;