MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.32
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //var/www/html/Modules/Product/Http/Controllers/ProductPriceController.php
<?php

namespace Modules\Product\Http\Controllers;

use Modules\Cart\CartItem;
use Darryldecode\Cart\ItemCollection;
use Modules\Product\Entities\Product;
use Modules\Product\Services\ChosenProductOptions;

class ProductPriceController
{
    /**
     * Show the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $product = Product::queryWithoutEagerRelations()
            ->select('id')
            ->withPrice()
            ->findOrFail($id);

        $variantPrice = $this->cartItem($product, request('options', []))
            ->total()
            ->convertToCurrentCurrency()
            ->format();

        return product_price_formatted($product, function ($price) use ($product, $variantPrice) {
            if (! $product->hasSpecialPrice()) {
                return $variantPrice;
            }

            return "{$variantPrice} <span class='previous-price'>{$price}</span>";
        });
    }

    private function cartItem(Product $product, array $options)
    {
        $chosenOptions = new ChosenProductOptions($product, $options);

        return new CartItem(new ItemCollection([
            'id' => $product->id,
            'quantity' => 1,
            'attributes' => [
                'product' => $product,
                'options' => $chosenOptions->getEntities(),
            ],
        ]));
    }
}