diff --git a/.env b/.env index a3b101a..271cfa2 100644 --- a/.env +++ b/.env @@ -5,10 +5,10 @@ APP_DEBUG=true APP_URL=https://partner.gruene-seele.test APP_DOMAIN=partner.gruene-seele.test -APP_CHECKOUT_MAIL=kevin.adametz@me.com -APP_CHECKOUT_TEST_MAIL=kevin.adametz@me.com -APP_INFO_MAIL=kevin.adametz@me.com -APP_INFO_TEST_MAIL=kevin.adametz@me.com +APP_CHECKOUT_MAIL=register@adametz.media +APP_CHECKOUT_TEST_MAIL=register@adametz.media +APP_INFO_MAIL=register@adametz.media +APP_INFO_TEST_MAIL=register@adametz.media APP_MAIN_TAX = 1.19 APP_MAIN_TAX_RATE = 19 diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index b202a5b..6495ec6 100755 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -34,10 +34,10 @@ class SettingController extends Controller { $data = Request::all(); - if(isset($data['action'])){ if(isset($data['settings'])){ foreach ($data['settings'] as $key=>$value){ + $value['val'] = isset($value['val']) ? $value['val'] : false; Setting::setContentBySlug($key, $value['val'], $value['type']); } } diff --git a/app/Http/Controllers/User/CheckoutController.php b/app/Http/Controllers/User/CheckoutController.php index 7f3f72c..1422fff 100755 --- a/app/Http/Controllers/User/CheckoutController.php +++ b/app/Http/Controllers/User/CheckoutController.php @@ -479,6 +479,7 @@ class CheckoutController extends Controller ]; $shopping_order_item = ShoppingOrderItem::create($data); } + } return $shopping_order; } diff --git a/app/Http/Controllers/User/OrderController.php b/app/Http/Controllers/User/OrderController.php index a3d7bd5..216ebe9 100755 --- a/app/Http/Controllers/User/OrderController.php +++ b/app/Http/Controllers/User/OrderController.php @@ -18,7 +18,7 @@ use App\Models\ProductCategory; use App\Models\ShippingCountry; use App\Models\ShoppingInstance; use App\Http\Controllers\Controller; - +use App\Models\ProductBuy; class OrderController extends Controller { @@ -153,7 +153,6 @@ class OrderController extends Controller Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for); Yard::instance('shopping')->setShoppingUser($user, true); - $data = [ 'shopping_user' => $shopping_user, 'user' => $user, @@ -161,7 +160,7 @@ class OrderController extends Controller 'isView' => 'customer', 'for' => $for, 'delivery_id' => $delivery_id, - //'comp_products' => $this->getCompProducts($for), + 'comp_products' => $this->getCompProducts($for), ]; return view('user.order.list', $data); } @@ -184,7 +183,7 @@ class OrderController extends Controller return back()->withErrors($validator)->withInput(Request::all()); } - /* if(Yard::instance('shopping')->getNumComp() > 0){ + 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{ @@ -200,7 +199,7 @@ class OrderController extends Controller return back()->withErrors($validator)->withInput(Request::all()); } } - */ + /*do { $identifier = Util::getToken(); } while( ShoppingInstance::where('identifier', $identifier)->count() );*/ @@ -280,6 +279,7 @@ class OrderController extends Controller public function datatable(){ $show_at = 1; + $not_show_pids = ProductBuy::getNotShowProductIDs(Auth::user()->id); if(Request::get('shipping_is_for') === 'me'){ $query = Product::with('categories')->select('products.*')->where('active', true)->where(function ($q) { $q->where('show_at', '=', 1) @@ -294,6 +294,12 @@ class OrderController extends Controller ->orWhere('show_at', '=', 1); }); } + + foreach($not_show_pids as $not_show_pid){ + $query->where('id', '!=', $not_show_pid); + } + + //Kunden und Vertriebspartner //->orWhere('show_at', '=', 2); // Nur Vertriebspartner //->orderBy('pos', 'DESC') @@ -418,7 +424,7 @@ class OrderController extends Controller $data = Request::all(); $is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot'; - // $data['comp_products'] = $this->getCompProducts($is_for); + $data['comp_products'] = $this->getCompProducts($is_for); if($data['action'] === 'updateCart' && isset($data['product_id'])){ if($product = Product::find($data['product_id'])){ @@ -448,9 +454,12 @@ class OrderController extends Controller } // 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(); - return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>'']); + + return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]); } } if($data['action'] === 'clearCart') { @@ -462,18 +471,30 @@ class OrderController extends Controller if(isset($data['shipping_country_id'])){ if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){ Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for); - //$this->checkCompProduct(Yard::instance('shopping')->getNumComp()); + $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 = 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'){ + // $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(); + + return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]); + + } 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) { @@ -486,8 +507,10 @@ class OrderController extends Controller 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); + Yard::instance('shopping')->remove($row->rowId); + } } @@ -497,13 +520,33 @@ class OrderController extends Controller 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' => $data['comp_num'], 'product_id' => $product->id]); + $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 + ]); Yard::setTax($cartItem->rowId, 0); } } } - */ + private function getCompProducts($for){ + + if($for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){ + return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get(); + } + if($for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){ + return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get(); + } + return null; + } + + } \ No newline at end of file diff --git a/app/Models/Product.php b/app/Models/Product.php index 40b28c9..01fb1f0 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -141,7 +141,10 @@ class Product extends Model 'wp_number' => 'int', 'single_commission' => 'bool', 'amount_commission' => 'bool', - 'active' => 'bool' + 'active' => 'bool', + 'shipping_addon' => 'bool', + 'max_buy' => 'bool', + 'max_buy_num' => 'int' ]; use Sluggable; @@ -178,7 +181,10 @@ class Product extends Model 'partner_commission', 'identifier', 'action', - 'upgrade_to_id' + 'upgrade_to_id', + 'shipping_addon', + 'max_buy', + 'max_buy_num' ]; public $identifiers_types = [ @@ -249,6 +255,10 @@ class Product extends Model return $this->hasMany(CountryPrice::class, 'product_id'); } + public function product_buys() + { + return $this->hasMany(ProductBuy::class, 'product_id'); + } public function p_ingredients() { diff --git a/app/Models/ProductBuy.php b/app/Models/ProductBuy.php new file mode 100644 index 0000000..9cc3a50 --- /dev/null +++ b/app/Models/ProductBuy.php @@ -0,0 +1,72 @@ + 'int', + 'product_id' => 'int', + 'num' => 'int' + ]; + + protected $fillable = [ + 'auth_user_id', + 'product_id', + 'num' + ]; + + public function product() + { + return $this->belongsTo(Product::class); + } + + public function user() + { + return $this->belongsTo('App\User','auth_user_id'); + } + + public function auth_user() + { + return $this->belongsTo('App\User','auth_user_id'); + } + + public static function getNotShowProductIDs($user_id){ + $ret = []; + $ProductBuys = ProductBuy::where('auth_user_id', $user_id)->get(); + if($ProductBuys){ + foreach($ProductBuys as $ProductBuy){ + if($ProductBuy->product){ + if($ProductBuy->product->max_buy && $ProductBuy->num >= $ProductBuy->product->max_buy_num){ + $ret[] = $ProductBuy->product->id; + } + } + } + } + return $ret; + } + +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 6a14963..b7daf73 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -77,6 +77,10 @@ class Setting extends Model 'object' => 'Object', 'full_text' => 'Full Text', 'text' => 'Text', + 'int' => 'Zahl', + 'bool' => 'Bool', + + ]; public function sluggable() @@ -103,6 +107,9 @@ class Setting extends Model case 'int': return $content->int; break; + case 'bool': + return $content->int === 1 ? true : false; + break; } } return false; @@ -120,17 +127,20 @@ class Setting extends Model $content->type = $type; switch ($content->type){ case 'object': - $content->object = $value; + $content->object = $value ? $value : null;; break; case 'full_text': - $content->full_text = $value; + $content->full_text = $value ? $value : null;; break; case 'text': - $content->text = $value; + $content->text = $value ? $value : null;; break; case 'int': $content->int = (int) $value; break; + case 'bool': + $content->int = $value ? 1 : 0; + break; } $content->save(); diff --git a/app/Repositories/ProductRepository.php b/app/Repositories/ProductRepository.php index adc9efb..d08de76 100644 --- a/app/Repositories/ProductRepository.php +++ b/app/Repositories/ProductRepository.php @@ -29,6 +29,9 @@ class ProductRepository extends BaseRepository { $data['active'] = isset($data['active']) ? 1 : 0; $data['single_commission'] = isset($data['single_commission']) ? 1 : 0; $data['amount_commission'] = isset($data['amount_commission']) ? 1 : 0; + $data['shipping_addon'] = isset($data['shipping_addon']) ? 1 : 0; + $data['max_buy'] = isset($data['max_buy']) ? 1 : 0; + if($data['id'] === "new"){ $this->model = Product::create($data); diff --git a/app/Services/Payment.php b/app/Services/Payment.php index 9b78988..1a240e7 100644 --- a/app/Services/Payment.php +++ b/app/Services/Payment.php @@ -2,13 +2,15 @@ namespace App\Services; -use App\Mail\MailCheckout; +use App\User; +use App\Models\Product; use App\Models\Setting; +use App\Mail\MailCheckout; +use App\Models\ProductBuy; use App\Models\ShoppingOrder; +use App\Models\UserPayCredit; use App\Models\ShoppingPayment; use App\Models\UserCreditMargin; -use App\Models\UserPayCredit; -use App\User; use Illuminate\Support\Facades\Mail; class Payment @@ -117,6 +119,23 @@ class Payment ]); } + public static function addProductBuy(User $user, Product $product){ + + if($product->max_buy && $product->max_buy_num > 0){ + $ProductBuy = ProductBuy::where('auth_user_id', $user->id)->where('product_id', $product->id)->first(); + if(!$ProductBuy){ + ProductBuy::create([ + 'auth_user_id' => $user->id, + 'product_id' => $product->id, + 'num' => 1, + ]); + }else{ + $ProductBuy->num = $ProductBuy->num+1; + $ProductBuy->save(); + } + } + } + public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){ $send_link = false; @@ -129,8 +148,14 @@ class Payment if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){ foreach($shopping_order->shopping_order_items as $shopping_order_item){ if($shopping_order_item->product){ + //add product when buy + $user = User::findOrFail($shopping_order->auth_user_id); + + if($shopping_order_item->product->max_buy && $shopping_order_item->product->max_buy_num > 0){ + self::addProductBuy($user, $shopping_order_item->product); + } + //product action if($shopping_order_item->product->action){ - $user = User::findOrFail($shopping_order->auth_user_id); $user->save(); $send_link = true; //new date diff --git a/app/Services/Yard.php b/app/Services/Yard.php index f166295..4d12e56 100644 --- a/app/Services/Yard.php +++ b/app/Services/Yard.php @@ -22,7 +22,7 @@ class Yard extends Cart private $shipping_tax = 0; private $shipping_country_id = 0; //default de private $shipping_is_for; - //private $num_comp; + private $num_comp; private $ysession; private $yinstance; private $shopping_data = []; @@ -87,9 +87,9 @@ class Yard extends Cart $this->global_tax_rate = config('cart.tax'); } - /*if($this->getYardExtra('num_comp')){ + if($this->getYardExtra('num_comp')){ $this->num_comp = $this->getYardExtra('num_comp'); - }*/ + } parent::__construct($session, $events); @@ -164,7 +164,10 @@ class Yard extends Cart return $this->ysession->get($this->yinstance); } - + public function reCalculateShippingPrice(){ + $this->calculateShippingPrice(); + } + public function reCalculate(){ $this->calculateShippingPrice(); } @@ -328,18 +331,23 @@ class Yard extends Cart } if($shipping_price){ $price = $shipping_price->price; - /*$this->num_comp = 0; - if($this->shipping_is_for === 'me'){ + $this->num_comp = 0; + + if($this->shipping_is_for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){ $price = $shipping_price->price_comp; $this->num_comp = $shipping_price->num_comp; + } + if($this->shipping_is_for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){ + $price = $shipping_price->price_comp; + $this->num_comp = $shipping_price->num_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->putYardExtra('num_comp', $this->num_comp); + $this->putYardExtra('num_comp', $this->num_comp); $this->putYardExtra('shipping_price', $this->shipping_price); $this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate); $this->putYardExtra('shipping_tax', $this->shipping_tax); @@ -627,7 +635,7 @@ class Yard extends Cart } public function getNumComp(){ - return 0; //$this->num_comp; + return $this->num_comp; } public function getCompProductBy($comp, $product_id=false){ diff --git a/database/migrations/2018_10_21_164001_create_products_table.php b/database/migrations/2018_10_21_164001_create_products_table.php index 2b193bd..a4f201d 100644 --- a/database/migrations/2018_10_21_164001_create_products_table.php +++ b/database/migrations/2018_10_21_164001_create_products_table.php @@ -69,6 +69,11 @@ class CreateProductsTable extends Migration $table->string('identifier', 20)->nullable(); + $table->boolean('shipping_addon')->default(false); + $table->boolean('max_buy')->default(false); + $table->tinyInteger('max_buy_num')->unsigned()->nullable()->default(0); + + $table->string('action')->nullable(); //is an upgrade product, set this product id by payments API paid diff --git a/database/migrations/2021_06_15_112357_create_product_buys_table.php b/database/migrations/2021_06_15_112357_create_product_buys_table.php new file mode 100644 index 0000000..697eae2 --- /dev/null +++ b/database/migrations/2021_06_15_112357_create_product_buys_table.php @@ -0,0 +1,43 @@ +id(); + $table->unsignedInteger('auth_user_id'); + $table->unsignedInteger('product_id'); + $table->unsignedTinyInteger('num')->default(0); + + $table->timestamps(); + + $table->foreign('product_id') + ->references('id') + ->on('products'); + + $table->foreign('user_id') + ->references('id') + ->on('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_buys'); + } +} diff --git a/public/js/iq-shopping-cart.js b/public/js/iq-shopping-cart.js index 53d3268..21a421e 100755 --- a/public/js/iq-shopping-cart.js +++ b/public/js/iq-shopping-cart.js @@ -58,11 +58,10 @@ var IqShoppingCart = { event.preventDefault(); _self.update_cart_database($(this).data('product-id'), 0); }); - if(_self.is_for === 'me'){ - $('input[name^="'+_self.comp_products+'"]').on('change', function(){ - _self.update_comp_product($(this)); - }); - } + $('input[name^="'+_self.comp_products+'"]').on('change', function(){ + _self.update_comp_product($(this)); + }); + }, update_shipping_state : function (_obj){ var _self = this; diff --git a/resources/views/admin/product/form.blade.php b/resources/views/admin/product/form.blade.php index 3d73982..5d5a683 100755 --- a/resources/views/admin/product/form.blade.php +++ b/resources/views/admin/product/form.blade.php @@ -46,6 +46,29 @@ {{ Form::textarea('copy', $product->copy , array('placeholder'=>__('Produktbeschreibung'), 'class'=>'form-control summernote', 'id'=>'copy')) }} +