105 lines
No EOL
3.3 KiB
PHP
105 lines
No EOL
3.3 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
use Yard;
|
|
use App\Models\Product;
|
|
use App\Models\ShippingCountry;
|
|
|
|
class PromotionCart
|
|
{
|
|
|
|
public static $points = 0;
|
|
public static $price = 0;
|
|
public static $price_net = 0;
|
|
public static $ek_price = 0;
|
|
public static $income_price = 0;
|
|
|
|
|
|
public static function initYard(){
|
|
|
|
$id = 1;
|
|
if($ShippingCountry = ShippingCountry::all()->first()){
|
|
$id = $ShippingCountry->id;
|
|
}
|
|
Yard::instance('shopping')->setShippingCountryWithPrice($id, 'shop');
|
|
}
|
|
|
|
public static function getLowestShippingPrice($shipping_for = 2)
|
|
{
|
|
if($ShippingCountry = ShippingCountry::all()->first()){
|
|
if($ShippingCountry->shipping){
|
|
if($ShippingPrices = $ShippingCountry->shipping->getShippingPricesBy($shipping_for)->orderBy('price', 'ASC')->first()){
|
|
return formatNumber($ShippingPrices->price);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function clearCart($data, $add=false)
|
|
{
|
|
Yard::instance('shopping')->destroy();
|
|
}
|
|
|
|
public static function updateProduct($data, $add=false)
|
|
{
|
|
if($product = Product::find($data['product_id'])){
|
|
$image = "";
|
|
if($product->images->count()){
|
|
$image = $product->images->first()->slug;
|
|
}
|
|
|
|
//get the card item
|
|
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax,
|
|
[
|
|
'image' => $image,
|
|
'slug' => $product->slug,
|
|
'weight' => $product->weight,
|
|
]);
|
|
|
|
Yard::setTax($cartItem->rowId, $product->tax);
|
|
if(!$add){
|
|
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
|
|
Yard::instance('shopping')->remove($cartItem->rowId);
|
|
}
|
|
}
|
|
|
|
Yard::instance('shopping')->reCalculate();
|
|
return $cartItem->qty;
|
|
}
|
|
}
|
|
|
|
public static function updateFeeProduct($data)
|
|
{
|
|
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->free_product) {
|
|
Yard::instance('shopping')->remove($row->rowId);
|
|
}
|
|
}
|
|
|
|
if(isset($data['free_poduct_id'])) {
|
|
if ($product = Product::find($data['free_poduct_id'])) {
|
|
$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,
|
|
'free_product' => 1,
|
|
'product_id' => $product->id
|
|
]);
|
|
Yard::setTax($cartItem->rowId, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} |