Payone, Shop, wizard
This commit is contained in:
parent
446bc4561b
commit
044a6bf253
28 changed files with 996 additions and 814 deletions
|
|
@ -46,7 +46,7 @@ class Yard extends Cart
|
|||
return config('cart.tax');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function putShippingExtra($key, $value){
|
||||
|
||||
$content = $this->getYContent();
|
||||
|
|
@ -71,6 +71,14 @@ class Yard extends Cart
|
|||
}
|
||||
return "";
|
||||
}
|
||||
public function getShippingCountryCountryId()
|
||||
{
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if($shippingCountry && $shippingCountry->country){
|
||||
return $shippingCountry->country->id;
|
||||
}
|
||||
return 1; //default DE
|
||||
}
|
||||
|
||||
public function getShippingCountryId()
|
||||
{
|
||||
|
|
@ -86,27 +94,68 @@ class Yard extends Cart
|
|||
return $this->ysession->get($this->yinstance);
|
||||
}
|
||||
|
||||
|
||||
public function reCalculateShippingPrice(){
|
||||
$this->calculateShippingPrice();
|
||||
}
|
||||
|
||||
public function setShippingCountryWithPrice($shipping_country_id)
|
||||
{
|
||||
$this->shipping_country_id = $shipping_country_id;
|
||||
$this->putShippingExtra('shipping_country_id', $shipping_country_id);
|
||||
$this->calculateShippingPrice();
|
||||
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
$shipping = $shippingCountry->shipping;
|
||||
|
||||
if(intval($this->weight()) == 0){
|
||||
$price = $shipping->prices->first();
|
||||
$price->price = 0;
|
||||
}else{
|
||||
//first by price
|
||||
$price = $this->shippingPriceByTotal($shipping->prices, floatval($this->total(2, '.', ',')));
|
||||
//sec by weight
|
||||
if(!$price){
|
||||
$price = $this->shippingPriceByWeight($shipping->prices, intval($this->weight()));
|
||||
|
||||
if($shipping_country_id > 0){
|
||||
$shippingCountry = ShippingCountry::find($shipping_country_id);
|
||||
$shipping = $shippingCountry->shipping;
|
||||
if($this->weight() == 0){
|
||||
$price = $shipping->prices->first();
|
||||
$price->price = 0;
|
||||
}else{
|
||||
$price = $shipping->prices->first();
|
||||
}
|
||||
if($price){
|
||||
$this->shipping = floatval($price->price);
|
||||
$this->putShippingExtra('shipping_price', $this->shipping);
|
||||
//default
|
||||
if(!$price){
|
||||
$price = $shipping->prices->first();
|
||||
}
|
||||
}
|
||||
if($price){
|
||||
$this->shipping = floatval($price->price);
|
||||
$this->putShippingExtra('shipping_price', $this->shipping);
|
||||
}
|
||||
}
|
||||
|
||||
private function shippingPriceByTotal($prices, $total){
|
||||
foreach ($prices as $price){
|
||||
if($price->total_from > 0 && $price->total_to > 0){
|
||||
if($total >= $price->total_from && $total <= $price->total_to){
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private function shippingPriceByWeight($prices, $weight){
|
||||
foreach ($prices as $price){
|
||||
if($price->weight_from > 0 && $price->weight_to > 0){
|
||||
if($weight >= $price->weight_from && $weight <= $price->weight_to){
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -169,7 +218,7 @@ class Yard extends Cart
|
|||
{
|
||||
$content = $this->getContent();
|
||||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
return $total + ($cartItem->options->weight ? intval($cartItem->options->weight) : 0);
|
||||
return $total + ($cartItem->options->weight ? intval($cartItem->options->weight*$cartItem->qty) : 0);
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue