Warenwirtschaft: AP-09 bis AP-13 (Produktbestand, Set-Produkte, Ausschuss, Konzepte)

- AP-09 Produktbestand inkl. Bewegungshistorie (product_stock_movements, ProductStockService)
- AP-10 Rohstoffbestand-Ansicht je Lager (RawMaterialStockController)
- AP-11 Bestandsschwellen / Out-of-Stock-Handling fuer Produkte und Shop
- AP-12 Ausgang/Ausschuss (stock_disposals, StockDisposalController, InventoryService)
- Set-Produkte (product_set_items) inkl. Aufloesung
- Produktentwicklung & Hinweise-Verwaltung (Notices)
- AP-13 Entwicklungskonzept Shop-Bestandsabzug im Plan dokumentiert
- Feature-Tests fuer neue Module + aktualisierter Entwicklungsplan

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin Adametz 2026-06-03 11:04:22 +00:00
parent 78679e0c55
commit 3ee2d756e9
63 changed files with 5968 additions and 901 deletions

View file

@ -1,54 +1,54 @@
<?php
namespace App\Http\Controllers\User;
use Auth;
use Yard;
use Request;
use App\User;
use Validator;
use App\Services\Shop;
use App\Services\Util;
use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\UserShop;
use App\Services\Payment;
use App\Models\ProductBuy;
use App\Models\UserHistory;
use App\Models\ShoppingUser;
use App\Models\ShoppingOrder;
use App\Services\UserService;
use App\Models\ProductCategory;
use App\Models\Setting;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Http\Controllers\Controller;
use App\Models\UserHistory;
use App\Services\MyLog;
use App\Services\Payment;
use App\Services\Shop;
use App\Services\UserService;
use App\Services\Util;
use App\User;
use Auth;
use Request;
use Validator;
use Yard;
class OrderController extends Controller
{
public function __construct()
{
$this->middleware('active.account');
}
public function delivery($for, $id=null)
public function delivery($for, $id = null)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){
if (strpos($for, 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
if(!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
if (! Shop::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'){
if (Request::get('action') === 'next') {
Yard::instance('shopping')->destroy();
if(strpos(Request::get('switchers-radio-is-for'), 'ot') !== false){
if (strpos(Request::get('switchers-radio-is-for'), 'ot') !== false) {
$delivery_id = $id;
}
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
}
$data = [
@ -58,39 +58,41 @@ class OrderController extends Controller
'for' => $for,
'delivery_id' => $delivery_id,
];
return view('user.order.delivery', $data);
}
public function list($for, $id=null)
public function list($for, $id = null)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){
if (strpos($for, 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
}
if($for === 'ot-customer'){ //noch nicht implementiert
//Liederung an ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
if ($for === 'ot-customer') { // noch nicht implementiert
// Liederung an ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
UserService::initCustomerYard($shopping_user, $for);
}else{
//Lieferung an user oder ot-member (Kunden) rechnung geht an User
//lieferland und rechnungsland prüfen
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
if(!$shipping_country_id){
} else {
// Lieferung an user oder ot-member (Kunden) rechnung geht an User
// lieferland und rechnungsland prüfen
$shipping_country_id = Shop::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]));
}
UserService::initUserYard($user, $shipping_country_id, $for);
}
if($for === 'cr'){
if ($for === 'cr') {
Yard::instance('shopping')->setGlobalTaxRate(0);
Yard::instance('shopping')->setShoppingUser($user, false);
}else{
} else {
Yard::instance('shopping')->setShoppingUser($user, true);
}
$data = [
@ -102,15 +104,17 @@ class OrderController extends Controller
'delivery_id' => $delivery_id,
'comp_products' => $this->getCompProducts($for),
];
return view('user.order.list', $data);
}
public function payment($for, $id=null){
public function payment($for, $id = null)
{
$data = Request::all();
$user = User::find(Auth::user()->id);
$rules = array(
$rules = [
'shipping_salutation' => 'required',
'shipping_firstname' => 'required',
'shipping_lastname' => 'required',
@ -118,25 +122,25 @@ class OrderController extends Controller
'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());
}
//hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
// hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
if(Yard::instance('shopping')->getNumComp() > 0){
if(!isset($data['switchers-comp-product'])){
if (Yard::instance('shopping')->getNumComp() > 0) {
if (! isset($data['switchers-comp-product'])) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle ein Kompensationsprodukt aus'));
}else{
if(!is_array($data['switchers-comp-product'])){
} else {
if (! is_array($data['switchers-comp-product'])) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle ein Kompensationsprodukt aus'));
}else{
if(count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()){
$validator->errors()->add('switchers-comp-product', __('Bitte wähle :count Kompensationsprodukte aus', ['count'=>Yard::instance('shopping')->getNumComp()]));
} else {
if (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle :count Kompensationsprodukte aus', ['count' => Yard::instance('shopping')->getNumComp()]));
}
}
}
@ -144,7 +148,7 @@ class OrderController extends Controller
return back()->withErrors($validator)->withInput(Request::all());
}
}
/*
do {
$identifier = Util::getToken();
@ -173,118 +177,119 @@ class OrderController extends Controller
]);
Yard::instance('shopping')->store($identifier);
*/
//add to DB
//$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier]);
//$path = str_replace('http', 'https', $path);
//return redirect()->secure($path);
// add to DB
// $path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action' => 'user_order_payment', 'status' => 1, 'product_id' => null, 'identifier' => $identifier]);
// $path = str_replace('http', 'https', $path);
// return redirect()->secure($path);
return redirect(route('user_checkout', [$identifier]));
}
private function checkSendYardForPayment($data, $id){
private function checkSendYardForPayment($data, $id)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
if(strpos($data['shipping_is_for'], 'ot') !== false){
if (strpos($data['shipping_is_for'], 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
}
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
if(!$shipping_country_id){
if (! $shipping_country_id) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_found'));
}
//must be the same shipping country
if($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()){
// must be the same shipping country
if ($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_correctly'));
}
if($data['shipping_is_for'] !== 'ot-customer'){
if(Yard::instance('shopping')->shipping_free){
if ($data['shipping_is_for'] !== 'ot-customer') {
if (Yard::instance('shopping')->shipping_free) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_shipping_free'));
}
}
if($data['shipping_is_for'] === 'ot-customer'){
if(!$user->shop){
if ($data['shipping_is_for'] === 'ot-customer') {
if (! $user->shop) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_not_user_shop'));
}
}
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
//for other and has weight - check
if(strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price){
// for other and has weight - check
if (strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0) {
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
}
if($data['shipping_is_for'] == 'me' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
if ($data['shipping_is_for'] == 'me' && Yard::instance('shopping')->weight() > 0) {
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp){
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
if(Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp){
if (Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
abort(403, __('msg.compensation_products_cannot_be_0'));
}
}
}
public function datatable(){
public function datatable()
{
$not_show_pids = ProductBuy::getNotShowProductIDs(Auth::user()->id);
@ -294,7 +299,7 @@ class OrderController extends Controller
break;
case 'mp':
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '2');
break;
break;
case 'cr':
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '6');
break;
@ -302,9 +307,8 @@ class OrderController extends Controller
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '1');
break;
}
foreach($not_show_pids as $not_show_pid){
foreach ($not_show_pids as $not_show_pid) {
$query->where('id', '!=', $not_show_pid);
}
@ -314,7 +318,11 @@ class OrderController extends Controller
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
return '<strong>'.$product->name.'</strong><br><div class="no-line-break input-group-min-w">
if ($product->isOutOfStock()) {
$controls = '<div class="product-stock-hint">'.e($product->outOfStockNotice()).'</div>';
} else {
$controls = '<div class="no-line-break input-group-min-w">
<div class="input-group d-inline-flex w-auto">
<span class="input-group-prepend">
<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>
@ -325,6 +333,9 @@ class OrderController extends Controller
</span>
</div>
</div>';
}
return '<strong>'.$product->name.'</strong><br>'.$controls;
})
/*
->addColumn('add_card', function (Product $product) {
@ -349,32 +360,33 @@ class OrderController extends Controller
</div>';
})*/
->addColumn('category', function (Product $product) {
$ret = "";
foreach($product->categories as $category){
$ret = '';
foreach ($product->categories as $category) {
$ret .= '<span><div style="white-space: nowrap">'.$category->category->name.'</div></span>';
}
return $ret;
})
->addColumn('picture', function (Product $product) {
if(count($product->images)){
if (count($product->images)) {
return '<a href="" class="" 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">
<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">
<div class="text-center"><i class="ion ion-md-eye"></i></div></a>';
}
return "";
return '';
})
->addColumn('price_net', function (Product $product) {
return $product->getFormattedPriceWith(true, false). "";
return $product->getFormattedPriceWith(true, false).'€';
})
->addColumn('price_gross', function (Product $product) {
return $product->getFormattedPriceWith(false, false). "";
return $product->getFormattedPriceWith(false, false).'€';
})
->addColumn('price_vk_gross', function (Product $product) {
return $product->getFormattedPriceWith(false, false). "";
return $product->getFormattedPriceWith(false, false).'€';
})
->addColumn('single_commission', function (Product $product) {
return $product->single_commission ? '<span class="badge badge-warning">Handelspanne: '.$product->getFormattedValueCommission().' %</span>' : '<span class="badge badge-primary">Staffelprovision</span> <button class="btn btn-default btn-xs icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
@ -386,8 +398,8 @@ class OrderController extends Controller
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>';
})
->filterColumn('product', function($query, $keyword) {
if($keyword != ""){
->filterColumn('product', function ($query, $keyword) {
if ($keyword != '') {
$query->where('name', 'LIKE', '%'.$keyword.'%');
}
})
@ -414,32 +426,32 @@ class OrderController extends Controller
, $order);
})*/
->rawColumns(['add_card', 'category', 'product', 'quantity', 'picture', 'action', 'single_commission'])
->make(true);
}
public function performRequest(){
public function performRequest()
{
if(Request::ajax()) {
if (Request::ajax()) {
$data = Request::all();
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot';
$data['comp_products'] = $this->getCompProducts($is_for);
if($data['action'] === 'updateCart' && isset($data['product_id'])){
if($product = Product::find($data['product_id'])){
$image = "";
if($product->images->count()){
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
// get the card item
// Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
//Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax,
//$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), $product->getTaxWith(Yard::instance('shopping')->getUserCountry()), //$product->tax, true?
// $product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), $product->getTaxWith(Yard::instance('shopping')->getUserCountry()), //$product->tax, true?
[
'image' => $image,
'slug' => $product->slug,
@ -450,140 +462,144 @@ class OrderController extends Controller
'partner_commission' => $product->partner_commission,
]);
if(Yard::instance('shopping')->getUserTaxFree()){
//Yard::setTax($cartItem->rowId, 0);
Yard::instance('shopping')->setGlobalTaxRate(0);
}else{
//Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if (Yard::instance('shopping')->getUserTaxFree()) {
// Yard::setTax($cartItem->rowId, 0);
Yard::instance('shopping')->setGlobalTaxRate(0);
} else {
// Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if(isset($data['qty']) && $data['qty'] > 0){
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
} else {
// if 0 get the item by qty:1 and remove it
Yard::instance('shopping')->remove($cartItem->rowId);
}
//
Yard::instance('shopping')->reCalculate();
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
}
if($data['action'] === 'reCalculateCart') {
//set use_payment_credit
$data['reduce_payment_credit'] = $data['reduce_payment_credit'] == 'true' ? true: false;
if ($data['action'] === 'reCalculateCart') {
// set use_payment_credit
$data['reduce_payment_credit'] = $data['reduce_payment_credit'] == 'true' ? true : false;
Yard::instance('shopping')->setReducePaymentCredit($data['reduce_payment_credit']);
Yard::instance('shopping')->reCalculate();
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
if($data['action'] === 'clearCart') {
if ($data['action'] === 'clearCart') {
Yard::instance('shopping')->destroy();
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html_card'=>'', 'html_comp'=>'']);
return response()->json(['response' => true, 'data' => Yard::instance('shopping')->count(), 'html_card' => '', 'html_comp' => '']);
}
if($data['action'] === 'updateShippingCountry') {
if(isset($data['shipping_country_id'])){
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for); //$is_for == 'ot' or 'me'
if ($data['action'] === 'updateShippingCountry') {
if (isset($data['shipping_country_id'])) {
if ($shipping_country = ShippingCountry::find($data['shipping_country_id'])) {
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for); // $is_for == 'ot' or 'me'
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
}
}
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
if($data['action'] === 'updateCompProduct'){
if ($data['action'] === 'updateCompProduct') {
// $data['comp_product_id']
// $data['comp_num']
//count_comp_products
$this->updateCompProduct($data);
Yard::instance('shopping')->reCalculateShippingPrice();
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
// count_comp_products
$this->updateCompProduct($data);
Yard::instance('shopping')->reCalculateShippingPrice();
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
return response()->json(['response' => false, 'data'=>$data]);
}
return response()->json(['response' => false, 'data' => $data]);
}
}
private function checkCompProduct($count_comp_products){
private function checkCompProduct($count_comp_products)
{
foreach (Yard::instance('shopping')->content() as $row) {
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp > $count_comp_products) {
// wenn gleich löschen, da neue Versandkosten
if ($row->options->comp > $count_comp_products) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
private function updateCompProduct($data){
//clear old
foreach (Yard::instance('shopping')->content() as $row) {
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
private function updateCompProduct($data)
{
// clear old
foreach (Yard::instance('shopping')->content() as $row) {
// wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
// wenn gleich löschen, da neue Versandkosten
if ($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
}
if(isset($data['comp_product_id'])) {
if (isset($data['comp_product_id'])) {
if ($product = Product::find($data['comp_product_id'])) {
$image = "";
$image = '';
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, 0,
[
'image' => $image,
'slug' => $product->slug,
'weight' => 0,
'single_commission' => 0,
'amount_commission' => 0,
'value_commission' => 0,
'partner_commission' => 0,
'comp' => $data['comp_num'],
'product_id' => $product->id
]);
[
'image' => $image,
'slug' => $product->slug,
'weight' => 0,
'single_commission' => 0,
'amount_commission' => 0,
'value_commission' => 0,
'partner_commission' => 0,
'comp' => $data['comp_num'],
'product_id' => $product->id,
]);
Yard::setTax($cartItem->rowId, 0);
}
}
}
private function getCompProducts($for) {
if($for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')) {
private function getCompProducts($for)
{
if ($for === 'me' && Setting::getContentBySlug('order_partner_is_comp_me')) {
return Product::whereActive(true)
->where(function($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"2\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
->where(function ($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"2\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
}
if($for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')) {
if ($for === 'ot' && Setting::getContentBySlug('order_partner_is_comp_ot')) {
return Product::whereActive(true)
->where(function($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"1\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
->where(function ($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"1\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
}
return null;
}
}
}