Free Shipping, Business Levels correction, Products Buying, Fonts

This commit is contained in:
Kevin Adametz 2023-01-25 12:37:29 +01:00
parent 3f2fbd6d5b
commit 0341c9c189
197 changed files with 9161 additions and 329 deletions

View file

@ -22,6 +22,7 @@ class Yard extends Cart
private $num_comp;
private $ysession;
private $user_tax_free;
private $shipping_free;
private $user_reverse_charge;
private $user_country_id;
private $user_country;
@ -62,6 +63,9 @@ class Yard extends Cart
if($this->getYardExtra('user_tax_free')){
$this->user_tax_free = $this->getYardExtra('user_tax_free');
}
if($this->getYardExtra('shipping_free')){
$this->shipping_free = $this->getYardExtra('shipping_free');
}
if($this->getYardExtra('user_reverse_charge')){
$this->user_reverse_charge = $this->getYardExtra('user_reverse_charge');
}
@ -159,14 +163,17 @@ class Yard extends Cart
public function setUserPriceInfos($setUserPriceInfos = [])
{
$this->shipping_free = isset($setUserPriceInfos['shipping_free']) ? $setUserPriceInfos['shipping_free'] : false;
$this->putYardExtra('shipping_free', $this->shipping_free);
$this->user_tax_free = $setUserPriceInfos['user_tax_free'];
$this->putYardExtra('user_tax_free', $setUserPriceInfos['user_tax_free']);
$this->putYardExtra('user_tax_free', $this->user_tax_free);
$this->user_reverse_charge = $setUserPriceInfos['user_reverse_charge'];
$this->putYardExtra('user_reverse_charge', $setUserPriceInfos['user_reverse_charge']);
$this->putYardExtra('user_reverse_charge', $this->user_reverse_charge);
$this->user_country_id = $setUserPriceInfos['user_country_id'];
$this->putYardExtra('user_country_id', $setUserPriceInfos['user_country_id']);
$this->putYardExtra('user_country_id', $this->user_country_id);
$this->user_country = Country::findOrFail($setUserPriceInfos['user_country_id']);
$this->putYardExtra('user_country', $this->user_country);
@ -177,6 +184,7 @@ class Yard extends Cart
'user_tax_free' =>$this->user_tax_free,
'user_reverse_charge' =>$this->user_reverse_charge,
'user_country_id' =>$this->user_country_id,
'shipping_free' => $this->shipping_free,
];
}
@ -195,6 +203,11 @@ class Yard extends Cart
return $this->user_tax_free ? true : false;
}
public function getShippingFree()
{
return $this->shipping_free;
}
private function calculateShippingPrice(){
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
@ -202,19 +215,29 @@ class Yard extends Cart
return;
}
$shipping = $shippingCountry->shipping;
$shipping_price = $shipping->shipping_prices->first();
if(!$shipping_price){
return;
}
if($this->weight() == 0){
$shipping_price = $shipping->shipping_prices->first();
if(!$shipping_price){
return;
}
$shipping_price->price = 0;
$shipping_price->price_comp = 0;
}else{
//first by price
$shipping_price = $this->shippingPriceByTotal($shipping->shipping_prices, $this->total(2, '.', ''));
//sec by weight
if(!$shipping_price){
if($this->shipping_free && $this->total(2, '.', '') >= $this->shipping_free){
if($this->weightByFreeShipping() == 0){
$shipping_price->price = 0;
$shipping_price->price_comp = 0;
}else{
$shipping_price = $this->shippingPriceByWeight($shipping->shipping_prices, $this->weightByFreeShipping());
}
}else{
$shipping_price = $this->shippingPriceByWeight($shipping->shipping_prices, $this->weight());
//first by price
//$shipping_price = $this->shippingPriceByTotal($shipping->shipping_prices, $this->total(2, '.', ''));
//sec by weight
//if(!$shipping_price){
//}
}
//default
if(!$shipping_price){
@ -338,6 +361,18 @@ class Yard extends Cart
return $total;
}
public function weightByFreeShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$content = $this->getContent();
$total = $content->reduce(function ($total, CartItem $cartItem) {
if($cartItem->options->no_free_shipping){
return $total + ($cartItem->options->weight ? ($cartItem->options->weight*$cartItem->qty) : 0);
}
return $total;
}, 0);
return $total;
}
public function points()
{
$content = $this->getContent();