/** * Retrieve customer cart quote object model * * @return \Magento\Sales\Model\Quote */ public function getCustomerCart() { if (!is_null($this->_cart)) { return $this->_cart; } $this->_cart = $this->_objectManager->create('Magento\\Sales\\Model\\Quote'); $customerId = (int) $this->getSession()->getCustomerId(); if ($customerId) { $this->_cart->setStore($this->getSession()->getStore())->loadByCustomer($customerId); if (!$this->_cart->getId()) { $customerData = $this->_customerAccountService->getCustomer($customerId); $this->_cart->assignCustomer($customerData); $this->_cart->save(); } } return $this->_cart; }
/** * Retrieve quote model object * * @return \Magento\Sales\Model\Quote */ public function getQuote() { if (is_null($this->_quote)) { $this->_quote = $this->_quoteFactory->create(); if ($this->getStoreId() && $this->getQuoteId()) { $this->_quote->setStoreId($this->getStoreId())->load($this->getQuoteId()); } elseif ($this->getStoreId() && $this->hasCustomerId()) { $customerGroupId = $this->_scopeConfig->getValue(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $this->_quote->setStoreId($this->getStoreId())->setCustomerGroupId($customerGroupId)->setIsActive(false)->save(); $this->setQuoteId($this->_quote->getId()); try { $customerData = $this->_customerService->getCustomer($this->getCustomerId()); $this->_quote->assignCustomer($customerData); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { /** Customer does not exist */ } } $this->_quote->setIgnoreOldQty(true); $this->_quote->setIsSuperMode(true); } return $this->_quote; }
/** * Setter for customer * * @param CustomerDataObject $customerData * @return $this */ public function setCustomerData(CustomerDataObject $customerData) { $this->_quote->assignCustomer($customerData); $this->_customerId = $customerData->getId(); return $this; }