File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Products/ProductController.php
<?php
namespace App\KommaApp\Products;
use App\Http\Controllers\Controller;
use App\Http\Requests\ProductFormRequest;
use App\KommaApp\Orders\Models\Order;
use App\KommaApp\Orders\OrderService;
use App\KommaApp\Products\Models\Product;
use App\KommaApp\WeFact\WeFactService;
use App\Mail\Products\AdminProductOrderMail;
use App\Mail\Products\ProductOrderMail;
class ProductController extends Controller
{
private $modelPrefix = 'pages.products.';
private $productService;
public function __construct(ProductService $productService)
{
parent::__construct();
$this->productService = $productService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
abort(404);
// $page = $this->pageService->getPageByCodeName('shop');
// $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
// Load the highlighted products
// $highlightedProducts = $this->productService->getHighlightedProducts();
// Get the id's of the highlighted products, because we need to exclude them from the paginated products
// $productIds = $highlightedProducts->pluck('id')->all();
// $products = $this->productService->getProducts(true, true, $productIds);
// $products->withPath('/' . $this->links->products->route);
// Return view
// return \View::make($this->baseViewPath.$this->modelPrefix.'index',[
// 'page' => $page,
// 'otherLanguages' => $otherLanguageRoutes,
// 'highlightedProducts' => $highlightedProducts,
// 'products' => $products,
// ]);
}
/**
* @param Product $product
* @return \Illuminate\Contracts\View\View
*/
public function show(Product $product)
{
// Load translation by eager loading
$product->load('translation');
$page = $this->pageService->getPageByCodeName('shop');
$product->translation = $this->decodeDynamicContent($product->translation);
// Return view
return \View::make($this->baseViewPath.$this->modelPrefix.'show', [
'page' => $page,
'product' => $product,
]);
}
public function process(ProductFormRequest $request)
{
/** @var WeFactService $weFactService */
$weFactService = app()->make(WeFactService::class);
/** @var OrderService $orderService */
$orderService = app()->make(OrderService::class);
list($product, $orderProduct, $mailableValues, $orderValues) = $this->productService->convertRequest($request->except('_token', 'accept_legal', '_method'));
// Create an order for the given input
$order = $orderService->createOrderForProductable($orderValues, $orderProduct);
\Mail::send(new ProductOrderMail($order, $product));
\Mail::send(new AdminProductOrderMail($product, $mailableValues));
$orderService->sendInvoiceForOrderByWeFact($order, $product->wefact_code);
return redirect($this->links->shop->route . '/' . $product->translation->slug. '/'. __('site/routes.products.success'));
}
public function previewMail()
{
$order = Order::find(799);
$product = Product::where('id', 1)->with('translation')->first();
$mailValues = (object)[
"first_name" => "Pascal",
"last_name" => "Lemmen",
"email" => "pascal@komma.pro",
"site_url" => "Komma.pro",
"we_transfer" => "https://we.tl/t-r66XS5JsOp",
];
return new AdminProductOrderMail($product, $mailValues);
// return new ProductOrderMail($order, $product);
}
public function success(Product $product)
{
// Load translation by eager loading
$product->load('translation');
$page = $this->pageService->getPageByCodeName('shop');
// Return view
return \View::make($this->baseViewPath.$this->modelPrefix.'success', [
'page' => $page,
'product' => $product,
]);
}
/**
* Sync the given product with the billing system
*
* @param Product $product
*/
public function sync(Product $product)
{
$this->productService->syncProduct($product);
}
}