140 lines
No EOL
3.7 KiB
PHP
Executable file
140 lines
No EOL
3.7 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Product;
|
|
use App\Models\ShoppingInstance;
|
|
use Validator;
|
|
use App\Services\Util;
|
|
use Yard;
|
|
use Input;
|
|
|
|
class CardController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
|
|
|
|
//Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
|
public function addToCardGet($id, $quantity = 1, $product_slug = false)
|
|
{
|
|
$product = Product::find($id);
|
|
if($product){
|
|
$image = "";
|
|
if($product->images->count()){
|
|
$image = $product->images->first()->slug;
|
|
}
|
|
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug, 'weight' => $product->weight]);
|
|
Yard::instance('shopping')->reCalculateShippingPrice();
|
|
|
|
\Session()->flash('show-card-after-add', true);
|
|
}
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
public function addToCardPost($id)
|
|
{
|
|
|
|
$product = Product::find($id);
|
|
|
|
if($product){
|
|
$image = "";
|
|
if($product->images->count()){
|
|
$image = $product->images->first()->slug;
|
|
}
|
|
$quantity = Input::get('quantity') ? Input::get('quantity') : 1;
|
|
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
|
|
Yard::instance('shopping')->reCalculateShippingPrice();
|
|
|
|
\Session()->flash('show-card-after-add', true);
|
|
}
|
|
return back();
|
|
|
|
|
|
}
|
|
|
|
public function showCard(){
|
|
|
|
if(Input::get('selected_country')){
|
|
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
|
|
}else{
|
|
Yard::instance('shopping')->reCalculateShippingPrice();
|
|
}
|
|
$data = [
|
|
'user_shop' => Util::getUserShop(),
|
|
];
|
|
return view('web.templates.card', $data);
|
|
}
|
|
|
|
public function updateCard(){
|
|
|
|
$data = Input::all();
|
|
if(isset($data['quantity'])){
|
|
foreach ($data['quantity'] as $rowId => $qty){
|
|
Yard::instance('shopping')->update($rowId, $qty);
|
|
Yard::instance('shopping')->reCalculateShippingPrice();
|
|
}
|
|
}else{
|
|
$this->deleteCard();
|
|
}
|
|
return back();
|
|
}
|
|
|
|
public function checkoutServer(){
|
|
|
|
|
|
$user_shop = Util::getUserShop();
|
|
|
|
do {
|
|
$identifier = Util::getToken();
|
|
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
|
|
|
ShoppingInstance::create([
|
|
'identifier' => $identifier,
|
|
'user_shop_id' => $user_shop->id,
|
|
'subdomain' => url('/'),
|
|
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
|
|
|
]);
|
|
Yard::instance('shopping')->store($identifier);
|
|
//add to DB
|
|
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
|
if(strpos($path, 'https') === false){
|
|
$path = str_replace('http', 'https', $path);
|
|
}
|
|
return redirect()->secure($path);
|
|
}
|
|
|
|
public function backToShop(){
|
|
$this->deleteCard();
|
|
return redirect(url('/'));
|
|
|
|
}
|
|
public function removeCard($rowId){
|
|
|
|
Yard::instance('shopping')->remove($rowId);
|
|
return back();
|
|
}
|
|
|
|
public function deleteCard(){
|
|
|
|
Yard::instance('shopping')->destroy();
|
|
return back();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |