Skip to content

Commit

Permalink
Misc fixes (#124)
Browse files Browse the repository at this point in the history
* fixing some type hinting

* updating read me a bit

* allow user to add via item id as well as item model

* showing more of the bindings availalble

* adding the exceptiong

* removing scrutinzier,

* hotfix

* fixing and cleaning up migrations

* idea should be in global gitignore

* CS

* more cs

* adding facade back in

* fixing bad code
  • Loading branch information
lukepolo committed Apr 30, 2016
1 parent a80ee64 commit ad4e5a7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/vendor
composer.lock
.idea
composer.lock
4 changes: 2 additions & 2 deletions src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public function getModel()

$itemModel->with($this->itemModelRelations)->find($this->id);

if(empty($itemModel)) {
throw new ModelNotFound('Could not find the item model for '.$this->id);
if (empty($itemModel)) {
throw new ModelNotFound('Could not find the item model for ' . $this->id);
}

return $itemModel;
Expand Down
4 changes: 2 additions & 2 deletions src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function add(
}

if (empty($itemModel)) {
throw new ModelNotFound('Could not find the item '.$itemID);
throw new ModelNotFound('Could not find the item ' . $itemID);
}

$bindings = config('laracart.item_model_bindings');
Expand Down Expand Up @@ -770,7 +770,7 @@ private function getItemModelOptions(Model $itemModel, $options = [])
* @param Model $itemModel
* @param $attr
* @param null $defaultValue
*
*
* @return Model|null
*/
private function getFromModel(Model $itemModel, $attr, $defaultValue = null)
Expand Down
19 changes: 8 additions & 11 deletions src/LaraCartServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@ class LaraCartServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->publishes(
[
__DIR__ . '/config/laracart.php' => config_path('laracart.php'),
]
);
$this->publishes([
__DIR__ . '/config/laracart.php' => config_path('laracart.php'),
]);

$this->mergeConfigFrom(
__DIR__ . '/config/laracart.php',
'laracart'
);

/*
* Publish migration if not published yet
*/
if (!$this->migrationHasAlreadyBeenPublished()) {
$timestamp = date('Y_m_d_His', time());
$this->publishes([
__DIR__ . '/../resources/migrations/add_cart_session_id_to_users_table.php.stub' => database_path('migrations/' . $timestamp . '_add_cart_session_id_to_users_table.php'),
__DIR__ . '/database/migrations/add_cart_session_id_to_users_table.php.stub' => database_path('migrations/' . date('Y_m_d_His') . '_add_cart_session_id_to_users_table.php'),
], 'migrations');
}
}
Expand Down Expand Up @@ -68,11 +62,14 @@ function () {
}

/**
* Checks to see if the migration has already been published
*
* @return bool
*/
protected function migrationHasAlreadyBeenPublished()
{
$files = glob(database_path('/migrations/*_add_cart_session_id_to_users_table.php'));
$files = glob(database_path('migrations/*_add_cart_session_id_to_users_table.php'));

return count($files) > 0;
}
}
13 changes: 6 additions & 7 deletions src/Traits/CartOptionsMagicMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ public function __set($option, $value)
throw new InvalidPrice('The price must be a valid number');
}
break;
// Bad code , will need to look at later
// case CartItem::ITEM_TAX:
// if (!is_numeric($value) || $value > 1) {
// throw new InvalidTaxableValue('The tax must be a float less than 1');
// }
// break;
case CartItem::ITEM_TAX:
if (!empty($value) && (!is_numeric($value) || $value > 1)) {
throw new InvalidTaxableValue('The tax must be a float less than 1');
}
break;
case CartItem::ITEM_TAXABLE:
if(!is_bool($value)) {
if (!is_bool($value)) {
throw new InvalidTaxableValue('The taxable option must be a boolean');
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class AddCartSessionIdToUsersTable extends Migration
});
}
}
}
}

0 comments on commit ad4e5a7

Please sign in to comment.