Added InstanceIdentifier

This commit is contained in:
Patrick Henninger
2018-12-21 17:11:18 +01:00
parent d947fe8a57
commit 706261dd4f
2 changed files with 27 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ use Gloudemans\Shoppingcart\Contracts\Buyable;
use Gloudemans\Shoppingcart\Exceptions\UnknownModelException; use Gloudemans\Shoppingcart\Exceptions\UnknownModelException;
use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException; use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException;
use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException; use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier;
class Cart class Cart
{ {
@@ -68,6 +69,12 @@ class Cart
{ {
$instance = $instance ?: self::DEFAULT_INSTANCE; $instance = $instance ?: self::DEFAULT_INSTANCE;
if ($instance instanceof InstanceIdentifier)
{
$this->discount = $instance->getInstanceGlobalDiscount();
$this->instance = $instance->getInstanceIdentifier();
}
$this->instance = sprintf('%s.%s', 'cart', $instance); $this->instance = sprintf('%s.%s', 'cart', $instance);
return $this; return $this;

View File

@@ -0,0 +1,20 @@
<?php
namespace Gloudemans\Shoppingcart\Contracts;
interface InstanceIdentifier
{
/**
* Get the unique identifier to load the Cart from
*
* @return int|string
*/
public function getInstanceIdentifier($options = null);
/**
* Get the unique identifier to load the Cart from
*
* @return int|string
*/
public function getInstanceGlobalDiscount($options = null);
}