Custom Price / Land / User Order Homeparty
This commit is contained in:
parent
d46824a4ac
commit
51d81d8ec6
55 changed files with 1951 additions and 681 deletions
|
|
@ -1,14 +1,15 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use \Gloudemans\Shoppingcart\Cart;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
|
||||
|
||||
class Yard extends Cart
|
||||
|
|
@ -21,7 +22,10 @@ class Yard extends Cart
|
|||
private $shipping_is_for;
|
||||
private $num_comp;
|
||||
private $ysession;
|
||||
private $yinstance;
|
||||
private $user_tax_free;
|
||||
private $user_reverse_charge;
|
||||
private $user_country_id;
|
||||
private $user_country;
|
||||
private $shopping_data = [];
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
|
|
@ -51,10 +55,21 @@ class Yard extends Cart
|
|||
if($this->getYardExtra('shipping_is_for')){
|
||||
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('num_comp')){
|
||||
$this->num_comp = $this->getYardExtra('num_comp');
|
||||
}
|
||||
if($this->getYardExtra('user_tax_free')){
|
||||
$this->user_tax_free = $this->getYardExtra('user_tax_free');
|
||||
}
|
||||
if($this->getYardExtra('user_reverse_charge')){
|
||||
$this->user_reverse_charge = $this->getYardExtra('user_reverse_charge');
|
||||
}
|
||||
if($this->getYardExtra('user_country_id')){
|
||||
$this->user_country_id = $this->getYardExtra('user_country_id');
|
||||
}
|
||||
if($this->getYardExtra('user_country')){
|
||||
$this->user_country = $this->getYardExtra('user_country');
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
|
@ -139,6 +154,44 @@ class Yard extends Cart
|
|||
|
||||
}
|
||||
|
||||
public function setUserPriceInfos($setUserPriceInfos = [])
|
||||
{
|
||||
$this->user_tax_free = $setUserPriceInfos['user_tax_free'];
|
||||
$this->putYardExtra('user_tax_free', $setUserPriceInfos['user_tax_free']);
|
||||
|
||||
$this->user_reverse_charge = $setUserPriceInfos['user_reverse_charge'];
|
||||
$this->putYardExtra('user_reverse_charge', $setUserPriceInfos['user_reverse_charge']);
|
||||
|
||||
$this->user_country_id = $setUserPriceInfos['user_country_id'];
|
||||
$this->putYardExtra('user_country_id', $setUserPriceInfos['user_country_id']);
|
||||
|
||||
$this->user_country = Country::findOrFail($setUserPriceInfos['user_country_id']);
|
||||
$this->putYardExtra('user_country', $this->user_country);
|
||||
}
|
||||
|
||||
public function getUserPriceInfos(){
|
||||
return [
|
||||
'user_tax_free' =>$this->user_tax_free,
|
||||
'user_reverse_charge' =>$this->user_reverse_charge,
|
||||
'user_country_id' =>$this->user_country_id,
|
||||
];
|
||||
}
|
||||
|
||||
public function getUserCountryId()
|
||||
{
|
||||
return $this->user_country_id;
|
||||
}
|
||||
|
||||
public function getUserCountry()
|
||||
{
|
||||
return $this->user_country;
|
||||
}
|
||||
|
||||
public function getUserTaxFree()
|
||||
{
|
||||
return $this->user_tax_free;
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
|
|
@ -146,9 +199,11 @@ class Yard extends Cart
|
|||
return;
|
||||
}
|
||||
$shipping = $shippingCountry->shipping;
|
||||
|
||||
if($this->weight() == 0){
|
||||
$shipping_price = $shipping->shipping_prices->first();
|
||||
if(!$shipping_price){
|
||||
return;
|
||||
}
|
||||
$shipping_price->price = 0;
|
||||
$shipping_price->price_comp = 0;
|
||||
}else{
|
||||
|
|
@ -241,16 +296,24 @@ class Yard extends Cart
|
|||
|
||||
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
if($this->user_tax_free){
|
||||
return $this->numberFormat(0, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
$total = $this->totalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
return $this->numberFormat(($total - $totalTax), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
if($this->user_tax_free){
|
||||
$total = (float) ($this->subtotal(2, '.', '')) + $this->shipping_price_net;
|
||||
}else{
|
||||
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
}
|
||||
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +422,7 @@ class Yard extends Cart
|
|||
}
|
||||
$price = $product->price;
|
||||
if($set_price === 'with'){
|
||||
$price = $product->getPriceWith(false, true);
|
||||
$price = $product->getPriceWith(false, true, $this->getUserCountry());
|
||||
}
|
||||
$cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
$content = $this->getContent();
|
||||
|
|
@ -402,6 +465,71 @@ class Yard extends Cart
|
|||
return $this->numberFormat(($price * $row->qty), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
public function isPriceCurrency()
|
||||
{
|
||||
return ($this->user_country && $this->user_country->currency) ? true : false;
|
||||
}
|
||||
|
||||
public function getPriceCurrencyUnit()
|
||||
{
|
||||
return ($this->user_country && $this->user_country->currency) ? $this->user_country->currency_unit : false;
|
||||
}
|
||||
|
||||
public function convertCurrency($value = 0, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
if($this->isPriceCurrency()){
|
||||
$faktor = isset($this->user_country->currency_faktor) ? $this->user_country->currency_faktor : 1;
|
||||
$value = Util::reFormatNumber($value);
|
||||
return $this->numberFormat($value, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
public function getCurrencyByKey($key = false, CartItem $row = null, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
|
||||
if($this->isPriceCurrency()){
|
||||
$rNumber = 0;
|
||||
$faktor = isset($this->user_country->currency_faktor) ? $this->user_country->currency_faktor : 1;
|
||||
switch ($key) {
|
||||
case 'rowPriceNetCurrency':
|
||||
if($row){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
$rNumber = $price * $faktor;
|
||||
}
|
||||
break;
|
||||
case 'rowSubtotalCurrency':
|
||||
if($row){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
$rNumber = $price * $faktor * $row->qty;
|
||||
}
|
||||
break;
|
||||
case 'subtotal':
|
||||
$rNumber = (float) ($this->subtotal(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'shippingNet':
|
||||
$rNumber = (float) ($this->shippingNet(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'subtotalWithShipping':
|
||||
$rNumber = (float) ($this->subtotalWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'taxWithShipping':
|
||||
$rNumber = (float) ($this->taxWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'totalWithShipping':
|
||||
$rNumber = (float) ($this->totalWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'total':
|
||||
$rNumber = (float) ($this->total(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'shipping':
|
||||
$rNumber = (float) ($this->shipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
}
|
||||
return $this->numberFormat($rNumber, $decimals, $decimalPoint, $thousandSeperator);
|
||||
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getNumComp(){
|
||||
return $this->num_comp;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue