mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-22 07:05:23 +00:00
Updated the search function, it now does a better search, including options, and it returns the rowid of the found item(s)
This commit is contained in:
@@ -214,12 +214,15 @@ class Cart {
|
||||
{
|
||||
foreach($this->getContent() as $item)
|
||||
{
|
||||
$rowId = $this->generateRowId($search['id'], $search['options']);
|
||||
$found = $item->search($search);
|
||||
|
||||
if($rowId === $item->rowid) return true;
|
||||
if($found)
|
||||
{
|
||||
$rows[] = $item->rowid;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return (empty($rows)) ? false : $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,4 +19,23 @@ class CartRowCollection extends Collection {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function search(Array $search)
|
||||
{
|
||||
foreach($search as $key => $value)
|
||||
{
|
||||
if($key === 'options')
|
||||
{
|
||||
$found = $this->{$key}->search($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$found = ($this->{$key} === $value) ? true : false;
|
||||
}
|
||||
|
||||
if( ! $found) return false;
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,4 +19,16 @@ class CartRowOptionsCollection extends Collection {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function search(Array $search)
|
||||
{
|
||||
foreach($search as $key => $value)
|
||||
{
|
||||
$found = ($this->{$key} === $value) ? true : false;
|
||||
|
||||
if( ! $found) return false;
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user