HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/debierbaron.komma.pro/app/Komma/Shop/ShopController.php
<?php

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Shop;

use Komma\NewsLetters\NewsLetterService;
use Komma\Payments\PaymentService;

class ShopController extends \BaseController
{

    public $data;

    private $shopService;
    private $paymentService;
    private $newsletterService;

    public function __construct(ShopService $shopService, PaymentService $paymentService, NewsLetterService $newsLetterService)
    {
        $this->shopService = $shopService;
        $this->paymentService = $paymentService;
        $this->newsletterService = $newsLetterService;
        $this->data = (object)[];
    }

    public function addProductToCart($productId, $quantity = 1)
    {
        $this->shopService->addProductToCart($productId, $quantity, false);

        return \Redirect::route('shop.checkout');
    }

    public function checkout()
    {
        $this->data->id = null;
        $this->data->content = (object)[];
        $this->data->content->meta_title = 'Checkout';
        $this->data->content->meta_description = 'Checkout';
        $this->data->content->code_name = 'Checkout';
        return \View::make('layouts.shop.checkout')->with('data', $this->data);

    }

    public function processCheckout()
    {

        if ($errors = $this->shopService->validateCheckoutForm()) {
            return \Redirect::back()->withErrors($errors)->withInput();
        }

        if (!\Session::has('cart.products')) dd('do nothing');

        //Save the order
        $order = $this->shopService->saveOrder();

        //Empty the sessions
        \Session::forget('cart');

        //Subscribe for the newsletter if it is set
        if (\Request::get('news_letter')) $this->newsletterService->subscribe($order);

        //Start a payment
        return $this->paymentService->startPayment($order);
    }

    public function processCheckoutSubscription()
    {
        if ($errors = $this->shopService->validateCheckoutForm()) {
            return \Redirect::back()->withErrors($errors)->withInput();
        }

        //Save the subscription
        $subscription = $this->shopService->saveSubscription();

        //Subscribe for the newsletter if it is set
        if (\Request::get('news_letter')) $this->newsletterService->subscribe($subscription);

        //Start a payment
        return $this->paymentService->startSubscriptionPayment($subscription);

    }

    public function checkoutSubscription()
    {
        //Create an subscription session
        $this->data->id = null;
        $this->data->content = (object)[];
        $this->data->content->meta_title = 'Checkout Subscription';
        $this->data->content->meta_description = 'Checkout Subscription';
        $this->data->content->code_name = 'Checkout Subscription';
        return \View::make('layouts.shop.checkout-subscription')->with('data', $this->data);
    }


    public function ajaxUpdateProductToCart($productId)
    {

        if (!\Request::has('quantity')) return \App::abort(404, 'no quantity given');
        $this->shopService->addProductToCart($productId, \Request::input('quantity'), true);

        return \Response::json(\Session::get('cart'));

    }

    public function ajaxDeleteProductFromCart($productId)
    {
        $this->shopService->deleteProductFromCart($productId);
        return \Response::json(\Session::get('cart'));
    }

    public function ajaxValidateCoupon()
    {

        //Check if there is a coupon in the post, if not. abort
        if (!\Input::has('coupon')) return \App::abort(404, 'no coupon given');

        if (!$this->shopService->validateCoupon(\Input::get('coupon'))) return \Response::json(\Session::get('cart'), 424);

        //Return a Json of the cart
        return \Response::json(\Session::get('cart'));
    }

}