first upload all files

This commit is contained in:
NW
2023-06-11 13:14:03 +01:00
parent f14dbc52b5
commit c08b36d1b6
1705 changed files with 106852 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?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(),
],
]));
}
}