123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Checkout\Model;
- use Magento\Catalog\Helper\Product\ConfigurationPool;
- use Magento\Checkout\Helper\Data as CheckoutHelper;
- use Magento\Checkout\Model\Session as CheckoutSession;
- use Magento\Customer\Api\AddressMetadataInterface;
- use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
- use Magento\Customer\Model\Context as CustomerContext;
- use Magento\Customer\Model\Session as CustomerSession;
- use Magento\Customer\Model\Url as CustomerUrlManager;
- use Magento\Eav\Api\AttributeOptionManagementInterface;
- use Magento\Framework\Api\CustomAttributesDataInterface;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\App\Http\Context as HttpContext;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\Data\Form\FormKey;
- use Magento\Framework\Locale\FormatInterface as LocaleFormat;
- use Magento\Framework\UrlInterface;
- use Magento\Quote\Api\CartItemRepositoryInterface as QuoteItemRepository;
- use Magento\Quote\Api\CartTotalRepositoryInterface;
- use Magento\Quote\Api\Data\AddressInterface;
- use Magento\Quote\Api\ShippingMethodManagementInterface as ShippingMethodManager;
- use Magento\Quote\Model\QuoteIdMaskFactory;
- use Magento\Store\Model\ScopeInterface;
- use Magento\Ui\Component\Form\Element\Multiline;
- /**
- * Default Config Provider
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyFields)
- */
- class DefaultConfigProvider implements ConfigProviderInterface
- {
- /**
- * @var AttributeOptionManagementInterface
- */
- private $attributeOptionManager;
- /**
- * @var CheckoutHelper
- */
- private $checkoutHelper;
- /**
- * @var CheckoutSession
- */
- private $checkoutSession;
- /**
- * @var CustomerRepository
- */
- private $customerRepository;
- /**
- * @var CustomerSession
- */
- private $customerSession;
- /**
- * @var CustomerUrlManager
- */
- private $customerUrlManager;
- /**
- * @var HttpContext
- */
- private $httpContext;
- /**
- * @var \Magento\Quote\Api\CartRepositoryInterface
- */
- private $quoteRepository;
- /**
- * @var QuoteItemRepository
- */
- private $quoteItemRepository;
- /**
- * @var ShippingMethodManager
- */
- private $shippingMethodManager;
- /**
- * @var ConfigurationPool
- */
- private $configurationPool;
- /**
- * @param QuoteIdMaskFactory
- */
- protected $quoteIdMaskFactory;
- /**
- * @var LocaleFormat
- */
- protected $localeFormat;
- /**
- * @var \Magento\Customer\Model\Address\Mapper
- */
- protected $addressMapper;
- /**
- * @var \Magento\Customer\Model\Address\Config
- */
- protected $addressConfig;
- /**
- * @var FormKey
- */
- protected $formKey;
- /**
- * @var \Magento\Catalog\Helper\Image
- */
- protected $imageHelper;
- /**
- * @var \Magento\Framework\View\ConfigInterface
- */
- protected $viewConfig;
- /**
- * @var \Magento\Directory\Model\Country\Postcode\ConfigInterface
- */
- protected $postCodesConfig;
- /**
- * @var \Magento\Directory\Helper\Data
- */
- protected $directoryHelper;
- /**
- * @var Cart\ImageProvider
- */
- protected $imageProvider;
- /**
- * @var CartTotalRepositoryInterface
- */
- protected $cartTotalRepository;
- /**
- * @var ScopeConfigInterface
- */
- protected $scopeConfig;
- /**
- * @var \Magento\Shipping\Model\Config
- */
- protected $shippingMethodConfig;
- /**
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $storeManager;
- /**
- * @var \Magento\Quote\Api\PaymentMethodManagementInterface
- */
- protected $paymentMethodManagement;
- /**
- * @var UrlInterface
- */
- protected $urlBuilder;
- /**
- * @var AddressMetadataInterface
- */
- private $addressMetadata;
- /**
- * @param CheckoutHelper $checkoutHelper
- * @param Session $checkoutSession
- * @param CustomerRepository $customerRepository
- * @param CustomerSession $customerSession
- * @param CustomerUrlManager $customerUrlManager
- * @param HttpContext $httpContext
- * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
- * @param QuoteItemRepository $quoteItemRepository
- * @param ShippingMethodManager $shippingMethodManager
- * @param ConfigurationPool $configurationPool
- * @param QuoteIdMaskFactory $quoteIdMaskFactory
- * @param LocaleFormat $localeFormat
- * @param \Magento\Customer\Model\Address\Mapper $addressMapper
- * @param \Magento\Customer\Model\Address\Config $addressConfig
- * @param FormKey $formKey
- * @param \Magento\Catalog\Helper\Image $imageHelper
- * @param \Magento\Framework\View\ConfigInterface $viewConfig
- * @param \Magento\Directory\Model\Country\Postcode\ConfigInterface $postCodesConfig
- * @param Cart\ImageProvider $imageProvider
- * @param \Magento\Directory\Helper\Data $directoryHelper
- * @param CartTotalRepositoryInterface $cartTotalRepository
- * @param ScopeConfigInterface $scopeConfig
- * @param \Magento\Shipping\Model\Config $shippingMethodConfig
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
- * @param UrlInterface $urlBuilder
- * @param AddressMetadataInterface $addressMetadata
- * @param AttributeOptionManagementInterface $attributeOptionManager
- * @codeCoverageIgnore
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- CheckoutHelper $checkoutHelper,
- CheckoutSession $checkoutSession,
- CustomerRepository $customerRepository,
- CustomerSession $customerSession,
- CustomerUrlManager $customerUrlManager,
- HttpContext $httpContext,
- \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
- QuoteItemRepository $quoteItemRepository,
- ShippingMethodManager $shippingMethodManager,
- ConfigurationPool $configurationPool,
- QuoteIdMaskFactory $quoteIdMaskFactory,
- LocaleFormat $localeFormat,
- \Magento\Customer\Model\Address\Mapper $addressMapper,
- \Magento\Customer\Model\Address\Config $addressConfig,
- FormKey $formKey,
- \Magento\Catalog\Helper\Image $imageHelper,
- \Magento\Framework\View\ConfigInterface $viewConfig,
- \Magento\Directory\Model\Country\Postcode\ConfigInterface $postCodesConfig,
- Cart\ImageProvider $imageProvider,
- \Magento\Directory\Helper\Data $directoryHelper,
- CartTotalRepositoryInterface $cartTotalRepository,
- ScopeConfigInterface $scopeConfig,
- \Magento\Shipping\Model\Config $shippingMethodConfig,
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
- UrlInterface $urlBuilder,
- AddressMetadataInterface $addressMetadata = null,
- AttributeOptionManagementInterface $attributeOptionManager = null
- ) {
- $this->checkoutHelper = $checkoutHelper;
- $this->checkoutSession = $checkoutSession;
- $this->customerRepository = $customerRepository;
- $this->customerSession = $customerSession;
- $this->customerUrlManager = $customerUrlManager;
- $this->httpContext = $httpContext;
- $this->quoteRepository = $quoteRepository;
- $this->quoteItemRepository = $quoteItemRepository;
- $this->shippingMethodManager = $shippingMethodManager;
- $this->configurationPool = $configurationPool;
- $this->quoteIdMaskFactory = $quoteIdMaskFactory;
- $this->localeFormat = $localeFormat;
- $this->addressMapper = $addressMapper;
- $this->addressConfig = $addressConfig;
- $this->formKey = $formKey;
- $this->imageHelper = $imageHelper;
- $this->viewConfig = $viewConfig;
- $this->postCodesConfig = $postCodesConfig;
- $this->imageProvider = $imageProvider;
- $this->directoryHelper = $directoryHelper;
- $this->cartTotalRepository = $cartTotalRepository;
- $this->scopeConfig = $scopeConfig;
- $this->shippingMethodConfig = $shippingMethodConfig;
- $this->storeManager = $storeManager;
- $this->paymentMethodManagement = $paymentMethodManagement;
- $this->urlBuilder = $urlBuilder;
- $this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class);
- $this->attributeOptionManager = $attributeOptionManager ??
- ObjectManager::getInstance()->get(AttributeOptionManagementInterface::class);
- }
- /**
- * Return configuration array
- *
- * @return array|mixed
- * @throws \Magento\Framework\Exception\NoSuchEntityException
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function getConfig()
- {
- $quote = $this->checkoutSession->getQuote();
- $quoteId = $quote->getId();
- $email = $quote->getShippingAddress()->getEmail();
- $quoteItemData = $this->getQuoteItemData();
- $output['formKey'] = $this->formKey->getFormKey();
- $output['customerData'] = $this->getCustomerData();
- $output['quoteData'] = $this->getQuoteData();
- $output['quoteItemData'] = $quoteItemData;
- $output['quoteMessages'] = $this->getQuoteItemsMessages($quoteItemData);
- $output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
- $output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
- if ($email && !$this->isCustomerLoggedIn()) {
- $shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress());
- $billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress());
- $output['shippingAddressFromData'] = $shippingAddressFromData;
- if ($shippingAddressFromData != $billingAddressFromData) {
- $output['billingAddressFromData'] = $billingAddressFromData;
- }
- $output['validatedEmailValue'] = $email;
- }
- $output['storeCode'] = $this->getStoreCode();
- $output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed();
- $output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired();
- $output['registerUrl'] = $this->getRegisterUrl();
- $output['checkoutUrl'] = $this->getCheckoutUrl();
- $output['defaultSuccessPageUrl'] = $this->getDefaultSuccessPageUrl();
- $output['pageNotFoundUrl'] = $this->pageNotFoundUrl();
- $output['forgotPasswordUrl'] = $this->getForgotPasswordUrl();
- $output['staticBaseUrl'] = $this->getStaticBaseUrl();
- $output['priceFormat'] = $this->localeFormat->getPriceFormat(
- null,
- $quote->getQuoteCurrencyCode()
- );
- $output['basePriceFormat'] = $this->localeFormat->getPriceFormat(
- null,
- $quote->getBaseCurrencyCode()
- );
- $output['postCodes'] = $this->postCodesConfig->getPostCodes();
- $output['imageData'] = $this->imageProvider->getImages($quoteId);
- $output['totalsData'] = $this->getTotalsData();
- $output['shippingPolicy'] = [
- 'isEnabled' => $this->scopeConfig->isSetFlag(
- 'shipping/shipping_policy/enable_shipping_policy',
- ScopeInterface::SCOPE_STORE
- ),
- 'shippingPolicyContent' => nl2br(
- $this->scopeConfig->getValue(
- 'shipping/shipping_policy/shipping_policy_content',
- ScopeInterface::SCOPE_STORE
- )
- )
- ];
- $output['activeCarriers'] = $this->getActiveCarriers();
- $output['originCountryCode'] = $this->getOriginCountryCode();
- $output['paymentMethods'] = $this->getPaymentMethods();
- $output['autocomplete'] = $this->isAutocompleteEnabled();
- $output['displayBillingOnPaymentMethod'] = $this->checkoutHelper->isDisplayBillingOnPaymentMethodAvailable();
- return $output;
- }
- /**
- * Is autocomplete enabled for storefront
- *
- * @return string
- * @codeCoverageIgnore
- */
- private function isAutocompleteEnabled()
- {
- return $this->scopeConfig->getValue(
- \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- ) ? 'on' : 'off';
- }
- /**
- * Retrieve customer data
- *
- * @return array
- */
- private function getCustomerData()
- {
- $customerData = [];
- if ($this->isCustomerLoggedIn()) {
- $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
- $customerData = $customer->__toArray();
- foreach ($customer->getAddresses() as $key => $address) {
- $customerData['addresses'][$key]['inline'] = $this->getCustomerAddressInline($address);
- if ($address->getCustomAttributes()) {
- $customerData['addresses'][$key]['custom_attributes'] = $this->filterNotVisibleAttributes(
- $customerData['addresses'][$key]['custom_attributes']
- );
- }
- }
- }
- return $customerData;
- }
- /**
- * Filter not visible on storefront custom attributes.
- *
- * @param array $attributes
- * @return array
- */
- private function filterNotVisibleAttributes(array $attributes)
- {
- $attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
- foreach ($attributesMetadata as $attributeMetadata) {
- if (!$attributeMetadata->isVisible()) {
- unset($attributes[$attributeMetadata->getAttributeCode()]);
- }
- }
- return $this->setLabelsToAttributes($attributes);
- }
- /**
- * Set additional customer address data
- *
- * @param \Magento\Customer\Api\Data\AddressInterface $address
- * @return string
- */
- private function getCustomerAddressInline($address)
- {
- $builtOutputAddressData = $this->addressMapper->toFlatArray($address);
- return $this->addressConfig
- ->getFormatByCode(\Magento\Customer\Model\Address\Config::DEFAULT_ADDRESS_FORMAT)
- ->getRenderer()
- ->renderArray($builtOutputAddressData);
- }
- /**
- * Retrieve quote data
- *
- * @return array
- */
- private function getQuoteData()
- {
- $quoteData = [];
- if ($this->checkoutSession->getQuote()->getId()) {
- $quote = $this->quoteRepository->get($this->checkoutSession->getQuote()->getId());
- $quoteData = $quote->toArray();
- $quoteData['is_virtual'] = $quote->getIsVirtual();
- if (!$quote->getCustomer()->getId()) {
- /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
- $quoteIdMask = $this->quoteIdMaskFactory->create();
- $quoteData['entity_id'] = $quoteIdMask->load(
- $this->checkoutSession->getQuote()->getId(),
- 'quote_id'
- )->getMaskedId();
- }
- }
- return $quoteData;
- }
- /**
- * Retrieve quote item data
- *
- * @return array
- */
- private function getQuoteItemData()
- {
- $quoteItemData = [];
- $quoteId = $this->checkoutSession->getQuote()->getId();
- if ($quoteId) {
- $quoteItems = $this->quoteItemRepository->getList($quoteId);
- foreach ($quoteItems as $index => $quoteItem) {
- $quoteItemData[$index] = $quoteItem->toArray();
- $quoteItemData[$index]['options'] = $this->getFormattedOptionValue($quoteItem);
- $quoteItemData[$index]['thumbnail'] = $this->imageHelper->init(
- $quoteItem->getProduct(),
- 'product_thumbnail_image'
- )->getUrl();
- $quoteItemData[$index]['message'] = $quoteItem->getMessage();
- }
- }
- return $quoteItemData;
- }
- /**
- * Retrieve formatted item options view
- *
- * @param \Magento\Quote\Api\Data\CartItemInterface $item
- * @return array
- */
- protected function getFormattedOptionValue($item)
- {
- $optionsData = [];
- $options = $this->configurationPool->getByProductType($item->getProductType())->getOptions($item);
- foreach ($options as $index => $optionValue) {
- /* @var $helper \Magento\Catalog\Helper\Product\Configuration */
- $helper = $this->configurationPool->getByProductType('default');
- $params = [
- 'max_length' => 55,
- 'cut_replacer' => ' <a href="#" class="dots tooltip toggle" onclick="return false">...</a>'
- ];
- $option = $helper->getFormattedOptionValue($optionValue, $params);
- $optionsData[$index] = $option;
- $optionsData[$index]['label'] = $optionValue['label'];
- }
- return $optionsData;
- }
- /**
- * Retrieve customer registration URL
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getRegisterUrl()
- {
- return $this->customerUrlManager->getRegisterUrl();
- }
- /**
- * Retrieve checkout URL
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getCheckoutUrl()
- {
- return $this->urlBuilder->getUrl('checkout');
- }
- /**
- * Retrieve checkout URL
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function pageNotFoundUrl()
- {
- return $this->urlBuilder->getUrl('checkout/noroute');
- }
- /**
- * Retrieve default success page URL
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getDefaultSuccessPageUrl()
- {
- return $this->urlBuilder->getUrl('checkout/onepage/success/');
- }
- /**
- * Retrieve selected shipping method
- *
- * @return array|null
- */
- private function getSelectedShippingMethod()
- {
- $shippingMethodData = null;
- try {
- $quoteId = $this->checkoutSession->getQuote()->getId();
- $shippingMethod = $this->shippingMethodManager->get($quoteId);
- if ($shippingMethod) {
- $shippingMethodData = $shippingMethod->__toArray();
- }
- } catch (\Exception $exception) {
- $shippingMethodData = null;
- }
- return $shippingMethodData;
- }
- /**
- * Create address data appropriate to fill checkout address form
- *
- * @param AddressInterface $address
- * @return array
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function getAddressFromData(AddressInterface $address)
- {
- $addressData = [];
- $attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
- foreach ($attributesMetadata as $attributeMetadata) {
- if (!$attributeMetadata->isVisible()) {
- continue;
- }
- $attributeCode = $attributeMetadata->getAttributeCode();
- $attributeData = $address->getData($attributeCode);
- if ($attributeData) {
- if ($attributeMetadata->getFrontendInput() === Multiline::NAME) {
- $attributeData = \is_array($attributeData) ? $attributeData : explode("\n", $attributeData);
- $attributeData = (object)$attributeData;
- }
- if ($attributeMetadata->isUserDefined()) {
- $addressData[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES][$attributeCode] = $attributeData;
- continue;
- }
- $addressData[$attributeCode] = $attributeData;
- }
- }
- return $addressData;
- }
- /**
- * Retrieve store code
- *
- * @return string
- * @codeCoverageIgnore
- */
- private function getStoreCode()
- {
- return $this->checkoutSession->getQuote()->getStore()->getCode();
- }
- /**
- * Check if guest checkout is allowed
- *
- * @return bool
- * @codeCoverageIgnore
- */
- private function isGuestCheckoutAllowed()
- {
- return $this->checkoutHelper->isAllowedGuestCheckout($this->checkoutSession->getQuote());
- }
- /**
- * Check if customer is logged in
- *
- * @return bool
- * @codeCoverageIgnore
- */
- private function isCustomerLoggedIn()
- {
- return (bool)$this->httpContext->getValue(CustomerContext::CONTEXT_AUTH);
- }
- /**
- * Check if customer must be logged in to proceed with checkout
- *
- * @return bool
- * @codeCoverageIgnore
- */
- private function isCustomerLoginRequired()
- {
- return $this->checkoutHelper->isCustomerMustBeLogged();
- }
- /**
- * Return forgot password URL
- *
- * @return string
- * @codeCoverageIgnore
- */
- private function getForgotPasswordUrl()
- {
- return $this->customerUrlManager->getForgotPasswordUrl();
- }
- /**
- * Return base static url.
- *
- * @return string
- * @codeCoverageIgnore
- */
- protected function getStaticBaseUrl()
- {
- return $this->checkoutSession->getQuote()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_STATIC);
- }
- /**
- * Return quote totals data
- *
- * @return array
- */
- private function getTotalsData()
- {
- /** @var \Magento\Quote\Api\Data\TotalsInterface $totals */
- $totals = $this->cartTotalRepository->get($this->checkoutSession->getQuote()->getId());
- $items = [];
- /** @var \Magento\Quote\Model\Cart\Totals\Item $item */
- foreach ($totals->getItems() as $item) {
- $items[] = $item->__toArray();
- }
- $totalSegmentsData = [];
- /** @var \Magento\Quote\Model\Cart\TotalSegment $totalSegment */
- foreach ($totals->getTotalSegments() as $totalSegment) {
- $totalSegmentArray = $totalSegment->toArray();
- if (is_object($totalSegment->getExtensionAttributes())) {
- $totalSegmentArray['extension_attributes'] = $totalSegment->getExtensionAttributes()->__toArray();
- }
- $totalSegmentsData[] = $totalSegmentArray;
- }
- $totals->setItems($items);
- $totals->setTotalSegments($totalSegmentsData);
- $totalsArray = $totals->toArray();
- if (is_object($totals->getExtensionAttributes())) {
- $totalsArray['extension_attributes'] = $totals->getExtensionAttributes()->__toArray();
- }
- return $totalsArray;
- }
- /**
- * Returns active carriers codes
- *
- * @return array
- */
- private function getActiveCarriers()
- {
- $activeCarriers = [];
- foreach ($this->shippingMethodConfig->getActiveCarriers() as $carrier) {
- $activeCarriers[] = $carrier->getCarrierCode();
- }
- return $activeCarriers;
- }
- /**
- * Returns origin country code
- *
- * @return string
- */
- private function getOriginCountryCode()
- {
- return $this->scopeConfig->getValue(
- \Magento\Shipping\Model\Config::XML_PATH_ORIGIN_COUNTRY_ID,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $this->storeManager->getStore()
- );
- }
- /**
- * Returns array of payment methods
- *
- * @return array $paymentMethods
- * @throws \Magento\Framework\Exception\NoSuchEntityException
- */
- private function getPaymentMethods()
- {
- $paymentMethods = [];
- $quote = $this->checkoutSession->getQuote();
- if ($quote->getIsVirtual()) {
- foreach ($this->paymentMethodManagement->getList($quote->getId()) as $paymentMethod) {
- $paymentMethods[] = [
- 'code' => $paymentMethod->getCode(),
- 'title' => $paymentMethod->getTitle()
- ];
- }
- }
- return $paymentMethods;
- }
- /**
- * Set Labels to custom Attributes
- *
- * @param array $customAttributes
- * @return array $customAttributes
- * @throws \Magento\Framework\Exception\InputException
- * @throws \Magento\Framework\Exception\StateException
- */
- private function setLabelsToAttributes(array $customAttributes) : array
- {
- if (!empty($customAttributes)) {
- foreach ($customAttributes as $customAttributeCode => $customAttribute) {
- $attributeOptionLabels = $this->getAttributeLabels($customAttribute, $customAttributeCode);
- if (!empty($attributeOptionLabels)) {
- $customAttributes[$customAttributeCode]['label'] = implode(', ', $attributeOptionLabels);
- }
- }
- }
- return $customAttributes;
- }
- /**
- * Get Labels by CustomAttribute and CustomAttributeCode
- *
- * @param array $customAttribute
- * @param string|integer $customAttributeCode
- * @return array $attributeOptionLabels
- * @throws \Magento\Framework\Exception\InputException
- * @throws \Magento\Framework\Exception\StateException
- */
- private function getAttributeLabels(array $customAttribute, string $customAttributeCode) : array
- {
- $attributeOptionLabels = [];
- if (!empty($customAttribute['value'])) {
- $customAttributeValues = explode(',', $customAttribute['value']);
- $attributeOptions = $this->attributeOptionManager->getItems(
- \Magento\Customer\Model\Indexer\Address\AttributeProvider::ENTITY,
- $customAttributeCode
- );
- if (!empty($attributeOptions)) {
- foreach ($attributeOptions as $attributeOption) {
- $attributeOptionValue = $attributeOption->getValue();
- if (in_array($attributeOptionValue, $customAttributeValues)) {
- $attributeOptionLabels[] = $attributeOption->getLabel() ?? $attributeOptionValue;
- }
- }
- }
- }
- return $attributeOptionLabels;
- }
- /**
- * Get notification messages for the quote items
- *
- * @param array $quoteItemData
- * @return array
- */
- private function getQuoteItemsMessages(array $quoteItemData): array
- {
- $quoteItemsMessages = [];
- if ($quoteItemData) {
- foreach ($quoteItemData as $item) {
- $quoteItemsMessages[$item['item_id']] = $item['message'];
- }
- }
- return $quoteItemsMessages;
- }
- }
|