mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 15:41:24 +00:00
Updated readme and phpdocs
This commit is contained in:
13
README.md
13
README.md
@@ -159,6 +159,19 @@ Cart::total();
|
|||||||
Cart::count(false); // Total rows
|
Cart::count(false); // Total rows
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Cart::search()**
|
||||||
|
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* Search if the cart has a item
|
||||||
|
*
|
||||||
|
* @param Array $search An array with the item ID and optional options
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
|
||||||
|
Cart::search(array('id' => 1, 'options' => array('size' => 'L')));
|
||||||
|
```
|
||||||
|
|
||||||
## Collections
|
## Collections
|
||||||
|
|
||||||
As you might have seen, the `Cart::content()` and `Cart::get()` methods both return a Collection, a `CartCollection` and a `CartRowCollection`.
|
As you might have seen, the `Cart::content()` and `Cart::get()` methods both return a Collection, a `CartCollection` and a `CartRowCollection`.
|
||||||
|
|||||||
@@ -204,6 +204,24 @@ class Cart {
|
|||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search if the cart has a item
|
||||||
|
*
|
||||||
|
* @param Array $search An array with the item ID and optional options
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function search($search)
|
||||||
|
{
|
||||||
|
foreach($this->getContent() as $item)
|
||||||
|
{
|
||||||
|
$rowId = $this->generateRowId($search['id'], $search['options']);
|
||||||
|
|
||||||
|
if($rowId === $item->rowid) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a unique id for the new row
|
* Generate a unique id for the new row
|
||||||
*
|
*
|
||||||
@@ -211,7 +229,7 @@ class Cart {
|
|||||||
* @param Array $options Array of additional options, such as 'size' or 'color'
|
* @param Array $options Array of additional options, such as 'size' or 'color'
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function generateRowId($id, $options)
|
protected function generateRowId($id, $options)
|
||||||
{
|
{
|
||||||
return md5($id . serialize($options));
|
return md5($id . serialize($options));
|
||||||
}
|
}
|
||||||
@@ -344,16 +362,4 @@ class Cart {
|
|||||||
return $this->updateRow($rowId, $attributes);
|
return $this->updateRow($rowId, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function search($search)
|
|
||||||
{
|
|
||||||
foreach($this->getContent() as $item)
|
|
||||||
{
|
|
||||||
$rowId = $this->generateRowId($search['id'], $search['options']);
|
|
||||||
|
|
||||||
if($rowId === $item->rowid) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user