diff --git a/vendor/magento/module-negotiable-quote/Model/Plugin/Quote/UpdateNegotiableQuotePlugin.php b/vendor/magento/module-negotiable-quote/Model/Plugin/Quote/UpdateNegotiableQuotePlugin.php new file mode 100644 index 000000000000..5d733bcc0fd2 --- /dev/null +++ b/vendor/magento/module-negotiable-quote/Model/Plugin/Quote/UpdateNegotiableQuotePlugin.php @@ -0,0 +1,97 @@ +getIsActive()) { + return $quoteResult; + } + + $negotiableQuoteToUpdate = $this->getNegotiableQuoteToBeUpdated($quote); + if (empty($quote->getUpdatedAt()) || !$negotiableQuoteToUpdate) { + return $quoteResult; + } + + if (!method_exists($negotiableQuoteToUpdate, 'getSnapshot') || + empty($negotiableQuoteToUpdate->getSnapshot()) + ) { + return $quoteResult; + } + + $snapshot = json_decode($negotiableQuoteToUpdate->getSnapshot(), true); + if (empty($snapshot)) { + return $quoteResult; + } + + $snapshot['quote']['updated_at'] = $quote->getUpdatedAt(); + $negotiableQuoteToUpdate->setSnapshot(json_encode($snapshot)); + $this->negotiableQuoteRepository->save($negotiableQuoteToUpdate); + + return $quoteResult; + } + + /** + * Return negotiable quotes that needs to be updated. + * + * @param CartInterface $quote + * + * @return NegotiableQuoteInterface|bool $negotiableQuoteToUpdate + */ + private function getNegotiableQuoteToBeUpdated(CartInterface $quote) + { + $negotiableQuoteToUpdate = false; + $extensionAttributes = $quote->getExtensionAttributes(); + + if ($extensionAttributes && $extensionAttributes->getNegotiableQuote()) { + $negotiableQuoteToUpdate = $extensionAttributes->getNegotiableQuote(); + if (!$negotiableQuoteToUpdate->getQuoteId() && $negotiableQuoteToUpdate->getIsRegularQuote()) { + $negotiableQuoteToUpdate->setQuoteId($quote->getId()); + } + } + return $negotiableQuoteToUpdate; + } +} diff --git a/vendor/magento/module-negotiable-quote/etc/di.xml b/vendor/magento/module-negotiable-quote/etc/di.xml index 256ea510cd2b..51c0f122ab95 100644 --- a/vendor/magento/module-negotiable-quote/etc/di.xml +++ b/vendor/magento/module-negotiable-quote/etc/di.xml @@ -515,4 +515,7 @@ + + +