<?php

namespace Autogedal\AutogedalHelper\Block\Checkout;

class Success extends \Magento\Checkout\Block\Onepage\Success
{
    protected $_productRepository;
    protected $_storeManager;
    protected $_orderFactory;
    protected $_storeInfo;
    protected $_checkoutSession;
    protected $_orderConfig;
    protected $_httpContext;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Sales\Model\Order\Config $orderConfig,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\ProductRepository $productRepository,
        \Magento\Store\Model\Information $storeInfo,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\App\Http\Context $httpContext
    ) {
        $this->_orderFactory = $orderFactory;
        $this->_storeManager = $storeManager;
        $this->_productRepository = $productRepository;
        $this->_storeInfo = $storeInfo;
        $this->_checkoutSession = $checkoutSession;
        $this->_orderConfig = $orderConfig;
        $this->_httpContext = $httpContext;
        $data = [];
        parent::__construct($context, $checkoutSession, $orderConfig, $httpContext, $data);
    }
    public function getOrder()
    {
        return $this->_checkoutSession->getLastRealOrder();
    }

    public function getOrderProduct($productId)
    {
        $productObject = $this->_productRepository->getById($productId);
        return $productObject;
    }

    public function getProductImageUrl($product)
    {
        $store         = $this->_storeManager->getStore();
        $imageUrl      = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
        return $imageUrl;
    }

    public function getStoreInfo()
    {
        $store            = $this->_storeManager->getStore();
        $storeInfo        = $this->_storeInfo->getStoreInformationObject($store);
        return $storeInfo;
    }

}