Skip to content

Magento 2 : Save quote

What is the Difference between

$this->quoteRepository->save($quote);

&

$quote->save();

In below code

public function aroundApply_shipping(
        StripeIntegrationPaymentsApiService $subject,
        callable $proceed,
        $address,
        $shipping_id = null
    ) {
        if (empty($this->checkoutSession) || empty($this->checkoutSession->getQuote()) || empty($this->checkoutSession->getQuote()->getId())) {
            $writer = new ZendLogWriterStream(BP . '/var/log/methodcallcheck.log');
            $logger = new ZendLogLogger();
            $logger->addWriter($writer);
            $logger->info('Your text message');
            $data = $this->request->getBodyParams();
            $token = "";
            $response['error'] = true;
            $response['message'] = "";
            if (isset($data['cart']) && !empty($data['cart'])) {
                $token = $data['cart'];
                $cartId = $this->maskedQuoteIdToQuoteId->execute($token);
                $quote = $this->quoteRepository->get($cartId);
                $quote->setRemoteIp($this->_remoteIp->getRemoteAddress());
                $this->quoteRepository->save($quote);
                try {
                    if (count($address) === 0) {
                        $address = $this->expressHelper->getDefaultShippingAddress();
                    }
                    if (!$quote->isVirtual()) {
                        $shippingAddress = $this->helper->getShippingAddress($address);
                        $shipping = $quote->getShippingAddress()->addData($shippingAddress);
                        if ($shipping_id) {
                            $shipping->setShippingMethod($shipping_id)
                                ->setCollectShippingRates(true)
                                ->collectShippingRates();
                            $parts = explode('_', $shipping_id);
                            $carrierCode = array_shift($parts);
                            $methodCode = implode("_", $parts);
                            /** @var MagentoQuoteApiDataAddressInterface $ba */
                            $shippingAddress = $this->inputProcessor->convertValue($shippingAddress, 'MagentoQuoteApiDataAddressInterface');
                            /** @var MagentoCheckoutApiDataShippingInformationInterface $shippingInformation */
                            $shippingInformation = $this->shippingInformationFactory->create();
                            $shippingInformation
                            //->setBillingAddress($shippingAddress)
                            ->setShippingAddress($shippingAddress)
                                ->setShippingCarrierCode($carrierCode)
                                ->setShippingMethodCode($methodCode);
                            $this->shippingInformationManagement->saveAddressInformation($quote->getId(), $shippingInformation);
                            $quote->setTotalsCollectedFlag(false);
                            $quote->collectTotals();
                            $this->quoteRepository->save($quote);
                        }
                    }