shipping costs

This commit is contained in:
Kevin Adametz 2019-01-07 00:15:41 +01:00
parent d4f6a774d0
commit 22a2b4710a
20 changed files with 797 additions and 457 deletions

View file

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Attribute;
use App\Models\Category;
use App\Models\Country;
use App\Models\ShippingCountry;
class HTMLHelper
{
@ -189,6 +190,36 @@ class HTMLHelper
return $ret;
}
public static function getCountriesWithoutUsedShippings($all=true){#
$values = Country::all();
$country_ids = ShippingCountry::all()->pluck('country_id')->toArray();
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
if(!in_array($value->id, $country_ids)){
$ret .= '<option value="'.$value->id.'">'.$value->getLocated().'</option>\n';
}
}
return $ret;
}
public static function getCountriesForShipping($id, $all=false){#
$values = ShippingCountry::all();
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->country->getLocated().'</option>\n';
}
return $ret;
}
public static function getSalutation($id){
$values = array('mr' => __('MR'), 'ms' => __('MS'));

View file

@ -1,6 +1,7 @@
<?php
namespace App\Services;
use App\Models\ShippingCountry;
use \Gloudemans\Shoppingcart\Cart;
use Gloudemans\Shoppingcart\CartItem;
use Illuminate\Session\SessionManager;
@ -11,6 +12,7 @@ class Yard extends Cart
{
private $shipping = 0;
private $shipping_country_id = 0;
public function __construct(SessionManager $session, Dispatcher $events)
{
@ -33,6 +35,24 @@ class Yard extends Cart
}
public function setShippingCountry($shipping_country_id)
{
$this->shipping_country_id = $shipping_country_id ;
if($this->shipping_country_id > 0){
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
$shipping = $shippingCountry->shipping;
$price = $shipping->prices->first();
if($price){
$this->setShipping($price->price);
}
}
}
public function getShippingCountry()
{
return $this->shipping_country_id;
}
/**
* @param null $decimals
* @param null $decimalPoint