<?php
/**
 * Magetop
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */

namespace Magetop\Quotesystem\Block\Product;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Data\Helper\PostHelper;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\Url\Helper\Data as urlData;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Catalog\Block\Product\Context;

class ListProduct extends \Magento\Catalog\Block\Product\ListProduct
{

    /**
     * @param \Magetop\Quotesystem\Helper\Data                               $helper
     * @param \Magento\Framework\Json\Helper\Data                           $jsonHelper
     * @param Context                                                       $context
     * @param PostHelper                                                    $postDataHelper
     * @param Resolver                                                      $layerResolver
     * @param CategoryRepositoryInterface                                   $categoryRepository
     * @param urlData                                                       $urlHelper
     * @param array                                                         $data
     */
    public function __construct(
        \Magetop\Quotesystem\Helper\Data $helper,
        \Magento\Framework\Json\Helper\Data $jsonHelper,
        Context $context,
        PostHelper $postDataHelper,
        Resolver $layerResolver,
        CategoryRepositoryInterface $categoryRepository,
        urlData $urlHelper,
        array $data = []
    ) {
        $this->_helper = $helper;
        $this->jsonHelper = $jsonHelper;
        parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
    }

    /**
     * Get product Price
     *
     * @param Product $product
     * @return string
     */
    public function getProductPrice(Product $product)
    {
        $priceRender = $this->getPriceRender();
        $price = '';
        if ($priceRender) {
            $price = $priceRender->render(
                FinalPrice::PRICE_CODE,
                $product,
                [
                    'include_container' => true,
                    'display_minimal_price' => true,
                    'zone' => Render::ZONE_ITEM_LIST,
                    'list_category_page' => true
                ]
            );
        }
        return $price;
    }

    /**
     * Get Helper
     *
     * @return Magetop\QuoteSystem\Helper\Data
     */
    public function getHelper()
    {
        return $this->_helper;
    }

    /**
     * Get Json Helper
     *
     * @return Magento\Framework\Json\Helper\Data
     */
    public function getJsonHelper()
    {
        return $this->jsonHelper;
    }
}
