10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
|
|
@ -2,46 +2,49 @@
|
|||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
|
||||
use Yard;
|
||||
use Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\ProductOrderContext;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
||||
class CardController extends Controller
|
||||
{
|
||||
private $instance = 'webshop';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
|
||||
//Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
||||
// Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
||||
public function addToCardGet($id, $quantity = 1, $product_slug = false)
|
||||
{
|
||||
$product = Product::find($id);
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
if ($product && ProductOrderContext::isProductAllowedInCustomerWebshop($product)) {
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), false, false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]);
|
||||
if(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
->add(
|
||||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
if (Yard::instance($this->instance)->getUserTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
|
@ -50,7 +53,6 @@ class CardController extends Controller
|
|||
}
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
public function addToCardPost($id)
|
||||
|
|
@ -58,39 +60,45 @@ class CardController extends Controller
|
|||
|
||||
$product = Product::find($id);
|
||||
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
if ($product && ProductOrderContext::isProductAllowedInCustomerWebshop($product)) {
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$quantity = Request::get('quantity') ? Request::get('quantity') : 1;
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), false, false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]);
|
||||
if(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
->add(
|
||||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
if (Yard::instance($this->instance)->getUserTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
||||
return back();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function showCard(){
|
||||
public function showCard()
|
||||
{
|
||||
|
||||
if(Request::get('selected_country')){
|
||||
if (Request::get('selected_country')) {
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice(Request::get('selected_country'));
|
||||
}else{
|
||||
} else {
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
}
|
||||
|
||||
//show konflikt wenn user eingeloggt ist und country nicht gesetzt ist
|
||||
// show konflikt wenn user eingeloggt ist und country nicht gesetzt ist
|
||||
$shipping_error = $this->checkShippingError();
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
|
|
@ -98,30 +106,49 @@ class CardController extends Controller
|
|||
'yard_instance' => $this->instance,
|
||||
'shipping_error' => $shipping_error ?? false,
|
||||
];
|
||||
|
||||
return view('web.templates.card', $data);
|
||||
}
|
||||
|
||||
public function updateCard(){
|
||||
public function updateCard()
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
if(isset($data['quantity'])){
|
||||
foreach ($data['quantity'] as $rowId => $qty){
|
||||
if (isset($data['quantity'])) {
|
||||
foreach ($data['quantity'] as $rowId => $qty) {
|
||||
$cartItem = Yard::instance($this->instance)->get($rowId);
|
||||
if ($cartItem) {
|
||||
$product = Product::find($cartItem->id);
|
||||
if ($product && $product->is_membership_only) {
|
||||
$qty = 1;
|
||||
}
|
||||
}
|
||||
Yard::instance($this->instance)->update($rowId, $qty);
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
}
|
||||
}else{
|
||||
$this->deleteCard();
|
||||
} else {
|
||||
$this->deleteCard();
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
public function checkoutServer(){
|
||||
|
||||
public function checkoutServer()
|
||||
{
|
||||
foreach (Yard::instance($this->instance)->content() as $row) {
|
||||
$product = Product::find($row->id);
|
||||
if (! $product || ! ProductOrderContext::isProductAllowedInCustomerWebshop($product)) {
|
||||
\Session::flash('alert-error', __('msg.cart_product_not_allowed_for_order_type'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'shopping';
|
||||
|
|
@ -130,7 +157,7 @@ class CardController extends Controller
|
|||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment' => 1, //Customer Shop Payment
|
||||
'payment' => 1, // Customer Shop Payment
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance($this->instance)->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
|
|
@ -138,55 +165,63 @@ class CardController extends Controller
|
|||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
|
||||
Yard::instance($this->instance)->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
if(strpos($path, 'https') === false){
|
||||
// add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
if (strpos($path, 'https') === false) {
|
||||
$path = str_replace('http', 'https', $path);
|
||||
}
|
||||
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
public function backToShop(){
|
||||
public function backToShop()
|
||||
{
|
||||
$this->deleteCard();
|
||||
return redirect(url('/'));
|
||||
|
||||
return redirect(url('/'));
|
||||
}
|
||||
public function removeCard($rowId){
|
||||
|
||||
public function removeCard($rowId)
|
||||
{
|
||||
|
||||
Yard::instance($this->instance)->remove($rowId);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
public function deleteCard(){
|
||||
public function deleteCard()
|
||||
{
|
||||
|
||||
$setCode = Shop::getUserShopLang(null, $this->instance);
|
||||
$mylangs = Shop::getLangChange($this->instance);
|
||||
foreach($mylangs as $code => $country){
|
||||
if(strtolower($setCode) === strtolower($code)){
|
||||
foreach ($mylangs as $code => $country) {
|
||||
if (strtolower($setCode) === strtolower($code)) {
|
||||
Shop::initUserShopLang($country, $this->instance);
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function checkShippingError(){
|
||||
private function checkShippingError()
|
||||
{
|
||||
$shipping_error = false;
|
||||
if(\Auth::guard('customers')->check()){
|
||||
if (\Auth::guard('customers')->check()) {
|
||||
$user = \Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
if ($user->shopping_user_id) {
|
||||
$shopping_user = ShoppingUser::find($user->shopping_user_id);
|
||||
if($shopping_user->same_as_billing){
|
||||
if($shopping_user->billing_country_id != Yard::instance($this->instance)->getUserCountryId()){
|
||||
if ($shopping_user->same_as_billing) {
|
||||
if ($shopping_user->billing_country_id != Yard::instance($this->instance)->getUserCountryId()) {
|
||||
$user_country = Yard::instance($this->instance)->getUserCountry();
|
||||
$user_country_name = $user_country ? $user_country->getLocated() : '';
|
||||
$billing_country = $shopping_user->billing_country;
|
||||
$country_name = $billing_country ? $billing_country->getLocated() : '';
|
||||
$shipping_error = __('website.shipping_error_billing', ['shipping_country' => $user_country_name, 'billing_country' => $country_name]);
|
||||
}
|
||||
}else{
|
||||
if($shopping_user->shipping_country_id != Yard::instance($this->instance)->getUserCountryId()){
|
||||
} else {
|
||||
if ($shopping_user->shipping_country_id != Yard::instance($this->instance)->getUserCountryId()) {
|
||||
$user_country = Yard::instance($this->instance)->getUserCountry();
|
||||
$user_country_name = $user_country ? $user_country->getLocated() : '';
|
||||
$shipping_country = $shopping_user->shipping_country;
|
||||
|
|
@ -194,9 +229,9 @@ class CardController extends Controller
|
|||
$shipping_error = __('website.shipping_error_delivery', ['shipping_country' => $user_country_name, 'billing_country' => $country_name]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $shipping_error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue