promotion 1.0
This commit is contained in:
parent
1cc8e025a1
commit
570d428b1c
60 changed files with 1596 additions and 272 deletions
|
|
@ -44,6 +44,7 @@ class Yard extends Cart
|
|||
private $yard_margin;
|
||||
|
||||
private $global_tax_rate = 0;
|
||||
private $shipping_option; //pick_up//dhl_shipping
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
{
|
||||
|
|
@ -53,42 +54,33 @@ class Yard extends Cart
|
|||
if($this->getYardExtra('shipping_price')){
|
||||
$this->shipping_price = (float) ($this->getYardExtra('shipping_price'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_price_net')){
|
||||
$this->shipping_price_net = (float) ($this->getYardExtra('shipping_price_net'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_tax_rate')){
|
||||
$this->shipping_tax_rate = (float) ($this->getYardExtra('shipping_tax_rate'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_tax')){
|
||||
$this->shipping_tax = (float) ($this->getYardExtra('shipping_tax'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_country_id')){
|
||||
$this->shipping_country_id = $this->getYardExtra('shipping_country_id');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_is_for')){
|
||||
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shopping_user')){
|
||||
$this->user = $this->getYardExtra('shopping_user');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('user')){
|
||||
$this->user = $this->getYardExtra('user');
|
||||
}
|
||||
if($this->getYardExtra('payment_credit')){
|
||||
$this->payment_credit = $this->getYardExtra('payment_credit');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_commission')){
|
||||
$this->yard_commission = $this->getYardExtra('yard_commission');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_margin')){
|
||||
$this->yard_margin = $this->getYardExtra('yard_margin');
|
||||
}
|
||||
|
|
@ -97,10 +89,12 @@ class Yard extends Cart
|
|||
}else{
|
||||
$this->global_tax_rate = config('cart.tax');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('num_comp')){
|
||||
$this->num_comp = $this->getYardExtra('num_comp');
|
||||
}
|
||||
if($this->getYardExtra('shipping_option')){
|
||||
$this->shipping_option = $this->getYardExtra('shipping_option');
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
|
@ -123,10 +117,31 @@ class Yard extends Cart
|
|||
}
|
||||
|
||||
public function setGlobalTaxRate($value){
|
||||
|
||||
$this->global_tax_rate = floatval($value);
|
||||
$this->putYardExtra('global_tax_rate', $this->global_tax_rate);
|
||||
}
|
||||
|
||||
public function setShippingOption($value){
|
||||
$this->shipping_option = $value;
|
||||
$this->putYardExtra('shipping_option', $this->shipping_option);
|
||||
}
|
||||
|
||||
public function getShippingOption(){
|
||||
return $this->shipping_option;
|
||||
}
|
||||
|
||||
public function isQuickShipping(){
|
||||
if($this->shipping_option === 'pick_up' && $this->totalWithShipping(2, '.', '') == 0.00){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isWithPayments(){
|
||||
if($this->totalWithShipping(2, '.', '') == 0.00){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function putYardExtra($key, $value){
|
||||
|
|
@ -272,7 +287,6 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$margin->setCommission($this->yard_commission);
|
||||
$margin->calculate();
|
||||
|
||||
|
|
@ -318,6 +332,15 @@ class Yard extends Cart
|
|||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
if($this->shipping_option && $this->shipping_option === 'pick_up'){
|
||||
$this->shipping_price = 0;
|
||||
$this->shipping_tax_rate = 0;
|
||||
$this->shipping_price_net = 0;
|
||||
$this->shipping_tax = 0;
|
||||
$this->putShippingPrices();
|
||||
return;
|
||||
}
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if(!$shippingCountry){
|
||||
return;
|
||||
|
|
@ -346,7 +369,6 @@ class Yard extends Cart
|
|||
}
|
||||
//default
|
||||
if(!$shipping_price){
|
||||
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
}
|
||||
}
|
||||
|
|
@ -368,14 +390,18 @@ class Yard extends Cart
|
|||
$this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2);
|
||||
$this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2);
|
||||
|
||||
$this->putYardExtra('num_comp', $this->num_comp);
|
||||
$this->putYardExtra('shipping_price', $this->shipping_price);
|
||||
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
|
||||
$this->putYardExtra('shipping_tax', $this->shipping_tax);
|
||||
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
|
||||
$this->putShippingPrices();
|
||||
}
|
||||
}
|
||||
|
||||
private function putShippingPrices(){
|
||||
$this->putYardExtra('num_comp', $this->num_comp);
|
||||
$this->putYardExtra('shipping_price', $this->shipping_price);
|
||||
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
|
||||
$this->putYardExtra('shipping_tax', $this->shipping_tax);
|
||||
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
|
||||
}
|
||||
|
||||
private function shippingPriceBySubTotal($prices, $total){
|
||||
foreach ($prices as $price){
|
||||
if($price->total_from > 0 && $price->total_to > 0){
|
||||
|
|
@ -386,6 +412,7 @@ class Yard extends Cart
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shippingPriceByWeight($prices, $weight){
|
||||
foreach ($prices as $price){
|
||||
if($price->weight_from > 0 && $price->weight_to > 0){
|
||||
|
|
@ -686,8 +713,8 @@ class Yard extends Cart
|
|||
|
||||
public function getFreeProductId(){
|
||||
foreach ($this->content() as $row) {
|
||||
if($row->options->free_product) {
|
||||
return $row->options->product_id;
|
||||
if($row->options->free_product_id) {
|
||||
return $row->options->free_product_id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -699,6 +726,8 @@ class Yard extends Cart
|
|||
foreach ($this->content() as $row) {
|
||||
if($row->options->comp){
|
||||
$comp[100+$row->options->comp] = $row;
|
||||
}elseif($row->options->free_product_id){
|
||||
$comp[200] = $row;
|
||||
}else{
|
||||
$ret[] = $row;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue