当前位置: 首页>>代码示例>>PHP>>正文


PHP QuoteRepository::save方法代码示例

本文整理汇总了PHP中Magento\Quote\Model\QuoteRepository::save方法的典型用法代码示例。如果您正苦于以下问题:PHP QuoteRepository::save方法的具体用法?PHP QuoteRepository::save怎么用?PHP QuoteRepository::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Quote\Model\QuoteRepository的用法示例。


在下文中一共展示了QuoteRepository::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Initialize coupon
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     /**
      * No reason continue with empty shopping cart
      */
     if (!$this->cart->getQuote()->getItemsCount()) {
         return $this->_goBack();
     }
     $couponCode = $this->getRequest()->getParam('remove') == 1 ? '' : trim($this->getRequest()->getParam('coupon_code'));
     $oldCouponCode = $this->cart->getQuote()->getCouponCode();
     if (!strlen($couponCode) && !strlen($oldCouponCode)) {
         return $this->_goBack();
     }
     $codeLength = strlen($couponCode);
     $isCodeLengthValid = $codeLength && $codeLength <= \Magento\Checkout\Helper\Cart::COUPON_CODE_MAX_LENGTH;
     $this->cart->getQuote()->getShippingAddress()->setCollectShippingRates(true);
     $this->cart->getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')->collectTotals();
     $this->quoteRepository->save($this->cart->getQuote());
     if ($codeLength) {
         if ($isCodeLengthValid && $couponCode == $this->cart->getQuote()->getCouponCode()) {
             $this->messageManager->addSuccess(__('The coupon code "%1" was applied.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($couponCode)));
         } else {
             $this->messageManager->addError(__('The coupon code "%1" is not valid.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($couponCode)));
             $this->cart->save();
         }
     } else {
         $this->messageManager->addSuccess(__('The coupon code was canceled.'));
     }
     return $this->_goBack();
 }
开发者ID:opexsw,项目名称:magento2,代码行数:38,代码来源:CouponPost.php

示例2: dispatch

 /**
  * Set new customer group to all his quotes
  *
  * @param Observer $observer
  * @return void
  */
 public function dispatch(Observer $observer)
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $observer->getEvent()->getCustomerDataObject();
     /** @var \Magento\Customer\Api\Data\CustomerInterface $origCustomer */
     $origCustomer = $observer->getEvent()->getOrigCustomerDataObject();
     if ($customer->getGroupId() !== $origCustomer->getGroupId()) {
         /**
          * It is needed to process customer's quotes for all websites
          * if customer accounts are shared between all of them
          */
         /** @var $websites \Magento\Store\Model\Website[] */
         $websites = $this->config->isWebsiteScope() ? [$this->storeManager->getWebsite($customer->getWebsiteId())] : $this->storeManager->getWebsites();
         foreach ($websites as $website) {
             try {
                 $quote = $this->quoteRepository->getForCustomer($customer->getId());
                 $quote->setWebsite($website);
                 $quote->setCustomerGroupId($customer->getGroupId());
                 $quote->collectTotals();
                 $this->quoteRepository->save($quote);
             } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             }
         }
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:31,代码来源:CustomerQuote.php

示例3: execute

 /**
  * Initialize shipping information
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     $country = (string) $this->getRequest()->getParam('country_id');
     $postcode = (string) $this->getRequest()->getParam('estimate_postcode');
     $city = (string) $this->getRequest()->getParam('estimate_city');
     $regionId = (string) $this->getRequest()->getParam('region_id');
     $region = (string) $this->getRequest()->getParam('region');
     $this->cart->getQuote()->getShippingAddress()->setCountryId($country)->setCity($city)->setPostcode($postcode)->setRegionId($regionId)->setRegion($region)->setCollectShippingRates(true);
     $this->quoteRepository->save($this->cart->getQuote());
     $this->cart->save();
     return $this->_goBack();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:17,代码来源:EstimatePost.php

示例4: execute

 /**
  * Initialize coupon
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $couponCode = $this->getRequest()->getParam('remove') == 1 ? '' : trim($this->getRequest()->getParam('coupon_code'));
     $cartQuote = $this->cart->getQuote();
     $oldCouponCode = $cartQuote->getCouponCode();
     $codeLength = strlen($couponCode);
     if (!$codeLength && !strlen($oldCouponCode)) {
         return $this->_goBack();
     }
     try {
         $isCodeLengthValid = $codeLength && $codeLength <= \Magento\Checkout\Helper\Cart::COUPON_CODE_MAX_LENGTH;
         $itemsCount = $cartQuote->getItemsCount();
         if ($itemsCount) {
             $cartQuote->getShippingAddress()->setCollectShippingRates(true);
             $cartQuote->setCouponCode($isCodeLengthValid ? $couponCode : '')->collectTotals();
             $this->quoteRepository->save($cartQuote);
         }
         if ($codeLength) {
             $escaper = $this->_objectManager->get('Magento\\Framework\\Escaper');
             if (!$itemsCount) {
                 if ($isCodeLengthValid) {
                     $coupon = $this->couponFactory->create();
                     $coupon->load($couponCode, 'code');
                     if ($coupon->getId()) {
                         $this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
                         $this->messageManager->addSuccess(__('You used coupon code "%1".', $escaper->escapeHtml($couponCode)));
                     } else {
                         $this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode)));
                     }
                 } else {
                     $this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode)));
                 }
             } else {
                 if ($isCodeLengthValid && $couponCode == $cartQuote->getCouponCode()) {
                     $this->messageManager->addSuccess(__('You used coupon code "%1".', $escaper->escapeHtml($couponCode)));
                 } else {
                     $this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode)));
                     $this->cart->save();
                 }
             }
         } else {
             $this->messageManager->addSuccess(__('You canceled the coupon code.'));
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We cannot apply the coupon code.'));
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
     }
     return $this->_goBack();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:58,代码来源:CouponPost.php

示例5: assign

 /**
  * {@inheritDoc}
  */
 public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     $this->addressValidator->validate($address);
     $quote->setBillingAddress($address);
     $quote->setDataChanges(true);
     try {
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save address. Please, check input data.'));
     }
     return $quote->getBillingAddress()->getId();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:BillingAddressManagement.php

示例6: testSave

 public function testSave()
 {
     $this->quoteMock->expects($this->once())->method('save');
     $this->quoteMock->expects($this->exactly(1))->method('getId')->willReturn(1);
     $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2);
     $this->model->save($this->quoteMock);
 }
开发者ID:ViniciusAugusto,项目名称:magento2,代码行数:7,代码来源:QuoteRepositoryTest.php

示例7: set

 /**
  * {@inheritDoc}
  *
  * @param int $cartId The shopping cart ID.
  * @param string $carrierCode The carrier code.
  * @param string $methodCode The shipping method code.
  * @return bool
  * @throws \Magento\Framework\Exception\InputException The shipping method is not valid for an empty cart.
  * @throws \Magento\Framework\Exception\CouldNotSaveException The shipping method could not be saved.
  * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart contains only virtual products and the shipping method is not applicable.
  * @throws \Magento\Framework\Exception\StateException The billing or shipping address is not set.
  */
 public function set($cartId, $carrierCode, $methodCode)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Shipping method is not applicable for empty cart'));
     }
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping method is not applicable.'));
     }
     $shippingAddress = $quote->getShippingAddress();
     if (!$shippingAddress->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     $shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
     if (!$shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod())) {
         throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode));
     }
     try {
         $this->quoteRepository->save($quote->collectTotals());
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Cannot set shipping method. %1', $e->getMessage()));
     }
     return true;
 }
开发者ID:nja78,项目名称:magento2,代码行数:37,代码来源:ShippingMethodManagement.php

示例8: saveAddressInformation

 /**
  * {@inheritDoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     $address = $addressInformation->getShippingAddress();
     $carrierCode = $addressInformation->getShippingCarrierCode();
     $methodCode = $addressInformation->getShippingMethodCode();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping address is not applicable.'));
     }
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Shipping method is not applicable for empty cart'));
     }
     $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
     $sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
     $customerAddressId = $address->getCustomerAddressId();
     $this->addressValidator->validate($address);
     $quote->setShippingAddress($address);
     $address = $quote->getShippingAddress();
     if ($customerAddressId) {
         $addressData = $this->addressRepository->getById($customerAddressId);
         $address = $quote->getShippingAddress()->importCustomerAddressData($addressData);
     }
     $address->setSameAsBilling($sameAsBilling);
     $address->setSaveInAddressBook($saveInAddressBook);
     $address->setCollectShippingRates(true);
     if (!$address->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     $address->setShippingMethod($carrierCode . '_' . $methodCode);
     try {
         $address->save();
         $address->collectTotals();
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save address. Please, check input data.'));
     }
     if (!$address->getShippingRateByCode($address->getShippingMethod())) {
         throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode));
     }
     if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
         throw new InputException($this->scopeConfig->getValue('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $quote->getStoreId()));
     }
     try {
         $address->save();
         $quote->collectTotals();
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save shipping information. Please, check input data.'));
     }
     /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */
     $paymentDetails = $this->paymentDetailsFactory->create();
     $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $paymentDetails;
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:62,代码来源:ShippingInformationManagement.php

示例9: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Quote\Api\Data\CartInterface $quote)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save($quote);
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php

示例10: collect

 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @return void
  */
 public function collect(\Magento\Quote\Model\Quote $quote)
 {
     if ($this->customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 /** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
                 $estimatedAddress = $this->estimatedAddressFactory->create();
                 $estimatedAddress->setCountryId($address->getCountryId());
                 $estimatedAddress->setPostcode($address->getPostcode());
                 $estimatedAddress->setRegion((string) $address->getRegion()->getRegion());
                 $estimatedAddress->setRegionId($address->getRegionId());
                 $this->shippingMethodManager->estimateByAddress($quote->getId(), $estimatedAddress);
                 $this->quoteRepository->save($quote);
             }
         }
     }
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:23,代码来源:CollectQuote.php

示例11: remove

 /**
  * {@inheritdoc}
  */
 public function remove($cartId)
 {
     /** @var  \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if (!$quote->getItemsCount()) {
         throw new NoSuchEntityException(__('Cart %1 doesn\'t contain products', $cartId));
     }
     $quote->getShippingAddress()->setCollectShippingRates(true);
     try {
         $quote->setCouponCode('');
         $this->quoteRepository->save($quote->collectTotals());
     } catch (\Exception $e) {
         throw new CouldNotDeleteException(__('Could not delete coupon code'));
     }
     if ($quote->getCouponCode() != '') {
         throw new CouldNotDeleteException(__('Could not delete coupon code'));
     }
     return true;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:22,代码来源:CouponManagement.php

示例12: assign

 /**
  * {@inheritDoc}
  */
 public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping address is not applicable.'));
     }
     $this->addressValidator->validate($address);
     $address->setSameAsBilling(0);
     $address->setCollectShippingRates(true);
     $quote->setShippingAddress($address);
     $quote->setDataChanges(true);
     try {
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save address. Please, check input data.'));
     }
     return $quote->getShippingAddress()->getId();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:ShippingAddressManagement.php

示例13: saveAddresses

 /**
  * @{inheritdoc}
  */
 public function saveAddresses($cartId, \Magento\Quote\Api\Data\AddressInterface $billingAddress, \Magento\Quote\Api\Data\AddressInterface $shippingAddress = null, \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData = null, $checkoutMethod = null)
 {
     $this->billingAddressManagement->assign($cartId, $billingAddress);
     /** @var \Magento\Quote\Api\Data\AddressDetailsInterface  $addressDetails */
     $addressDetails = $this->addressDetailsFactory->create();
     if ($shippingAddress) {
         $this->shippingAddressManagement->assign($cartId, $shippingAddress);
         $addressDetails->setFormattedShippingAddress($this->shippingAddressManagement->get($cartId)->format('html'));
         $addressDetails->setShippingMethods($this->shippingMethodManagement->getList($cartId));
     }
     $addressDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     if ($additionalData !== null) {
         $this->dataProcessor->process($additionalData);
     }
     if ($checkoutMethod != null) {
         $this->quoteRepository->save($this->quoteRepository->getActive($cartId)->setCheckoutMethod($checkoutMethod));
     }
     $addressDetails->setFormattedBillingAddress($this->billingAddressManagement->get($cartId)->format('html'));
     $addressDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $addressDetails;
 }
开发者ID:kid17,项目名称:magento2,代码行数:24,代码来源:AddressDetailsManagement.php

示例14: setGuest

 /**
  * Make quote to be guest
  *
  * @param bool $checkQuote Check quote to be persistent (not stolen)
  * @return void
  */
 public function setGuest($checkQuote = false)
 {
     /** @var $quote \Magento\Quote\Model\Quote */
     $quote = $this->checkoutSession->getQuote();
     if ($quote && $quote->getId()) {
         if ($checkQuote && !$this->persistentData->isShoppingCartPersist() && !$quote->getIsPersistent()) {
             $this->checkoutSession->clearQuote()->clearStorage();
             return;
         }
         $quote->getPaymentsCollection()->walk('delete');
         $quote->getAddressesCollection()->walk('delete');
         $this->_setQuotePersistent = false;
         $quote->setIsActive(true)->setCustomerId(null)->setCustomerEmail(null)->setCustomerFirstname(null)->setCustomerLastname(null)->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)->setIsPersistent(false)->removeAllAddresses();
         //Create guest addresses
         $quote->getShippingAddress();
         $quote->getBillingAddress();
         $quote->collectTotals();
         $this->quoteRepository->save($quote);
     }
     $this->persistentSession->getSession()->removePersistentCookie();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:27,代码来源:QuoteManager.php

示例15: save

 /**
  * Save cart
  *
  * @return $this
  */
 public function save()
 {
     $this->_eventManager->dispatch('checkout_cart_save_before', ['cart' => $this]);
     $this->getQuote()->getBillingAddress();
     $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
     $this->getQuote()->collectTotals();
     $this->quoteRepository->save($this->getQuote());
     $this->_checkoutSession->setQuoteId($this->getQuote()->getId());
     /**
      * Cart save usually called after changes with cart items.
      */
     $this->_eventManager->dispatch('checkout_cart_save_after', ['cart' => $this]);
     $this->reinitializeState();
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:Cart.php


注:本文中的Magento\Quote\Model\QuoteRepository::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。