當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CartRepositoryInterface::getActive方法代碼示例

本文整理匯總了PHP中Magento\Quote\Api\CartRepositoryInterface::getActive方法的典型用法代碼示例。如果您正苦於以下問題:PHP CartRepositoryInterface::getActive方法的具體用法?PHP CartRepositoryInterface::getActive怎麽用?PHP CartRepositoryInterface::getActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Quote\Api\CartRepositoryInterface的用法示例。


在下文中一共展示了CartRepositoryInterface::getActive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get

 /**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         $addressTotalsData = $quote->getBillingAddress()->getData();
         $addressTotals = $quote->getBillingAddress()->getTotals();
     } else {
         $addressTotalsData = $quote->getShippingAddress()->getData();
         $addressTotals = $quote->getShippingAddress()->getTotals();
     }
     /** @var \Magento\Quote\Api\Data\TotalsInterface $quoteTotals */
     $quoteTotals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($quoteTotals, $addressTotalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->itemConverter->modelToDataObject($item);
     }
     $calculatedTotals = $this->totalsConverter->process($addressTotals);
     $quoteTotals->setTotalSegments($calculatedTotals);
     $amount = $quoteTotals->getGrandTotal() - $quoteTotals->getTaxAmount();
     $amount = $amount > 0 ? $amount : 0;
     $quoteTotals->setCouponCode($this->couponService->get($cartId));
     $quoteTotals->setGrandTotal($amount);
     $quoteTotals->setItems($items);
     $quoteTotals->setItemsQty($quote->getItemsQty());
     $quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode());
     $quoteTotals->setQuoteCurrencyCode($quote->getQuoteCurrencyCode());
     return $quoteTotals;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:36,代碼來源:CartTotalRepository.php

示例2: savePaymentInformation

 /**
  * {@inheritDoc}
  */
 public function savePaymentInformation($cartId, $email, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null)
 {
     if ($billingAddress) {
         $billingAddress->setEmail($email);
         $this->billingAddressManagement->assign($cartId, $billingAddress);
     } else {
         $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
         $this->cartRepository->getActive($quoteIdMask->getQuoteId())->getBillingAddress()->setEmail($email);
     }
     $this->paymentMethodManagement->set($cartId, $paymentMethod);
     return true;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:15,代碼來源:GuestPaymentInformationManagement.php

示例3: placeOrder

 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]);
     $order = $this->submit($quote);
     if (null == $order) {
         throw new LocalizedException(__('Unable to place order. Please try again later.'));
     }
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->checkoutSession->setLastOrderStatus($order->getStatus());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }
開發者ID:rafaelstz,項目名稱:magento2,代碼行數:31,代碼來源:QuoteManagement.php

示例4: saveAddressInformation

 /**
  * {@inheritDoc}
  */
 public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     $address = $addressInformation->getShippingAddress();
     $billingAddress = $addressInformation->getBillingAddress();
     $carrierCode = $addressInformation->getShippingCarrierCode();
     $methodCode = $addressInformation->getShippingMethodCode();
     if (!$address->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode);
     $this->validateQuote($quote);
     $quote->setIsMultiShipping(false);
     if ($billingAddress) {
         $quote->setBillingAddress($billingAddress);
     }
     try {
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save shipping information. Please check input data.'));
     }
     $shippingAddress = $quote->getShippingAddress();
     if (!$shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod())) {
         throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode));
     }
     /** @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:rafaelstz,項目名稱:magento2,代碼行數:36,代碼來源:ShippingInformationManagement.php

示例5: getPaymentMethods

 /**
  * {@inheritDoc}
  */
 public function getPaymentMethods($quoteId, $country = null)
 {
     // get quote from quoteId
     $quote = $this->_quoteRepository->getActive($quoteId);
     $store = $quote->getStore();
     $paymentMethods = $this->_addHppMethodsToConfig($store, $country);
     return $paymentMethods;
 }
開發者ID:Adyen,項目名稱:adyen-magento2,代碼行數:11,代碼來源:PaymentMethods.php

示例6: saveAddressInformation

 /**
  * {@inheritDoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 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);
     $this->validateQuote($quote);
     $quote->setIsMultiShipping(false);
     $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);
     }
     $billingAddress = $addressInformation->getBillingAddress();
     if ($billingAddress) {
         $quote->setBillingAddress($billingAddress);
     }
     $address->setSaveInAddressBook($saveInAddressBook);
     $address->setSameAsBilling($sameAsBilling);
     $address->setCollectShippingRates(true);
     if (!$address->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     $address->setShippingMethod($carrierCode . '_' . $methodCode);
     try {
         $this->totalsCollector->collectAddressTotals($quote, $address);
     } 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:dragonsword007008,項目名稱:magento2,代碼行數:61,代碼來源:ShippingInformationManagement.php

示例7: 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:pradeep-wagento,項目名稱:magento2,代碼行數:22,代碼來源:CouponManagement.php

示例8: get

 /**
  * {@inheritDoc}
  */
 public function get($cartId)
 {
     /** @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.'));
     }
     /** @var \Magento\Quote\Model\Quote\Address $address */
     return $quote->getShippingAddress();
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:ShippingAddressManagement.php

示例9: estimateByAddressId

 /**
  * {@inheritDoc}
  */
 public function estimateByAddressId($cartId, $addressId)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     // no methods applicable for empty carts or carts with virtual products
     if ($quote->isVirtual() || 0 == $quote->getItemsCount()) {
         return [];
     }
     $address = $this->addressRepository->getById($addressId);
     return $this->getEstimatedRates($quote, $address->getCountryId(), $address->getPostcode(), $address->getRegionId(), $address->getRegion());
 }
開發者ID:rafaelstz,項目名稱:magento2,代碼行數:14,代碼來源:ShippingMethodManagement.php

示例10: save

 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Gift Messages is not applicable for empty cart'));
     }
     if ($quote->isVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $messageText = $giftMessage->getMessage();
     if ($messageText && !$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) {
         throw new CouldNotSaveException(__('Gift Message is not available'));
     }
     $this->giftMessageManager->setMessage($quote, 'quote', $giftMessage);
     return true;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:24,代碼來源:CartRepository.php

示例11: testGetActiveWithSharedStoreIds

 public function testGetActiveWithSharedStoreIds()
 {
     $cartId = 16;
     $sharedStoreIds = [1, 2];
     $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getId')->willReturn(1);
     $this->quoteMock->expects($this->once())->method('setSharedStoreIds')->with($sharedStoreIds)->willReturnSelf();
     $this->quoteMock->expects($this->once())->method('load')->with($cartId)->willReturn($this->storeMock);
     $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
     $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1);
     $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds));
     $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds));
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:QuoteRepositoryTest.php

示例12: saveShippingAddress

 protected function saveShippingAddress($cartId)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     $address = $quote->getShippingAddress();
     $region = $address->getRegion();
     if (!is_null($region) && $region instanceof \Magento\Customer\Model\Data\Region) {
         $regionString = $region->getRegion();
         $address->setRegion($regionString);
     }
     try {
         $address->save();
     } catch (\Exception $e) {
         $this->shipperLogger->postCritical('Shipperhq_Shipper', 'Exception raised whilst saving shipping address', $e->getMessage());
     }
 }
開發者ID:shipperhq,項目名稱:module-shipper,代碼行數:15,代碼來源:ShippingMethodManagementPlugin.php

示例13: aroundSaveAddressInformation

 /**
  *Set additional information for shipping address
  *
  * @param \Magento\Checkout\Model\ShippingInformationManagement $subject
  * @param callable $proceed
  *
  * @return \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundSaveAddressInformation(\Magento\Checkout\Model\ShippingInformationManagement $subject, $proceed, $cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     try {
         $carrierCode = $addressInformation->getShippingCarrierCode();
         $methodCode = $addressInformation->getShippingMethodCode();
         $shippingMethod = $carrierCode . '_' . $methodCode;
         $quote = $this->quoteRepository->getActive($cartId);
         $address = $quote->getShippingAddress();
         $validation = $this->checkoutSession->getShipAddressValidation();
         if (is_array($validation) && isset($validation['key'])) {
             if (isset($validation['validation_status'])) {
                 $additionalDetail['address_valid'] = $validation['validation_status'];
                 $address->setValidationStatus($validation['validation_status']);
             }
             if (isset($validation['destination_type'])) {
                 $additionalDetail['destination_type'] = $validation['destination_type'];
                 $address->setDestinationType($validation['destination_type']);
             }
             $this->checkoutSession->setShipAddressValidation(null);
         }
         $address->save();
         $additionalDetail = new \Magento\Framework\DataObject();
         $extAttributes = $addressInformation->getShippingAddress()->getExtensionAttributes();
         //push out event so other modules can save their data TODO add carrier_group_id
         $this->eventManager->dispatch('shipperhq_additional_detail_checkout', ['address_extn_attributes' => $extAttributes, 'additional_detail' => $additionalDetail, 'carrier_code' => $carrierCode]);
         $additionalDetailArray = $additionalDetail->convertToArray();
         $this->shipperLogger->postDebug('ShipperHQ Shipper', 'processing additional detail ', $additionalDetail);
         $this->carrierGroupHelper->saveCarrierGroupInformation($address, $shippingMethod, $additionalDetailArray);
     } catch (\Exception $e) {
         $this->shipperLogger->postCritical('Shipperhq_Shipper', 'Shipping Information Plugin', 'Exception raised ' . $e->getMessage());
     }
     $result = $proceed($cartId, $addressInformation);
     if ($address->getCustomerId()) {
         $customerAddresses = $quote->getCustomer()->getAddresses();
         foreach ($customerAddresses as $oneAddress) {
             if ($oneAddress->getId() == $address->getCustomerAddressId()) {
                 if ($address->getValidationStatus()) {
                     $oneAddress->setCustomAttribute('validation_status', $address->getValidationStatus());
                 }
                 if ($address->getDestinationType()) {
                     $oneAddress->setCustomAttribute('destination_type', $address->getDestinationType());
                 }
                 $this->addressRepository->save($oneAddress);
             }
         }
     }
     return $result;
 }
開發者ID:shipperhq,項目名稱:module-shipper,代碼行數:57,代碼來源:ShippingInformationPlugin.php

示例14: deleteById

 /**
  * {@inheritdoc}
  */
 public function deleteById($cartId, $itemId)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     $quoteItem = $quote->getItemById($itemId);
     if (!$quoteItem) {
         throw new NoSuchEntityException(__('Cart %1 doesn\'t contain item  %2', $cartId, $itemId));
     }
     try {
         $quote->removeItem($itemId);
         $this->quoteRepository->save($quote->collectTotals());
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not remove item from quote'));
     }
     return true;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:19,代碼來源:Repository.php

示例15: save

 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage, $itemId)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     if (!($item = $quote->getItemById($itemId))) {
         throw new NoSuchEntityException(__('There is no product with provided  itemId: %1 in the cart', $itemId));
     }
     if ($item->getIsVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $messageText = $giftMessage->getMessage();
     if ($messageText && !$this->helper->isMessagesAllowed('items', $quote, $this->storeManager->getStore())) {
         throw new CouldNotSaveException(__('Gift Message is not available'));
     }
     $this->giftMessageManager->setMessage($quote, 'quote_item', $giftMessage, $itemId);
     return true;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:24,代碼來源:ItemRepository.php


注:本文中的Magento\Quote\Api\CartRepositoryInterface::getActive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。