01 2022 Microsite Promotion

This commit is contained in:
Kevin Adametz 2022-01-18 18:30:14 +01:00
parent 3f1fb9377d
commit 38e7fd504a
39 changed files with 761 additions and 336 deletions

View file

@ -21,7 +21,7 @@ class CategoryController extends Controller
{
$data = [
'values' => Category::all(),
'values' => Category::orderBy('pos', 'ASC')->get(),
];
return view('admin.category.index', $data);
}
@ -46,42 +46,66 @@ class CategoryController extends Controller
{
$data = Request::all();
$data['active'] = isset($data['active']) ? true : false;
$data['parent_id'] = isset($data['parent_id']) ? $data['parent_id'] : null;
if($data['id'] == "new"){
$model = Category::create($data);
}else{
$model = Category::find($data['id']);
$model->fill($data)->save();
if($data['action'] === 'save-product_category'){
if($data['id'] === 'new'){
$ProductCategory = ProductCategory::create([
'pos' => $data['pos'],
'product_id' => $data['product_id'],
'category_id' => $data['category_id'],
]);
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_category_edit', [$ProductCategory->category_id]));
}else{
$ProductCategory = ProductCategory::findOrFail($data['id']);
if($ProductCategory->category_id != $data['category_id']){
abort(404);
}
$ProductCategory->pos = $data['pos'];
$ProductCategory->product_id = $data['product_id'];
$ProductCategory->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_category_edit', [$ProductCategory->category_id]));
}
}
$trans = [];
if(!empty($data['trans_name'])){
foreach ($data['trans_name'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
if($data['action'] === 'save-form'){
$data['active'] = isset($data['active']) ? true : false;
$data['parent_id'] = isset($data['parent_id']) ? $data['parent_id'] : null;
if($data['id'] == "new"){
$model = Category::create($data);
}else{
$model = Category::find($data['id']);
$model->fill($data)->save();
}
$trans = [];
if(!empty($data['trans_name'])){
foreach ($data['trans_name'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
}
}
}
}
$model->trans_name = $trans;
$model->save();
$trans = [];
if(!empty($data['trans_headline'])){
foreach ($data['trans_headline'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
$model->trans_name = $trans;
$model->save();
$trans = [];
if(!empty($data['trans_headline'])){
foreach ($data['trans_headline'] as $lang => $value){
if($value && $value != null){
$trans[$lang] = $value;
}
}
}
$model->trans_headline = $trans;
$model->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_categories'));
}
$model->trans_headline = $trans;
$model->save();
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_categories'));
}
@ -157,7 +181,7 @@ class CategoryController extends Controller
return redirect(route('admin_product_category_edit', [$category->id]));
}
catch (Exception $e) {
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect(route('admin_product_category_edit', [$category->id]));
}

View file

@ -8,6 +8,8 @@ use Response;
use Validator;
use App\Services\Util;
use App\Models\Product;
use App\Models\Category;
use App\Services\Payment;
use App\Models\UserHistory;
use App\Models\PaymentMethod;
use App\Models\PromotionUser;
@ -17,7 +19,6 @@ use App\Services\PromotionCart;
use App\Models\PaymentTransaction;
use App\Http\Controllers\Controller;
use App\Repositories\CheckoutRepository;
use App\Services\Payment;
class PromotionController extends Controller
{
@ -45,10 +46,16 @@ class PromotionController extends Controller
return view('web.promotion.outofstock', $data);
}
PromotionCart::initYard();
$first_category = Category::where('active', true)->whereJsonContains('show_on', ['3'])->orderBy('pos', 'DESC')->first();
$first_category_id = isset($first_category->id) ? $first_category->id : false;
$shop_products = $this->getShowProducts();
$data = [
'promotion_user' => $PromotionUser,
'shop_products' => Product::where('active', true)->whereJsonContains('show_on', ['3'])->orderBy('pos', 'ASC')->get(),
'shop_products' => $shop_products,
'user_payment_methods' => PaymentMethod::getDefaultAsArray()->toArray(),
'first_category_id' => $first_category_id,
];
return view('web.promotion.index', $data);
}
@ -95,7 +102,6 @@ class PromotionController extends Controller
}
if($data['action'] === 'submit-reminder-service'){
return redirect(route('web_promotion_goto', ['thanksreminder', $PromotionUser->id]));
}
if($data['action'] === 'submit-promotion-order'){
$rules = array(
@ -142,8 +148,6 @@ class PromotionController extends Controller
}
}
private function directPaymentStatus(PaymentTransaction $payt, $identifier){
if(isset($payt->transmitted_data['param'])){
@ -201,12 +205,19 @@ class PromotionController extends Controller
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if($data['action'] === 'web-show-product'){
$product = Product::find($data['id']); //current user form order
$ret = view("web.promotion.show_product", compact('product', 'data'))->render();
}
if($data['perform']){
if(isset($data['perform'])){
if($data['action'] === 'switch-show_products'){
$category_id = isset($data['show_products_option']) ? $data['show_products_option'] : false;
$shop_products = $this->getShowProducts($category_id);
$shop_products_view = view("web.promotion._shop_products_inner", compact('shop_products'))->render();
return response()->json(['response' => $data, 'shop_products_view'=>$shop_products_view, 'status'=>$status]);
}
if($data['action'] === 'switch-free-product'){
\App\Services\PromotionCart::updateFeeProduct($data);
}
@ -226,6 +237,10 @@ class PromotionController extends Controller
if($data['action'] === 'switch-shipping'){
\App\Services\PromotionCart::switchShipping($data);
}
if($data['action'] === 'change-state-shipping'){
\App\Services\PromotionCart::changeStateShipping($data);
}
$cart = view("web.promotion._promotion_cart", compact('data'))->render();
if(Yard::instance('shopping')->isQuickShipping()){
$invoice = view("web.promotion._invoice_details_quick")->render();
@ -233,10 +248,25 @@ class PromotionController extends Controller
$invoice = view("web.promotion._invoice_details")->render();
}
$checkout = view("web.promotion._checkout")->render();
$data['shipping_price_formated'] = Yard::instance('shopping')->shipping();
return response()->json(['response' => $data, 'cart'=>$cart, 'invoice'=>$invoice, 'checkout'=>$checkout, 'status'=>$status]);
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
}
private function getShowProducts($category_id = false){
$shop_products = [];
if($category_id){
$shop_products = Product::where('active', true)->whereJsonContains('show_on', ['3'])
->whereHas('categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id); //->whereJsonContains('show_on', ['3']);
})->orderBy('pos', 'ASC')->get();
}else{
$shop_products = Product::where('active', true)->whereJsonContains('show_on', ['3'])
->orderBy('pos', 'ASC')->get();
}
return $shop_products;
}
}

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Services\Type;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
@ -53,10 +54,10 @@ class Category extends Model
protected $table = 'categories';
protected $casts = ['trans_name' => 'array', 'trans_headline' => 'array'];
protected $casts = ['trans_name' => 'array', 'trans_headline' => 'array', 'show_on' => 'array'];
protected $fillable = [
'parent_id', 'name', 'headline', 'pos', 'active',
'parent_id', 'name', 'headline', 'pos', 'active', 'show_on'
];
public function sluggable()
@ -133,4 +134,15 @@ class Category extends Model
return rtrim($ret, ', ');
}
public function getShowOnTypes(){
$ret = [];
if(is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
}
return $ret;
}
}

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Services\Type;
use App\Services\Util;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@ -65,35 +66,16 @@ class PaymentMethod extends Model
'active'
];
public static $showATs = [
0 => 'Nur Kunden Shop',
1 => 'Nur Vertriebspartner Shop',
2 => 'Kunden + Vertriebspartner Shop',
3 => 'Nur Reg/Mitgliedschaft Vertriebspartner',
4 => 'Kunden + Vertriebspartner Shop + Reg/Mitgliedschaft',
5 => 'Vertriebspartner Shop + Reg/Mitgliedschaft',
9 => 'überall',
];
public static $showONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'überall',
];
public function getShowAtType(){
return isset(self::$showATs[$this->show_at]) ? self::$showATs[$this->show_at] : '-';
return isset(Type::$payShowATs[$this->show_at]) ? Type::$payShowATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
$ret = [];
if($this->show_on){
foreach($this->show_on as $show){
$ret[] = isset(self::$showONs[$show]) ? self::$showONs[$show] : '-';
$ret[] = isset(Type::$payShowONs[$show]) ? Type::$payShowONs[$show] : '-';
}
}
return $ret;

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Services\Type;
use App\Services\Util;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
@ -218,27 +219,7 @@ class Product extends Model
4 => 'KG',
];
public $showATs = [
0 => 'Nur Kunden Bestellungen',
1 => 'Kunden + Vertriebspartner Bestellungen',
2 => 'Nur Vertriebspartner Bestellungen',
3 => 'Registrierung / Mitgliedschaft Vertriebspartner',
4 => 'Nur Mitgliedschaft Vertriebspartner',
//5 => 'Onboarding Vertriebspartner',
//6 => 'Onboarding Vertriebspartner + Vertriebspartner Shop',
7 => 'zur internen Berechnung',
];
public $showONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'zur internen Berechnung',
];
public $actions = [
@ -439,13 +420,13 @@ class Product extends Model
return isset($this->unitTypes[$this->unit]) ? $this->unitTypes[$this->unit] : '-';
}
public function getShowAtType(){
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
return isset(Type::$showATs[$this->show_at]) ? Type::$showATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset($this->showONs[$show]) ? $this->showONs[$show] : '-';
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
return $ret;
}

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Services\Type;
use Illuminate\Database\Eloquent\Model;
/**
@ -28,8 +29,12 @@ class ProductCategory extends Model
{
protected $table = 'product_categories';
protected $casts = [
'show_on' => 'array',
];
protected $fillable = [
'product_id', 'category_id',
'pos', 'product_id', 'category_id', 'show_on'
];
public function product()
@ -42,4 +47,12 @@ class ProductCategory extends Model
return $this->belongsTo('App\Models\Category', 'category_id');
}
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
return $ret;
}
}

View file

@ -80,6 +80,13 @@ class Shipping extends Model
}
public function getShippingPricesBy($shipping_for){
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id')->where('shipping_for', $shipping_for);
return ShippingPrice::where('shipping_id', $this->id)->where('shipping_for', $shipping_for)->get();
}
public function getShippingPricesFirstBy($shipping_for){
return ShippingPrice::where('shipping_id', $this->id)->where('shipping_for', $shipping_for) ->orderBy('price', 'ASC')->first();
}
}

View file

@ -159,7 +159,18 @@ class ProductRepository extends BaseRepository {
'attribute_id' => $attribute->attribute_id,
]);
}
//INCS
$ingredients = $model->p_ingredients()->pluck('ingredient_id')->toArray();
if(is_array($ingredients)){
foreach ($ingredients as $incs_id){
ProductIngredient::create([
'product_id' => $this->model->id,
'ingredient_id' => $incs_id,
]);
}
}
//images
foreach ($model->images as $image){
$name = \App\Services\Slim::sanitizeFileName($image->original_name);

View file

@ -211,6 +211,19 @@ class HTMLHelper
return $ret;
}
public static function getCategoriesOptionsByShowOn($ids = array(), $all = false, $show_on = []){
$values = Category::where('active', true)->whereJsonContains('show_on', $show_on)->orderBy('pos', 'ASC')->get();
$ret = "";
if($all){
$ret .= '<option value="">'.$all.'</option>\n';
}
foreach ($values as $value){
$attr = in_array($value->id, $ids) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
}
return $ret;
}
public static function getProductIngredientsOptions($has_ids = array(), $all = true){
$values = Ingredient::where('active', 1)->get();
$ret = "";
@ -327,8 +340,20 @@ class HTMLHelper
return "not defined";
}
public static function getCountriesForShipping($id, $all=false){#
public static function getCountriesForShipping($id, $all=false, $shipping_for = false){#
$values = ShippingCountry::all();
if($shipping_for){
$temp = [];
foreach($values as $value){
if($shipping = $value->shipping){
if($shipping->getShippingPricesFirstBy($shipping_for)){
$temp[] = $value;
}
}
}
$values = $temp;
}
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';

View file

@ -28,7 +28,7 @@ class PromotionCart
{
if($ShippingCountry = ShippingCountry::all()->first()){
if($ShippingCountry->shipping){
if($ShippingPrices = $ShippingCountry->shipping->getShippingPricesBy($shipping_for)->orderBy('price', 'ASC')->first()){
if($ShippingPrices = $ShippingCountry->shipping->getShippingPricesFirstBy($shipping_for)){
return formatNumber($ShippingPrices->price);
}
}
@ -48,6 +48,18 @@ class PromotionCart
}
public static function changeStateShipping($data)
{
$id = 1;
if($ShippingCountry = ShippingCountry::find($data['shipping_country_id'])){
$id = $ShippingCountry->id;
}
Yard::instance('shopping')->setShippingCountryWithPrice($id, 'shop');
}
public static function updateProduct($data, $add=false)
{
if($product = Product::find($data['product_id'])){
@ -100,7 +112,8 @@ class PromotionCart
[
'image' => $image,
'slug' => $product->slug,
'weight' => $product->weight,
//'weight' => $product->weight,
'weight' => 1,
'free_product_id' => intval($data['free_product_id']),
'product_id' => $product->id
]);

53
app/Services/Type.php Normal file
View file

@ -0,0 +1,53 @@
<?php
namespace App\Services;
class Type
{
public static $showATs = [
0 => 'Nur Kunden Bestellungen',
1 => 'Kunden + Vertriebspartner Bestellungen',
2 => 'Nur Vertriebspartner Bestellungen',
3 => 'Registrierung / Mitgliedschaft Vertriebspartner',
4 => 'Nur Mitgliedschaft Vertriebspartner',
//5 => 'Onboarding Vertriebspartner',
//6 => 'Onboarding Vertriebspartner + Vertriebspartner Shop',
7 => 'zur internen Berechnung',
];
public static $showONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'zur internen Berechnung',
];
public static $payShowATs = [
0 => 'Nur Kunden Shop',
1 => 'Nur Vertriebspartner Shop',
2 => 'Kunden + Vertriebspartner Shop',
3 => 'Nur Reg/Mitgliedschaft Vertriebspartner',
4 => 'Kunden + Vertriebspartner Shop + Reg/Mitgliedschaft',
5 => 'Vertriebspartner Shop + Reg/Mitgliedschaft',
9 => 'überall',
];
public static $payShowONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'überall',
];
}

View file

@ -181,7 +181,6 @@ class Yard extends Cart
return $this->shipping_country_id;
}
public function getYContent()
{
if (is_null($this->ysession->get($this->yinstance))) {
@ -366,11 +365,14 @@ class Yard extends Cart
//sec by weight
if(!$shipping_price){
$shipping_price = $this->shippingPriceByWeight($shipping->getShippingPricesBy($shipping_price_for), $this->weight());
}
//default
if(!$shipping_price){
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
}
}
if($shipping_price){
$price = $shipping_price->price;
@ -443,7 +445,6 @@ class Yard extends Cart
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){