![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/InventoryCatalog/Model/Product/Checkout/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ namespace Ecombricks\InventoryCatalog\Model\Product\Checkout; /** * Default product checkout config provider */ class DefaultConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface { /** * Product * * @var \Magento\Catalog\Model\Product */ protected $product; /** * Registry * * @var \Magento\Framework\Registry */ protected $registry; /** * Locale format * * @var \Magento\Framework\Locale\FormatInterface */ protected $localeFormat; /** * Post code config * * @var \Magento\Directory\Model\Country\Postcode\ConfigInterface */ protected $postCodeConfig; /** * Scope config * * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $scopeConfig; /** * Shipping config * * @var \Magento\Shipping\Model\Config */ protected $shippingConfig; /** * Source management * * @var \Ecombricks\Inventory\Model\SourceManagement */ protected $sourceManagement; /** * Source item management * * @var \Ecombricks\InventoryInventorySales\Model\SourceItemManagement */ protected $sourceItemManagement; /** * Sources * * @var array */ protected $sources; /** * Constructor * * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Directory\Model\Country\Postcode\ConfigInterface $postCodeConfig * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Shipping\Model\Config $shippingConfig * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement * @param \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement * @return void */ public function __construct( \Magento\Framework\Registry $registry, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Directory\Model\Country\Postcode\ConfigInterface $postCodeConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Shipping\Model\Config $shippingConfig, \Ecombricks\Inventory\Model\SourceManagement $sourceManagement, \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement ) { $this->registry = $registry; $this->localeFormat = $localeFormat; $this->postCodeConfig = $postCodeConfig; $this->scopeConfig = $scopeConfig; $this->shippingConfig = $shippingConfig; $this->sourceManagement = $sourceManagement; $this->sourceItemManagement = $sourceItemManagement; } /** * Get product * * @return \Magento\Catalog\Model\Product */ protected function getProduct() { if ($this->product !== null) { return $this->product; } $this->product = $this->registry->registry('product'); return $this->product; } /** * Get store * * @return \Magento\Store\Model\Store */ protected function getStore() { return $this->getProduct()->getStore(); } /** * Get sources * * @return array */ protected function getSources() { if ($this->sources !== null) { return $this->sources; } $this->sources = []; $product = $this->getProduct(); foreach ($this->sourceItemManagement->getProductCurrentStockSalableSourceCodes($product) as $sourceCode) { $source = $this->sourceManagement->getSource($sourceCode); $this->sources[] = [ 'source_code' => $source->getSourceCode(), 'name' => $source->getName(), ]; } return $this->sources; } /** * Get quote data * * @return array */ protected function getQuoteData() { $product = $this->getProduct(); return [ 'is_virtual' => $product->isVirtual(), ]; } /** * Get product data * * @return array */ protected function getProductData() { $product = $this->getProduct(); return [ 'sku' => $product->getData(\Magento\Catalog\Api\Data\ProductInterface::SKU), 'is_virtual' => $product->isVirtual(), 'sources' => $this->getSources(), ]; } /** * Get active carriers * * @return array */ protected function getActiveCarriers() { $activeCarriers = []; foreach ($this->shippingConfig->getActiveCarriers() as $carrier) { $activeCarriers[] = $carrier->getCarrierCode(); } return $activeCarriers; } /** * Get origin country code * * @return string */ protected function getOriginCountryCode() { return $this->scopeConfig->getValue( \Magento\Shipping\Model\Config::XML_PATH_ORIGIN_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->getStore() ); } /** * Get config * * @return array|mixed * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getConfig() { $store = $this->getStore(); $output = []; $output['quoteData'] = $this->getQuoteData(); $output['productData'] = $this->getProductData(); $output['quoteItemData'] = []; $output['storeCode'] = $store->getCode(); $output['priceFormat'] = $this->localeFormat->getPriceFormat(null, $store->getCurrentCurrency()->getCode()); $output['basePriceFormat'] = $this->localeFormat->getPriceFormat(null, $store->getBaseCurrency()->getCode()); $output['postCodes'] = $this->postCodeConfig->getPostCodes(); $output['totalsData'] = []; $output['activeCarriers'] = $this->getActiveCarriers(); $output['originCountryCode'] = $this->getOriginCountryCode(); return $output; } }