diff --git a/app/code/Magento/Sales/Model/Reorder/Reorder.php b/app/code/Magento/Sales/Model/Reorder/Reorder.php index 27c2e280848a0..163ab2c496ef4 100644 --- a/app/code/Magento/Sales/Model/Reorder/Reorder.php +++ b/app/code/Magento/Sales/Model/Reorder/Reorder.php @@ -188,11 +188,13 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu $storeId = (string) $this->storeManager->getStore()->getId(); $this->addItemsToCart($cart, $order->getItemsCollection(), $storeId); - try { - $this->cartRepository->save($cart); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - // handle exception from \Magento\Quote\Model\QuoteRepository\SaveHandler::save - $this->addError($e->getMessage()); + if (!$cart->getHasError()) { + try { + $this->cartRepository->save($cart); + } catch (\Magento\Framework\Exception\LocalizedException $e) { + // handle exception from \Magento\Quote\Model\QuoteRepository\SaveHandler::save + $this->addError($e->getMessage()); + } } $savedCart = $this->cartRepository->get($cart->getId()); diff --git a/app/code/Magento/Sales/Test/Mftf/Test/StorefrontAddProductFromReorderUntilMaximumQtyAllowedInCartTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/StorefrontAddProductFromReorderUntilMaximumQtyAllowedInCartTest.xml new file mode 100644 index 0000000000000..5d26c89c883d2 --- /dev/null +++ b/app/code/Magento/Sales/Test/Mftf/Test/StorefrontAddProductFromReorderUntilMaximumQtyAllowedInCartTest.xml @@ -0,0 +1,111 @@ + + + + + + + + <description value="Make reorder with custom product price on frontend"/> + <severity value="CRITICAL"/> + <testCaseId value="PR-38069"/> + <group value="sales"/> + </annotations> + <before> + <!--Enable flat rate shipping--> + <magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" + stepKey="enableFlatRate"/> + + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createSimpleProduct"> + <field key="price">100.00</field> + <requiredEntity createDataKey="createCategory"/> + </createData> + + <!-- Create Customer Account --> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + + <actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/> + </before> + <after> + <actionGroup ref="AdminLogoutActionGroup" stepKey="LogoutAsAdmin"/> + <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer" /> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + </after> + + <actionGroup ref="AdminClearFiltersActionGroup" stepKey="openProductCatalogPage"/> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="clickFirstRowToOpenDefaultSimpleProduct"> + <argument name="product" value="$$createSimpleProduct$$"/> + </actionGroup> + + <!--Go to Advance Inventory and Enable Backorder and disable Manage Stock as No--> + <actionGroup ref="AdminClickOnAdvancedInventoryLinkActionGroup" stepKey="clickOnAdvancedInventoryLink"/> + <actionGroup ref="AdminSetMaxAllowedQtyForProductActionGroup" stepKey="fillMaxAllowedQty"> + <argument name="qty" value="1"/> + </actionGroup> + <actionGroup ref="AdminSubmitAdvancedInventoryFormActionGroup" stepKey="clickDoneButton"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/> + <!-- Create new order --> + <actionGroup ref="AdminNavigateToNewOrderPageExistingCustomerActionGroup" stepKey="CreateNewOrder"> + <argument name="customer" value="Simple_US_Customer"/> + </actionGroup> + + <!-- Add product to order --> + <actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addProductToOrder"> + <argument name="product" value="$$createSimpleProduct$$"/> + <argument name="productQty" value="1"/> + </actionGroup> + <waitForPageLoad stepKey="WaitForProductAdd"/> + <waitForLoadingMaskToDisappear stepKey="WaitForProductAddLoading"/> + + <!-- Set product custom price --> + <click selector="{{OrdersGridSection.customPrice($$createSimpleProduct.name$$)}}" stepKey="ClickOnCustomPrice"/> + <fillField selector="{{OrdersGridSection.customPriceInput($$createSimpleProduct.name$$)}}" userInput="10.00" + stepKey="FillCustomPrice"/> + <click selector="{{AdminOrderFormItemsSection.updateItemsAndQuantities}}" stepKey="clickUpdateItemsAndQuantities"/> + <waitForPageLoad stepKey="waitForItemsAndQuantitiesUpdating"/> + + <!--Select FlatRate shipping method--> + <actionGroup ref="OrderSelectFlatRateShippingActionGroup" stepKey="orderSelectFlatRateShippingMethod"/> + + <!--Submit order--> + <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <waitForPageLoad stepKey="WaitForOrderSubmit"/> + + <!--Login customer on storefront--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginCustomer"> + <argument name="Customer" value="$$createCustomer$$" /> + </actionGroup> + + <!-- Go to my Orders page --> + <amOnPage url="{{StorefrontCustomerDashboardPage.url}}" stepKey="onMyAccount"/> + <waitForPageLoad stepKey="waitForAccountPage"/> + <click selector="{{StorefrontCustomerSidebarSection.sidebarTab('My Orders')}}" stepKey="clickOnMyOrders"/> + <waitForPageLoad stepKey="waitForOrdersLoad"/> + + <!-- Clicking on Reorder link from Order Details Tab --> + <click selector="{{StorefrontCustomerOrderViewSection.reorder}}" stepKey="clickReorder"/> + + <!-- Go to my Orders page --> + <amOnPage url="{{StorefrontCustomerDashboardPage.url}}" stepKey="onMyAccountAgain"/> + <waitForPageLoad stepKey="waitForAccountPageAgain"/> + <click selector="{{StorefrontCustomerSidebarSection.sidebarTab('My Orders')}}" stepKey="clickOnMyOrdersAgain"/> + <waitForPageLoad stepKey="waitForOrdersLoadAgain"/> + + <!-- Clicking on Reorder link from Order Details Tab --> + <click selector="{{StorefrontCustomerOrderViewSection.reorder}}" stepKey="clickReorderAgain"/> + + <!-- Verify product is still in the cart --> + <actionGroup ref="StorefrontClickOnMiniCartActionGroup" stepKey="openMiniCart"/> + <actionGroup ref="AssertStorefrontMiniCartSubtotalActionGroup" stepKey="assertSubtotal"> + <argument name="subtotal" value="$100.00"/> + </actionGroup> + </test> +</tests>