Spamworldpro Mini Shell
Spamworldpro


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/old/app/code/Kaliop/CatalogGenericProductItem/Block/Product/ProductList/Item/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Kaliop/CatalogGenericProductItem/Block/Product/ProductList/Item/Block.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * kaliop_cataloggenericproductitem_m2
 * <[email protected]>
 */

declare(strict_types=1);

namespace Kaliop\CatalogGenericProductItem\Block\Product\ProductList\Item;

use Kaliop\CatalogGenericProductItem\ViewModel\Product\Item as ViewModelProductItem;
use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Block\Product\ListProduct as CatalogListProduct;
use Magento\Catalog\Block\Product\ProductList\Item\Block as OriginalBlock;
use Magento\Catalog\Model\Product;

class Block extends OriginalBlock
{
    /**
     * ListProduct
     */
    private $productList;

    /**
     * Block constructor.
     * @param Context $context
     * @param CatalogListProduct $productList
     * @param array $data
     */
    public function __construct(
        Context $context,
        CatalogListProduct $productList,
        array $data = []
    ) {
        parent::__construct($context, $data);

        $this->productList = $productList;
    }

    /**
     * \Magento\Catalog\Api\Data\ProductInterface can't be used as product param type,
     * because of wrong declaration in core, so \Magento\Catalog\Model\Product instead
     *
     * @param Product $product
     * @return array
     */
    public function getAddToCartPostParams(Product $product): array
    {
        return $this->productList->getAddToCartPostParams($product);
    }

    /**
     * \Magento\Catalog\Api\Data\ProductInterface can't be used as product param type,
     * because of wrong declaration in core, so \Magento\Catalog\Model\Product instead
     *
     * @param Product $product
     * @return string
     */
    public function getProductPrice(Product $product): string
    {
        /**
         * Price render is not same from list pages (category/search results), mainly for configurable products
         * Than from other areas on the site
         * Not sure why, but configurable prices render seems to not display original prices on list pages by default
         * (@see https://bit.ly/2tQzuSs or https://bit.ly/2t1plCr)
         *
         * By doing following check, we respect native behavior and different render, but might need to be adapted
         * If for example, you need to display original configurable prices on list pages
         * and so, always rely on parent method (use a Plugin on below isListPage method to adapt)
         */
        if ($this->isListPage()) {
            return $this->productList->getProductPrice($product);
        }

        return parent::getProductPrice($product);
    }

    /**
     * @return bool
     */
    public function isListPage(): bool
    {
        /**
         * @see ViewModelProductItem::renderProductListItem()
         */
        $parentBlock = $this->getData('parent_block');

        return (is_object($parentBlock) && $parentBlock instanceof CatalogListProduct);
    }
}

Spamworldpro Mini