final checkout and card

This commit is contained in:
Kevin Adametz 2019-02-21 21:38:36 +01:00
parent 4bd21bd986
commit 1953c97cd0
33 changed files with 2131 additions and 1084 deletions

View file

@ -6,52 +6,95 @@ use \Gloudemans\Shoppingcart\Cart;
use Gloudemans\Shoppingcart\CartItem;
use Illuminate\Session\SessionManager;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Collection;
class Yard extends Cart
{
private $shipping = 0;
private $shipping_country_id = 0;
private $shipping_country_id = 7; //default de
private $ysession;
private $yinstance;
public function __construct(SessionManager $session, Dispatcher $events)
{
$this->ysession = $session;
$this->yinstance = sprintf('%s.%s', 'cart', 'shipping_extras');
if($this->getShippingExtra('shipping_price')){
$this->shipping = floatval($this->getShippingExtra('shipping_price'));
}
if($this->getShippingExtra('shipping_country_id')){
$this->shipping_country_id = $this->getShippingExtra('shipping_country_id');
}
parent::__construct($session, $events);
}
public static function getTaxRate()
{
return config('cart.tax');
}
/**
* @param $shipping
*/
public function setShipping($shipping)
{
$this->shipping = floatval($shipping); ;
public function putShippingExtra($key, $value){
$content = $this->getYContent();
$content->put($key, $value);
$this->ysession->put($this->yinstance, $content);
}
public function setShippingCountry($shipping_country_id)
public function getShippingExtra($key){
$content = $this->getYContent();
if ($content->has($key)){
return $content->get($key);
}
return false;
}
public function getShippingCountryName(){
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
if($shippingCountry && $shippingCountry->country){
return $shippingCountry->country->getLocated();
}
return "";
}
public function getShippingCountryId()
{
$this->shipping_country_id = $shipping_country_id ;
if($this->shipping_country_id > 0){
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
return $this->shipping_country_id;
}
public function getYContent()
{
if (is_null($this->ysession->get($this->yinstance))) {
return new Collection([]);
}
return $this->ysession->get($this->yinstance);
}
public function setShippingCountryWithPrice($shipping_country_id)
{
$this->shipping_country_id = $shipping_country_id;
$this->putShippingExtra('shipping_country_id', $shipping_country_id);
if($shipping_country_id > 0){
$shippingCountry = ShippingCountry::find($shipping_country_id);
$shipping = $shippingCountry->shipping;
if($this->weight()){
//blance by weigt
}
$price = $shipping->prices->first();
if($price){
$this->setShipping($price->price);
$this->shipping = floatval($price->price);
$this->putShippingExtra('shipping_price', $this->shipping);
}
}
}
public function getShippingCountry()
{
return $this->shipping_country_id;
}
/**
* @param null $decimals
@ -101,7 +144,23 @@ class Yard extends Cart
/**
* Get the total price of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$content = $this->getContent();
$total = $content->reduce(function ($total, CartItem $cartItem) {
return $total + ($cartItem->options->weight ? intval($cartItem->options->weight) : 0);
}, 0);
return $total;
}
/**
* Get the total price of the items in the cart.
*