Country Prices | Homeparty | Shop | Order

This commit is contained in:
Kevin Adametz 2021-08-27 18:53:12 +02:00
parent 51d81d8ec6
commit 39d1e93416
284 changed files with 784 additions and 216 deletions

View file

@ -2,18 +2,20 @@
namespace App\Http\Controllers;
use App\Mail\MailInfo;
use App\Models\Product;
use App\Models\ShoppingInstance;
use App\Models\UserHistory;
use App\User;
use Auth;
use Carbon;
use Config;
use Illuminate\Validation\Rules\In;
use Request;
use Util;
use Yard;
use Carbon;
use Config;
use Request;
use App\User;
use App\Mail\MailInfo;
use App\Models\Product;
use App\Models\UserHistory;
use App\Services\UserService;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use Illuminate\Validation\Rules\In;
use Illuminate\Support\Facades\Mail;
@ -43,6 +45,13 @@ class MembershipController extends Controller
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->get()->last();
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
$shipping_country_id = $this->checkShoppingCountry($user);
if(!$shipping_country_id){
abort(403, __('validation.custom.shipping_not_found'));
}
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
$data = [
'user' => $user,
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
@ -51,11 +60,27 @@ class MembershipController extends Controller
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
'userHistoryDeleteMembership' => $userHistoryDeleteMembership,
'yard_info' => UserService::getYardInfo(),
];
return view('user.membership.index', $data);
}
private function checkShoppingCountry($user ){
$country_id = null;
if($user->account->same_as_billing){
$country_id = $user->account->country_id;
}else{
$country_id = $user->account->shipping_country_id;
}
if($country_id){
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
return $shipping_country->id;
}
}
return false;
}
public function storePayment($action){
@ -90,13 +115,29 @@ class MembershipController extends Controller
$user->abo_options = true;
$user->save();
}
$shipping_country_id = $this->checkShoppingCountry($user);
if(!$shipping_country_id){
abort(403, __('validation.custom.shipping_not_found'));
}
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
if($product && $product->active){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
}
$qty = Request::get('qty') ? Request::get('qty') : 1;
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
if(\App\Services\UserService::getTaxFree()){
Yard::setTax($cartItem->rowId, 0);
}else{
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
}
do {
$identifier = Util::getToken();
@ -105,6 +146,7 @@ class MembershipController extends Controller
$data = [];
$data['is_from'] = 'membership';
$data['is_for'] = 'me';
$data['user_price_infos'] = \App\Services\UserService::getUserPriceInfos();
ShoppingInstance::create([
'identifier' => $identifier,