Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow L5.8 compatibility #572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
.DS_Store
.idea/
1 change: 1 addition & 0 deletions .php_cs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"7.3.3","version":"2.14.2","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/CartItemOptions.php":3665257661,"src\/CanBeBought.php":1005429606,"src\/Cart.php":3875270740,"src\/CartItem.php":3911352031,"src\/Contracts\/Buyable.php":1677486857,"src\/Exceptions\/InvalidRowIDException.php":2549804056,"src\/Exceptions\/CartAlreadyStoredException.php":3751240650,"src\/Exceptions\/UnknownModelException.php":3696588695,"src\/Facades\/Cart.php":3887252644,"src\/ShoppingcartServiceProvider.php":2316062521}}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
}
],
"require": {
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*",
"illuminate/session": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*",
"illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*"
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*",
"illuminate/session": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*",
"illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*"
},
"require-dev": {
"phpunit/phpunit": "~5.0 || ~6.0 || ~7.0",
Expand Down
18 changes: 13 additions & 5 deletions src/CanBeBought.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ public function getBuyableIdentifier($options = null)
*/
public function getBuyableDescription($options = null)
{
if(property_exists($this, 'name')) return $this->name;
if(property_exists($this, 'title')) return $this->title;
if(property_exists($this, 'description')) return $this->description;
if (property_exists($this, 'name')) {
return $this->name;
}
if (property_exists($this, 'title')) {
return $this->title;
}
if (property_exists($this, 'description')) {
return $this->description;
}

return null;
}
Expand All @@ -36,8 +42,10 @@ public function getBuyableDescription($options = null)
*/
public function getBuyablePrice($options = null)
{
if(property_exists($this, 'price')) return $this->price;
if (property_exists($this, 'price')) {
return $this->price;
}

return null;
}
}
}
67 changes: 35 additions & 32 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Cart

/**
* Instance of the event dispatcher.
*
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
private $events;
Expand All @@ -40,7 +40,7 @@ class Cart
/**
* Cart constructor.
*
* @param \Illuminate\Session\SessionManager $session
* @param \Illuminate\Session\SessionManager $session
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function __construct(SessionManager $session, Dispatcher $events)
Expand Down Expand Up @@ -79,11 +79,11 @@ public function currentInstance()
/**
* Add an item to the cart.
*
* @param mixed $id
* @param mixed $name
* @param mixed $id
* @param mixed $name
* @param int|float $qty
* @param float $price
* @param array $options
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
Expand All @@ -103,8 +103,8 @@ public function add($id, $name = null, $qty = null, $price = null, array $option
}

$content->put($cartItem->rowId, $cartItem);
$this->events->fire('cart.added', $cartItem);

$this->events->dispatch('cart.added', $cartItem);

$this->session->put($this->instance, $content);

Expand All @@ -115,7 +115,7 @@ public function add($id, $name = null, $qty = null, $price = null, array $option
* Update the cart item with the given rowId.
*
* @param string $rowId
* @param mixed $qty
* @param mixed $qty
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function update($rowId, $qty)
Expand Down Expand Up @@ -148,7 +148,7 @@ public function update($rowId, $qty)
$content->put($cartItem->rowId, $cartItem);
}

$this->events->fire('cart.updated', $cartItem);
$this->events->dispatch('cart.updated', $cartItem);

$this->session->put($this->instance, $content);

Expand All @@ -169,7 +169,7 @@ public function remove($rowId)

$content->pull($cartItem->rowId);

$this->events->fire('cart.removed', $cartItem);
$this->events->dispatch('cart.removed', $cartItem);

$this->session->put($this->instance, $content);
}
Expand All @@ -184,8 +184,9 @@ public function get($rowId)
{
$content = $this->getContent();

if ( ! $content->has($rowId))
if (!$content->has($rowId)) {
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
}

return $content->get($rowId);
}
Expand Down Expand Up @@ -229,7 +230,7 @@ public function count()
/**
* Get the total price of the items in the cart.
*
* @param int $decimals
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
Expand All @@ -248,7 +249,7 @@ public function total($decimals = null, $decimalPoint = null, $thousandSeperator
/**
* Get the total tax of the items in the cart.
*
* @param int $decimals
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return float
Expand All @@ -267,7 +268,7 @@ public function tax($decimals = null, $decimalPoint = null, $thousandSeperator =
/**
* Get the subtotal (total - tax) of the items in the cart.
*
* @param int $decimals
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return float
Expand Down Expand Up @@ -300,12 +301,12 @@ public function search(Closure $search)
* Associate the cart item with the given rowId with the given model.
*
* @param string $rowId
* @param mixed $model
* @param mixed $model
* @return void
*/
public function associate($rowId, $model)
{
if(is_string($model) && ! class_exists($model)) {
if (is_string($model) && !class_exists($model)) {
throw new UnknownModelException("The supplied model {$model} does not exist.");
}

Expand All @@ -323,7 +324,7 @@ public function associate($rowId, $model)
/**
* Set the tax rate for the cart item with the given rowId.
*
* @param string $rowId
* @param string $rowId
* @param int|float $taxRate
* @return void
*/
Expand Down Expand Up @@ -360,7 +361,7 @@ public function store($identifier)
'content' => serialize($content)
]);

$this->events->fire('cart.stored');
$this->events->dispatch('cart.stored');
}

/**
Expand All @@ -371,7 +372,7 @@ public function store($identifier)
*/
public function restore($identifier)
{
if( ! $this->storedCartWithIdentifierExists($identifier)) {
if (!$this->storedCartWithIdentifierExists($identifier)) {
return;
}

Expand All @@ -390,7 +391,7 @@ public function restore($identifier)
$content->put($cartItem->rowId, $cartItem);
}

$this->events->fire('cart.restored');
$this->events->dispatch('cart.restored');

$this->session->put($this->instance, $content);

Expand All @@ -408,15 +409,15 @@ public function restore($identifier)
*/
public function __get($attribute)
{
if($attribute === 'total') {
if ($attribute === 'total') {
return $this->total();
}

if($attribute === 'tax') {
if ($attribute === 'tax') {
return $this->tax();
}

if($attribute === 'subtotal') {
if ($attribute === 'subtotal') {
return $this->subtotal();
}

Expand All @@ -440,11 +441,11 @@ protected function getContent()
/**
* Create a new CartItem from the supplied attributes.
*
* @param mixed $id
* @param mixed $name
* @param mixed $id
* @param mixed $name
* @param int|float $qty
* @param float $price
* @param array $options
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
*/
private function createCartItem($id, $name, $qty, $price, array $options)
Expand Down Expand Up @@ -474,7 +475,9 @@ private function createCartItem($id, $name, $qty, $price, array $options)
*/
private function isMulti($item)
{
if ( ! is_array($item)) return false;
if (!is_array($item)) {
return false;
}

return is_array(head($item)) || head($item) instanceof Buyable;
}
Expand Down Expand Up @@ -533,13 +536,13 @@ private function getConnectionName()
*/
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
{
if(is_null($decimals)){
if (is_null($decimals)) {
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
}
if(is_null($decimalPoint)){
if (is_null($decimalPoint)) {
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}
if(is_null($thousandSeperator)){
if (is_null($thousandSeperator)) {
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}

Expand Down
Loading