本文整理汇总了PHP中Magento\Quote\Model\QuoteRepository::create方法的典型用法代码示例。如果您正苦于以下问题:PHP QuoteRepository::create方法的具体用法?PHP QuoteRepository::create怎么用?PHP QuoteRepository::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\QuoteRepository
的用法示例。
在下文中一共展示了QuoteRepository::create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreate
public function testCreate()
{
$this->quoteFactoryMock->expects($this->once())->method('create')->with([1, 2, 3])->willReturn($this->quoteMock);
$this->storeManagerMock->expects($this->never())->method('getStore');
$this->storeMock->expects($this->never())->method('getId');
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
$this->quoteMock->expects($this->never())->method('load');
$this->quoteMock->expects($this->never())->method('getId');
$this->assertEquals($this->quoteMock, $this->model->create([1, 2, 3]));
}
示例2: loadCustomerQuote
/**
* Load data for customer quote and merge with current quote
*
* @return $this
*/
public function loadCustomerQuote()
{
if (!$this->_customerSession->getCustomerId()) {
return $this;
}
$this->_eventManager->dispatch('load_customer_quote_before', ['checkout_session' => $this]);
try {
$customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$customerQuote = $this->quoteRepository->create();
}
$customerQuote->setStoreId($this->_storeManager->getStore()->getId());
if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
if ($this->getQuoteId()) {
$this->quoteRepository->save($customerQuote->merge($this->getQuote())->collectTotals());
}
$this->setQuoteId($customerQuote->getId());
if ($this->_quote) {
$this->quoteRepository->delete($this->_quote);
}
$this->_quote = $customerQuote;
} else {
$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();
$this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals();
$this->quoteRepository->save($this->getQuote());
}
return $this;
}
示例3: _initData
/**
* Loads customer, quote and quote item by request params
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _initData()
{
$this->_customerId = (int) $this->getRequest()->getParam('customer_id');
if (!$this->_customerId) {
throw new \Magento\Framework\Exception\LocalizedException(__('No customer ID defined.'));
}
$quoteItemId = (int) $this->getRequest()->getParam('id');
$websiteId = (int) $this->getRequest()->getParam('website_id');
try {
$this->_quote = $this->quoteRepository->getForCustomer($this->_customerId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->_quote = $this->quoteRepository->create();
}
$this->_quote->setWebsite($this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getWebsite($websiteId));
$this->_quoteItem = $this->_quote->getItemById($quoteItemId);
if (!$this->_quoteItem) {
throw new LocalizedException(__('Please correct the quote items and try again.'));
}
return $this;
}
示例4: getQuote
/**
* Get the quote of the cart
*
* @return \Magento\Quote\Model\Quote
*/
protected function getQuote()
{
if (null === $this->quote) {
$customerId = $this->getCustomerId();
$storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
try {
$this->quote = $this->quoteRepository->getForCustomer($customerId, $storeIds);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->quote = $this->quoteRepository->create()->setSharedStoreIds($storeIds);
}
}
return $this->quote;
}
示例5: createCustomerCart
/**
* Creates a cart for the currently logged-in customer.
*
* @param int $customerId
* @param int $storeId
* @return \Magento\Quote\Model\Quote Cart object.
* @throws CouldNotSaveException The cart could not be created.
*/
protected function createCustomerCart($customerId, $storeId)
{
$customer = $this->customerRepository->getById($customerId);
try {
$quote = $this->quoteRepository->getActiveForCustomer($customerId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->create();
$quote->setStoreId($storeId);
$quote->setCustomer($customer);
$quote->setCustomerIsGuest(0);
}
return $quote;
}
示例6: getQuote
/**
* Get quote
*
* @return \Magento\Quote\Model\Quote
*/
protected function getQuote()
{
if (null == $this->quote) {
$storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
$this->quote = $this->quoteRepository->create()->setSharedStoreIds($storeIds);
$currentCustomerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
if (!empty($currentCustomerId)) {
try {
$this->quote = $this->quoteRepository->getForCustomer($currentCustomerId, $storeIds);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
}
}
}
return $this->quote;
}
示例7: createCustomerCart
/**
* Creates a cart for the currently logged-in customer.
*
* @param int $storeId
* @return \Magento\Quote\Model\Quote Cart object.
* @throws CouldNotSaveException The cart could not be created.
*/
protected function createCustomerCart($storeId)
{
$customer = $this->customerRepository->getById($this->userContext->getUserId());
try {
$this->quoteRepository->getActiveForCustomer($this->userContext->getUserId());
throw new CouldNotSaveException(__('Cannot create quote'));
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
}
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->create();
$quote->setStoreId($storeId);
$quote->setCustomer($customer);
$quote->setCustomerIsGuest(0);
return $quote;
}
示例8: getQuote
/**
* Retrieve quote model object
*
* @return \Magento\Quote\Model\Quote
*/
public function getQuote()
{
if ($this->_quote === null) {
$this->_quote = $this->quoteRepository->create();
if ($this->getStoreId()) {
if (!$this->getQuoteId()) {
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId())->setIsActive(false)->setStoreId($this->getStoreId());
$this->quoteRepository->save($this->_quote);
$this->setQuoteId($this->_quote->getId());
} else {
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
$this->_quote->setStoreId($this->getStoreId());
}
if ($this->getCustomerId()) {
$customer = $this->customerRepository->getById($this->getCustomerId());
$this->_quote->assignCustomer($customer);
}
}
$this->_quote->setIgnoreOldQty(true);
$this->_quote->setIsSuperMode(true);
}
return $this->_quote;
}
示例9: getCustomerCart
/**
* Retrieve customer cart quote object model
*
* @return \Magento\Quote\Model\Quote
*/
public function getCustomerCart()
{
if (!is_null($this->_cart)) {
return $this->_cart;
}
$this->_cart = $this->quoteRepository->create();
$customerId = (int) $this->getSession()->getCustomerId();
if ($customerId) {
try {
$this->_cart = $this->quoteRepository->getForCustomer($customerId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->_cart->setStore($this->getSession()->getStore());
$customerData = $this->customerRepository->getById($customerId);
$this->_cart->assignCustomer($customerData);
$this->quoteRepository->save($this->_cart);
}
}
return $this->_cart;
}