本文整理汇总了PHP中Magento\Quote\Model\QuoteRepository::getActive方法的典型用法代码示例。如果您正苦于以下问题:PHP QuoteRepository::getActive方法的具体用法?PHP QuoteRepository::getActive怎么用?PHP QuoteRepository::getActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\QuoteRepository
的用法示例。
在下文中一共展示了QuoteRepository::getActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* {@inheritDoc}
*
* @param int $cartId The cart ID.
* @return Totals Quote totals data.
*/
public function get($cartId)
{
/**
* Quote.
*
* @var \Magento\Quote\Model\Quote $quote
*/
$quote = $this->quoteRepository->getActive($cartId);
$shippingAddress = $quote->getShippingAddress();
if ($quote->isVirtual()) {
$totalsData = array_merge($quote->getBillingAddress()->getData(), $quote->getData());
} else {
$totalsData = array_merge($shippingAddress->getData(), $quote->getData());
}
$totals = $this->totalsFactory->create();
$this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
$items = [];
$weeeTaxAppliedAmount = 0;
foreach ($quote->getAllVisibleItems() as $index => $item) {
$items[$index] = $this->itemConverter->modelToDataObject($item);
$weeeTaxAppliedAmount += $item->getWeeeTaxAppliedAmount();
}
$totals->setCouponCode($this->couponService->get($cartId));
$calculatedTotals = $this->totalsConverter->process($quote->getTotals());
$amount = $totals->getGrandTotal() - $totals->getTaxAmount();
$amount = $amount > 0 ? $amount : 0;
$totals->setGrandTotal($amount);
$totals->setTotalSegments($calculatedTotals);
$totals->setItems($items);
$totals->setWeeeTaxAppliedAmount($weeeTaxAppliedAmount);
return $totals;
}
示例2: aroundGet
/**
* @param CartTotalRepository $subject
* @param \Closure $proceed
* @param int $cartId
* @return \Magento\Quote\Model\Cart\Totals
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGet(CartTotalRepository $subject, \Closure $proceed, $cartId)
{
$result = $proceed($cartId);
$quote = $this->quoteRepository->getActive($cartId);
$totals = $quote->getTotals();
if (!array_key_exists('tax', $totals)) {
return $result;
}
$taxes = $totals['tax']->getData();
if (!array_key_exists('full_info', $taxes)) {
return $result;
}
$detailsId = 1;
$finalData = [];
foreach ($taxes['full_info'] as $info) {
if (array_key_exists('hidden', $info) && $info['hidden'] || $info['amount'] == 0 && $this->taxConfig->displayCartZeroTax()) {
continue;
}
$taxDetails = $this->detailsFactory->create([]);
$taxDetails->setAmount($info['amount']);
$taxRates = $this->getRatesData($info['rates']);
$taxDetails->setRates($taxRates);
$taxDetails->setGroupId($detailsId);
$finalData[] = $taxDetails;
$detailsId++;
}
$attributes = $result->getExtensionAttributes();
if ($attributes === null) {
$attributes = $this->extensionFactory->create();
}
$attributes->setTaxGrandtotalDetails($finalData);
/** @var $result \Magento\Quote\Model\Cart\Totals */
$result->setExtensionAttributes($attributes);
return $result;
}
示例3: beforeSaveAddressInformation
/**
* @param \Magento\Checkout\Model\ShippingInformationManagement $subject
* @param $cartId
* @param \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
*/
public function beforeSaveAddressInformation(\Magento\Checkout\Model\ShippingInformationManagement $subject, $cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
{
$customFee = $addressInformation->getExtensionAttributes()->getFee();
$quote = $this->quoteRepository->getActive($cartId);
if ($customFee) {
$fee = $this->dataHelper->getCustomFee();
$quote->setFee($fee);
} else {
$quote->setFee(NULL);
}
}
示例4: get
/**
* {@inheritDoc}
*
* @param int $cartId The cart ID.
* @return Totals Quote totals data.
*/
public function get($cartId)
{
/**
* Quote.
*
* @var \Magento\Quote\Model\Quote $quote
*/
$quote = $this->quoteRepository->getActive($cartId);
$shippingAddress = $quote->getShippingAddress();
$totalsData = array_merge($shippingAddress->getData(), $quote->getData());
$totals = $this->totalsFactory->create();
$this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
$totals->setItems($quote->getAllItems());
return $totals;
}
示例5: placeOrder
/**
* {@inheritdoc}
*/
public function placeOrder($cartId, $agreements = null, 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();
if (isset($data['additional_data'])) {
$data = array_merge($data, (array) $data['additional_data']);
unset($data['additional_data']);
}
$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);
}
$order = $this->submit($quote);
$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();
}
示例6: 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'));
}
$billingAddress = $quote->getBillingAddress();
if (!$billingAddress->getCountryId()) {
throw new StateException(__('Billing 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;
}
示例7: getActive
/**
* {@inheritdoc}
*/
public function getActive($cartId, array $sharedStoreIds = array())
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getActive');
if (!$pluginInfo) {
return parent::getActive($cartId, $sharedStoreIds);
} else {
return $this->___callPlugins('getActive', func_get_args(), $pluginInfo);
}
}
示例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;
}
示例9: get
/**
* {@inheritDoc}
*/
public function get($cartId)
{
/**
* Quote.
*
* @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.'));
}
/**
* Address.
*
* @var \Magento\Quote\Model\Quote\Address $address
*/
return $quote->getShippingAddress();
}
示例10: 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;
}
示例11: placeOrder
/**
* {@inheritdoc}
*/
public function placeOrder($cartId)
{
$quote = $this->quoteRepository->getActive($cartId);
if ($quote->getCheckoutMethod() === 'guest') {
$quote->setCustomerId(null);
$quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
$quote->setCustomerIsGuest(true);
$quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
}
return $this->submit($quote)->getId();
}
示例12: 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'));
}
if (!$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) {
throw new CouldNotSaveException(__('Gift Message is not available'));
}
$this->giftMessageManager->setMessage($quote, 'quote', $giftMessage);
return true;
}
示例13: 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());
}
示例14: 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;
}
示例15: 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($this->storeMock);
$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));
}