mivita/app/Services/HomepartyUserCart.php
2023-07-03 10:07:08 +02:00

170 lines
No EOL
4.9 KiB
PHP

<?php
namespace App\Services;
use App\Models\HomepartyUser;
class HomepartyUserCart
{
/*private $shipping_price = 0;
private $shipping_price_net = 0;
private $shipping_tax_rate = 0;
private $shipping_tax = 0;
private $shipping_country_id = 0; //default de
private $shipping_is_for;
private $num_comp;
private $ysession;
private $yinstance;
private $shopping_data = [];*/
public $points;
public $price;
public $price_net;
public $ek_price;
public $ek_price_net;
public $real_price;
public $income_price;
public $weight;
public $shipping_weight;
public $shipping_price;
public $shipping_tax_rate;
public $shipping_price_net;
public $shipping_tax;
private $homepartyUser;
public function __construct(HomepartyUser $homepartyUser)
{
$this->homepartyUser = $homepartyUser;
//is all total
$this->points = 0;
$this->price = 0;
$this->price_net = 0;
$this->ek_price = 0;
$this->ek_price_net = 0;
$this->real_price = 0;
$this->income_price = 0;
$this->weight = 0;
$this->shipping_weight = 0;
$this->shipping_price = 0;
$this->shipping_tax_rate = 0;
$this->shipping_price_net = 0;
$this->shipping_tax = 0;
$this->calculateUserCart();
}
public function calculateUserCart(){
foreach ($this->homepartyUser->homeparty_user_order_items as $order_item) {
$this->points += $order_item->getTotalPoints();
$this->price += $order_item->getTotalPrice();
$this->real_price += $order_item->getTotalPrice();
$this->price_net += $order_item->geTotalPriceNet();
$this->ek_price += $order_item->geTotalEKPrice();
$this->ek_price_net += $order_item->geTotalEKPriceNet();
$this->income_price += $order_item->geTotalIncomePrice();
$this->weight += ($order_item->product->weight * $order_item->qty);
}
}
public function isPrice(){
return ($this->real_price) > 0 ? true : false;
}
public function getFormattedPoints()
{
return formatNumber($this->points, 0);
}
public function getFormattedPrice()
{
return formatNumber($this->price);
}
public function getFormattedPriceWithout()
{
return formatNumber($this->price - $this->shipping_price);
}
public function getFormattedPriceNet()
{
return formatNumber($this->price_net);
}
public function getFormattedEkPrice()
{
return formatNumber($this->ek_price);
}
public function getFormattedEkPriceWithout()
{
return formatNumber($this->ek_price - $this->shipping_price);
}
public function getFormattedIncomePrice()
{
return formatNumber($this->income_price);
}
public function getFormattedShippingPrice()
{
return formatNumber($this->shipping_price);
}
protected function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
{
if(is_null($decimals)){
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
}
if(is_null($decimalPoint)){
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}
if(is_null($thousandSeperator)){
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
}
public function getCurrencyByKey($key)
{
$rNumber = 0;
if($this->homepartyUser->homeparty && $this->homepartyUser->homeparty->isPriceCurrency()){
$user_country = $this->homepartyUser->homeparty->getUserCountry();
$faktor = isset($user_country->currency_faktor) ? $user_country->currency_faktor : 1;
switch ($key) {
case 'ShippingPrice':
$rNumber = $this->shipping_price * $faktor;
break;
case 'IncomePrice':
$rNumber = $this->income_price * $faktor;
break;
case 'Price':
$rNumber = $this->price * $faktor;
break;
case 'PriceWithout':
$rNumber = ($this->price - $this->shipping_price) * $faktor;
break;
case 'EkPrice':
$rNumber = $this->ek_price * $faktor;
break;
case 'EkPriceWithout':
$rNumber = ($this->ek_price - $this->shipping_price) * $faktor;
break;
}
}
return formatNumber($rNumber);
}
}