1010use Magento \Checkout \Controller \Cart ;
1111use Magento \Checkout \Controller \Sidebar \UpdateItemQty ;
1212use Magento \Checkout \Model \Session ;
13+ use Magento \Checkout \Model \Cart as CartModel ;
1314use Magento \Customer \Api \AddressRepositoryInterface ;
1415use Magento \Framework \App \RequestInterface ;
1516use Magento \Framework \Exception \LocalizedException ;
1920
2021/**
2122 * Cleans shipping addresses and item assignments after MultiShipping flow
23+ *
24+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2225 */
2326class MultishippingClearItemAddress
2427{
@@ -42,22 +45,30 @@ class MultishippingClearItemAddress
4245 */
4346 private $ disableMultishipping ;
4447
48+ /**
49+ * @var CartModel
50+ */
51+ private $ cartmodel ;
52+
4553 /**
4654 * @param CartRepositoryInterface $cartRepository
4755 * @param Session $checkoutSession
4856 * @param AddressRepositoryInterface $addressRepository
4957 * @param DisableMultishipping $disableMultishipping
58+ * @param CartModel $cartmodel
5059 */
5160 public function __construct (
5261 CartRepositoryInterface $ cartRepository ,
5362 Session $ checkoutSession ,
5463 AddressRepositoryInterface $ addressRepository ,
55- DisableMultishipping $ disableMultishipping
64+ DisableMultishipping $ disableMultishipping ,
65+ CartModel $ cartmodel
5666 ) {
5767 $ this ->cartRepository = $ cartRepository ;
5868 $ this ->checkoutSession = $ checkoutSession ;
5969 $ this ->addressRepository = $ addressRepository ;
6070 $ this ->disableMultishipping = $ disableMultishipping ;
71+ $ this ->cartmodel = $ cartmodel ;
6172 }
6273
6374 /**
@@ -90,9 +101,8 @@ public function clearAddressItem($subject, $request)
90101 }
91102 $ this ->cartRepository ->save ($ quote );
92103 if ($ subject instanceof UpdateItemQty) {
93- $ quote = $ this ->checkoutSession ->getQuote ();
94- $ quote ->setTotalsCollectedFlag (false );
95- $ this ->cartRepository ->save ($ quote );
104+ $ quote = $ this ->cartRepository ->get ($ quote ->getId ());
105+ $ this ->cartmodel ->setQuote ($ quote );
96106 }
97107 } elseif ($ this ->disableMultishipping ->execute ($ quote ) && $ this ->isVirtualItemInQuote ($ quote )) {
98108 $ quote ->setTotalsCollectedFlag (false );
0 commit comments