Berater Bestellungen
This commit is contained in:
parent
a5db985ae8
commit
bde1095014
26 changed files with 1524 additions and 577 deletions
|
|
@ -79,39 +79,66 @@ class CustomerController extends Controller
|
|||
abort(404);
|
||||
}
|
||||
}
|
||||
if(old('email') || old('billing_email')){
|
||||
$step = 1;
|
||||
$shopping_user->same_as_billing = true;
|
||||
|
||||
$billing_email = null;
|
||||
if(!session('errors')){
|
||||
if(old('email') || old('billing_email')){
|
||||
$step = 1;
|
||||
$shopping_user->same_as_billing = true;
|
||||
$billing_email = old('email');
|
||||
}
|
||||
if(old('switcher-without-email') === 'true'){
|
||||
$step = 1;
|
||||
$shopping_user->same_as_billing = true;
|
||||
$billing_email = time()."@faker-mivita.care";
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => $step === 0 ? 'customer' : 'customer-add',
|
||||
'step' => $step,
|
||||
'billing_email' => old('email'),
|
||||
'billing_email' => $billing_email,
|
||||
|
||||
];
|
||||
return view('user.customer.add', $data);
|
||||
}
|
||||
|
||||
private function checkShoppingUsersEmail($data){
|
||||
$rules = array(
|
||||
'email' => 'required|string|email|max:255|unique:shopping_users,billing_email',
|
||||
);
|
||||
$messages = [
|
||||
'unique' => __('validation.custom.unique_email_client'),
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules, $messages);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
$rules = array(
|
||||
'email' => 'required|string|email|max:255|unique:users,email',
|
||||
);
|
||||
$messages = [
|
||||
'unique' => __('validation.custom.unique_email_member'),
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules, $messages);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
return back()->withInput(Request::all());
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
if($id === 'new' && $data['action'] === 'add_customer_step_email'){
|
||||
$rules = array(
|
||||
'email' => 'required|string|email|max:255|unique:shopping_users,billing_email',
|
||||
);
|
||||
$messages = [
|
||||
'unique' => __('validation.custom.unique_email_client'),
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules, $messages);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
//okay, go to step 1
|
||||
if($id === 'new' && $data['action'] === 'add_customer_with_email'){
|
||||
return $this->checkShoppingUsersEmail($data);
|
||||
}
|
||||
if($id === 'new' && $data['action'] === 'add_customer_without_email'){
|
||||
return back()->withInput(Request::all());
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'shopping-user-store-new' || $data['action']==='shopping-user-store'){
|
||||
|
|
@ -159,6 +186,7 @@ class CustomerController extends Controller
|
|||
CustomerPriority::checkChangeOne($shopping_user, $data, true);
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
|
||||
}
|
||||
|
||||
if($id === 'new' && $data['action'] === 'shopping-user-store-new') {
|
||||
|
|
@ -169,6 +197,10 @@ class CustomerController extends Controller
|
|||
}
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
|
||||
if($shopping_user->is_like){
|
||||
\Session()->flash('custom-error', __('validation.custom.match_found'));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('user_customer_detail', [$shopping_user->id]));
|
||||
}
|
||||
|
|
@ -209,7 +241,7 @@ class CustomerController extends Controller
|
|||
return get_active_badge($ShoppingUser->subscribed);
|
||||
})
|
||||
->addColumn('status', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->is_like ? '<span class="badge badge-pill badge-warning"><i class="fa fa-clock"></i> in Prüfung</span> ' : '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> aktiv</span>';
|
||||
return $ShoppingUser->is_like ? '<span class="badge badge-pill badge-warning"><i class="fa fa-clock"></i> in Prüfung</span> ' : '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> zugewiesen</span>';
|
||||
})
|
||||
->addColumn('extras', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->wp_order_number.($ShoppingUser->mode==='dev' ? ' <span class="badge badge-warning">dev</span>' : '');
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@
|
|||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\Payment;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
|
||||
class OrderController extends Controller
|
||||
|
|
@ -17,10 +19,9 @@ class OrderController extends Controller
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.shop');
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
|
|
@ -47,22 +48,23 @@ class OrderController extends Controller
|
|||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
|
||||
/*if (Request::isMethod('post')) {
|
||||
$data = Request::all();
|
||||
if($data['switchers-radio-is-for'] === 'is-for-member'){
|
||||
return redirect(route('user_order_my_list', ['me']));
|
||||
}
|
||||
if($data['switchers-radio-is-for'] === 'is-for-customer'){
|
||||
//check ist customer
|
||||
return redirect(route('user_order_my_list', ['ot', $id]));
|
||||
}
|
||||
}*/
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
if($for === 'ot'){
|
||||
$shopping_user = $this->checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
if(!$this->checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
|
||||
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
}
|
||||
|
||||
if(Request::get('action') === 'next'){
|
||||
Yard::instance('shopping')->destroy();
|
||||
if(Request::get('switchers-radio-is-for') === 'ot'){
|
||||
$delivery_id = $id;
|
||||
}
|
||||
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
@ -78,19 +80,26 @@ class OrderController extends Controller
|
|||
public function list($for, $id=null)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
|
||||
if($for === 'ot'){
|
||||
$shopping_user = $this->checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
}
|
||||
//$data = Request::all();
|
||||
//dd(session('switchers-radio-is-for'));
|
||||
//$shopping_user = new ShoppingUser();
|
||||
//$shopping_user->id = "new";
|
||||
//$shopping_user->same_as_billing = true;
|
||||
$shipping_country_id = $this->checkShoppingCountry($for, $id);
|
||||
if(!$shipping_country_id){
|
||||
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
|
||||
$comp_products = null;
|
||||
if($for === 'me'){
|
||||
$comp_products = Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
|
||||
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'user' => $user,
|
||||
|
|
@ -98,11 +107,129 @@ class OrderController extends Controller
|
|||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'delivery_id' => $delivery_id,
|
||||
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
return view('user.order.list', $data);
|
||||
}
|
||||
|
||||
public function payment($for, $id=null){
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
$user = User::find(Auth::user()->id);
|
||||
$rules = array(
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_state' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($for === 'me'){
|
||||
if(Request::get('switchers-comp-product')) {
|
||||
$product = Product::find(Request::get('switchers-comp-product'));
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, ['image' => '', 'slug' => $product->slug, 'weight' => 0]);
|
||||
}
|
||||
|
||||
}
|
||||
// Yard::instance('shopping')->destroy();
|
||||
|
||||
return back()->withInput(Request::all());
|
||||
|
||||
if($for === 'ot' && $id){
|
||||
dd($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Yard::instance('shopping')->destroy();
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
$showAboOptions = false;
|
||||
if(Request::get('abo_options')){
|
||||
$showAboOptions = true;
|
||||
$user->abo_options = true;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
if($product && $product->active && $product->show_at == 3){
|
||||
//set membership product
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
|
||||
//set onboarding products
|
||||
if(Request::get('products_on_board')){
|
||||
foreach (Request::get('products_on_board') as $product_on_board_id){
|
||||
$product_on_board = Product::find($product_on_board_id);
|
||||
$image = "";
|
||||
if($product_on_board->images->count()){
|
||||
$image = $product_on_board->images->first()->slug;
|
||||
}
|
||||
Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, $product_on_board->price, ['image' => $image, 'slug' => $product_on_board->slug, 'weight' => $product_on_board->weight]);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 4, //Berater Wizard
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'wizard_payment', 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
|
||||
}
|
||||
|
||||
\Session()->flash('alert-error', "Fehler beim Produkt");
|
||||
return back();
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($for, $id=null){
|
||||
$country_id = null;
|
||||
if($for === 'me'){
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if($user->same_as_billing){
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
}
|
||||
if($for === 'ot' && $id){
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->same_as_billing){
|
||||
$country_id = $shopping_user->billing_country_id;
|
||||
}else{
|
||||
$country_id = $shopping_user->shipping_country_id;
|
||||
}
|
||||
}
|
||||
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkShoppingUser($id, $user){
|
||||
if($id === null){
|
||||
abort(403, 'Error: Keine User ID');
|
||||
|
|
@ -129,27 +256,22 @@ class OrderController extends Controller
|
|||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('add_card', function (Product $product) {
|
||||
return '<a href="#" class="btn btn-sm btn-md-extra btn-secondary">
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith().'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</a>';
|
||||
|
||||
/*'<a href="javascript:void(0)" class="btn btn-secondary btn-sm my-1 mx-2">
|
||||
<i class="ion ion-md-add"></i> <i class="ion ion-md-basket"></i>
|
||||
</a><br>
|
||||
<a href="javascript:void(0)" class="btn btn-outline-secondary btn-sm my-1 mx-2">
|
||||
<i class="ion ion-md-remove"></i> <i class="ion ion-md-basket"></i>
|
||||
</a>'*/;
|
||||
</button>';
|
||||
})
|
||||
->addColumn('quantity', function (Product $product) {
|
||||
//return '<input type="text" class="form-control text-center" value="0" style="width: 4em">';
|
||||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<div class="no-line-break input-group-min-w">
|
||||
<div class="input-group d-inline-flex w-auto">
|
||||
<span class="input-group-prepend">
|
||||
<button class="btn btn-secondary icon-btn md-btn-extra" type="button">-</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control text-center input-extra" value="0">
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
|
||||
<span class="input-group-append">
|
||||
<button class="btn btn-secondary icon-btn md-btn-extra" type="button">+</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
|
@ -161,22 +283,27 @@ class OrderController extends Controller
|
|||
}
|
||||
return "";
|
||||
})
|
||||
->addColumn('price', function (Product $product) {
|
||||
return $product->getFormattedPriceWith();
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(true, true). " €";
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, true). " €";
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, false). " €";
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price', 'price $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price_vk_gross $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
->rawColumns(['add_card', 'quantity', 'picture', 'action'])
|
||||
|
|
@ -184,4 +311,82 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
|
||||
public function performRequest(){
|
||||
|
||||
if(Request::ajax()) {
|
||||
$data = Request::all();
|
||||
if($data['action'] === 'updateCart' && isset($data['product_id'])){
|
||||
if($product = Product::find($data['product_id'])){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
//get the card item
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(false, true), ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
Yard::setTax($cartItem->rowId, $product->tax);
|
||||
|
||||
if(isset($data['qty']) && $data['qty'] > 0){
|
||||
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
|
||||
}else{
|
||||
//if 0 get the item by qty:1 and remove it
|
||||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
}
|
||||
$this->updateCompProduct($data);
|
||||
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html'=>'']);
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'updateShippingCountry') {
|
||||
if(isset($data['shipping_country_id'])){
|
||||
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot';
|
||||
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$this->updateCompProduct($data);
|
||||
}
|
||||
}
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
|
||||
}
|
||||
if($data['action'] === 'updateCompProduct'){
|
||||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
|
||||
}
|
||||
return response()->json(['response' => false, 'data'=>$data]);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateCompProduct($data){
|
||||
//clear old
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
if($row->options->comp) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
}
|
||||
if(isset($data['comp_product_id'])) {
|
||||
if ($product = Product::find($data['comp_product_id'])) {
|
||||
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, ['image' => $image, 'slug' => $product->slug, 'weight' => 0, 'points' => 0, 'comp' => $product->id]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -295,7 +295,7 @@ class Product extends Model
|
|||
$price = $this->attributes['price'];
|
||||
$price = $net ? $this->calcPriceNet($price) : $price;
|
||||
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
|
||||
return $price;
|
||||
return round($price, 2);
|
||||
}
|
||||
/*out*/
|
||||
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ namespace App\Services;
|
|||
|
||||
|
||||
use App\Models\ShoppingUser;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
|
||||
class Shop
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use \Gloudemans\Shoppingcart\Cart;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
|
|
@ -12,8 +14,11 @@ use Illuminate\Support\Collection;
|
|||
class Yard extends Cart
|
||||
{
|
||||
private $shipping_price = 0;
|
||||
private $shipping_price_net = 0;
|
||||
private $shipping_tax_rate = 0;
|
||||
private $shipping_tax = 0;
|
||||
private $shipping_country_id = 0; //default de
|
||||
private $shipping_is_for;
|
||||
private $ysession;
|
||||
private $yinstance;
|
||||
|
||||
|
|
@ -33,16 +38,22 @@ class Yard extends Cart
|
|||
$this->shipping_country_id = $this->getShippingExtra('shipping_country_id');
|
||||
}
|
||||
|
||||
if($this->getShippingExtra('shipping_is_for')){
|
||||
$this->shipping_is_for = $this->getShippingExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
||||
if($this->shipping_country_id == 0){
|
||||
if(gettype($this->shipping_country_id) !== 'object' && $this->shipping_country_id == 0){
|
||||
$shippingCountry = ShippingCountry::first();
|
||||
if($shippingCountry){
|
||||
$this->shipping_country_id = $shippingCountry->id;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->shipping_price == 0){
|
||||
self::instance('shopping')->setShippingCountryWithPrice($this->shipping_country_id);
|
||||
self::instance('shopping')->setShippingCountryWithPrice($this->shipping_country_id, $this->shipping_is_for);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,10 +113,14 @@ class Yard extends Cart
|
|||
$this->calculateShippingPrice();
|
||||
}
|
||||
|
||||
public function setShippingCountryWithPrice($shipping_country_id)
|
||||
public function setShippingCountryWithPrice($shipping_country_id, $shipping_is_for = 'ot')
|
||||
{
|
||||
$this->shipping_country_id = $shipping_country_id;
|
||||
$this->putShippingExtra('shipping_country_id', $shipping_country_id);
|
||||
|
||||
$this->shipping_is_for = $shipping_is_for;
|
||||
$this->putShippingExtra('shipping_is_for', $shipping_is_for);
|
||||
|
||||
$this->calculateShippingPrice();
|
||||
|
||||
}
|
||||
|
|
@ -113,11 +128,15 @@ class Yard extends Cart
|
|||
private function calculateShippingPrice(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if(!$shippingCountry){
|
||||
return;
|
||||
}
|
||||
$shipping = $shippingCountry->shipping;
|
||||
|
||||
if($this->weight() == 0){
|
||||
$shipping_price = $shipping->shipping_prices->first();
|
||||
$shipping_price->price = 0;
|
||||
$shipping_price->price_comp = 0;
|
||||
}else{
|
||||
//first by price
|
||||
$shipping_price = $this->shippingPriceByTotal($shipping->shipping_prices, $this->total(2, '.', ''));
|
||||
|
|
@ -131,10 +150,20 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
if($shipping_price){
|
||||
$this->shipping_price = $shipping_price->price;
|
||||
$this->shipping_tax = $shipping_price->tax_rate;
|
||||
$price = $shipping_price->price;
|
||||
if($this->shipping_is_for === 'me'){
|
||||
$price = $shipping_price->price_comp;
|
||||
|
||||
}
|
||||
$this->shipping_price = $price;
|
||||
$this->shipping_tax_rate = $shipping_price->tax_rate;
|
||||
$this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2);
|
||||
$this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2);
|
||||
|
||||
$this->putShippingExtra('shipping_price', $this->shipping_price);
|
||||
$this->putShippingExtra('shipping_tax_rate', $this->shipping_tax_rate);
|
||||
$this->putShippingExtra('shipping_tax', $this->shipping_tax);
|
||||
$this->putShippingExtra('shipping_price_net', $this->shipping_price_net);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -169,31 +198,36 @@ class Yard extends Cart
|
|||
{
|
||||
return $this->numberFormat($this->shipping_price, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
public function shippingNet($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
return $this->numberFormat($this->shipping_price_net, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
//
|
||||
private function shippingTax($decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
$shippingTax = $this->shipping_price / (100 + $this->shipping_tax) * $this->shipping_tax;
|
||||
return $this->numberFormat($shippingTax, $decimals, $decimalPoint, $thousandSeperator);
|
||||
private function shippingTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
return $this->numberFormat($this->shipping_tax, $decimals, $decimalPoint, $thousandSeperator);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function subShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
$subShipping = $this->shipping_price - $this->shippingTax($decimals, $decimalPoint, $thousandSeperator);
|
||||
/* private function subShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
$subShipping = $this->shipping_price_net
|
||||
return $this->numberFormat($subShipping, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
//netto
|
||||
public function subtotalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$subtotal = $this->subtotal(2, '.', '') + $this->subShipping(2, '.', '');
|
||||
$subtotal = (float) $this->shipping_price_net + $this->subtotal(2, '.', '');
|
||||
return $this->numberFormat($subtotal, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$totalTax = $this->tax(2, '.', '');
|
||||
$shippingTax = $this->shippingTax(2, '.', '');
|
||||
return $this->numberFormat(($totalTax+$shippingTax), $decimals, $decimalPoint, $thousandSeperator);
|
||||
$total = $this->totalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
return $this->numberFormat(($total - $totalTax), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -220,6 +254,27 @@ class Yard extends Cart
|
|||
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function points()
|
||||
{
|
||||
$content = $this->getContent();
|
||||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
return $total + ($cartItem->options->points ? ($cartItem->options->points * $cartItem->qty) : 0);
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function compCount()
|
||||
{
|
||||
$content = $this->getContent();
|
||||
|
||||
$count = parent::count();
|
||||
$comp_count = $content->reduce(function ($comp_count, CartItem $cartItem) {
|
||||
return $cartItem->options->comp ? $comp_count + 1 : $comp_count;
|
||||
}, 0);
|
||||
return $count-$comp_count;
|
||||
}
|
||||
/**
|
||||
* Get the total price of the items in the cart.
|
||||
*
|
||||
|
|
@ -271,13 +326,48 @@ class Yard extends Cart
|
|||
$content = $this->getContent();
|
||||
|
||||
$subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) {
|
||||
$priceTax = $cartItem->price / (100 + $cartItem->taxRate) * $cartItem->taxRate;
|
||||
return $subTotal + ($cartItem->qty * ($cartItem->price - $priceTax));
|
||||
$price_net = $cartItem->price / ((100 + $cartItem->taxRate) / 100);
|
||||
return $subTotal + ($cartItem->qty * $price_net);
|
||||
}, 0);
|
||||
|
||||
return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function getCartItemByProduct($product_id, $set_price='with'){
|
||||
if($product = Product::find($product_id)) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$price = $product->price;
|
||||
if($set_price === 'with'){
|
||||
$price = $product->getPriceWith(false, true);
|
||||
}
|
||||
$cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
$content = $this->getContent();
|
||||
|
||||
if ($content->has($cartItem->rowId)){
|
||||
return $content->get($cartItem->rowId);
|
||||
}
|
||||
return $cartItem;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getCartItem($id, $name = null, $qty = null, $price = null, array $options = []){
|
||||
if ($id instanceof Buyable) {
|
||||
$cartItem = CartItem::fromBuyable($id, $qty ?: []);
|
||||
} elseif (is_array($id)) {
|
||||
$cartItem = CartItem::fromArray($id);
|
||||
} else {
|
||||
$cartItem = CartItem::fromAttributes($id, $name, $price, $options);
|
||||
}
|
||||
return $cartItem;
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
$this->ysession->remove($this->yinstance);
|
||||
|
|
@ -285,6 +375,17 @@ class Yard extends Cart
|
|||
|
||||
}
|
||||
|
||||
public function rowPriceNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
return $this->numberFormat($price, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
public function rowSubtotalNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
return $this->numberFormat(($price * $row->qty), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the Formated number
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ if (! function_exists('get_file_last_time')) {
|
|||
if (file_exists($value)) {
|
||||
return filemtime($value);
|
||||
}
|
||||
return date("Ymd-i", time());
|
||||
return date("Ymd-is", time());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue