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/Cnc/Catalog/Model/Product/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Cnc/Catalog/Model/Product/Price.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)
 * cnc_catalog_m2
 * <[email protected]>
 */

declare(strict_types=1);

namespace Cnc\Catalog\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\GroupedProduct\Model\Product\Type\Grouped;

class Price implements ArgumentInterface
{
    /**
     * @var PriceCurrencyInterface
     */
    private $priceCurrency;

    /**
     * @var ProductRepositoryInterface
     */
    private $productRepositoryInterface;

    /**
     * Price constructor.
     *
     * @param PriceCurrencyInterface $priceCurrency
     * @param ProductRepositoryInterface $productRepositoryInterface
     */
    public function __construct(
        PriceCurrencyInterface $priceCurrency,
        ProductRepositoryInterface $productRepositoryInterface
    ) {
        $this->priceCurrency = $priceCurrency;
        $this->productRepositoryInterface = $productRepositoryInterface;
    }

    /**
     * @param ProductInterface $product
     * @param bool $withTranslate
     *
     * @return string
     * @todo add project logic
     */
    public function getTierPriceLabel(ProductInterface $product, $withTranslate = true): string
    {
        if ($this->hasTierPrices($product)) {
            return $withTranslate
                ? __('Tier prices !')->__toString()
                : 'Tier prices !';
        }

        return '';
    }

    /**
     * @param ProductInterface $product
     *
     * @return bool
     */
    public function hasTierPrices(ProductInterface $product): bool
    {
        return $product->getTierPrices() ? true : false;
    }

    /**
     * @param ProductInterface $product
     *
     * @return string
     */
    public function getPercentageDiscount(ProductInterface $product): string
    {
        $originalPrice = $product->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getValue();
        $finalPrice = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();

        if ($product->getTypeId() == Grouped::TYPE_CODE) {
            $minProduct = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getMinProduct();
            $originalPrice = $minProduct ?
                $minProduct->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getValue() : $originalPrice;
        }

        if ($originalPrice > $finalPrice) {
            return number_format(($originalPrice - $finalPrice) * 100 / $originalPrice, 0);
        }

        return '';
    }

    /**
     * @param ProductInterface $product
     *
     * @return string
     */
    public function getManufacturerPrice(ProductInterface $product): string
    {
        return $product->getCncManufacturerPrice() ?: '';
    }

    /**
     * @param ProductInterface $product
     *
     * @param ProductInterface|null $parentProduct
     * @return float
     * @throws NoSuchEntityException
     */
    public function getSavedAmount(ProductInterface $product, ProductInterface $parentProduct = null): float
    {
        $savedMoney = 0;
        if ($product->getCncManufacturerPrice() && $product->getPrice()) {
            $savedMoney = $product->getCncManufacturerPrice() - $product->getPrice();
        } elseif ($parentProduct || $product->getData('_linked_to_product_id')) {
            $groupedProduct = $parentProduct
                ?: $this->productRepositoryInterface->getById($product->getData('_linked_to_product_id'));
            if ($groupedProduct->getCncManufacturerPrice() && $product->getPrice()) {
                $savedMoney = $groupedProduct->getCncManufacturerPrice() - $product->getPrice();
            }
        }
        return $savedMoney;
    }

    /**
     * Format Price
     *
     * @param $price
     *
     * @return string
     */
    public function formatPrice($price): string
    {
        return (string)$this->priceCurrency->format(
            $price
        );
    }

    /**
     * @param ProductInterface $product
     *
     * @return string
     */
    public function getManufacturerPriceLastUpdateDate(ProductInterface $product): string
    {
        $date = '';
        if ($product->getCncManufacturerPriceDate()) {
            $date = date('m-Y', strtotime($product->getCncManufacturerPriceDate()));
        }
        return $date;
    }
}

Spamworldpro Mini