Skip to content

Commit 4ccb1c2

Browse files
committed
Merge pull request #12 from Turaylon/master
Added functions for getting conditions and removing them by type
2 parents 13a8e2e + fec9626 commit 4ccb1c2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Darryldecode/Cart/Cart.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,30 @@ public function getCondition($conditionName)
304304
{
305305
return $this->getConditions()->get($conditionName);
306306
}
307+
308+
/**
309+
* Get all the condition filtered by Type
310+
* @param $type
311+
* @return CartConditionCollection
312+
*/
313+
public function getConditionsByType($type){
314+
return $this->getConditions()->filter(function(CartCondition $condition) use ($type){
315+
return $condition->getType() == $type;
316+
});
317+
}
318+
319+
320+
/**
321+
* Remove all the condition with the $type specified
322+
* @param $type
323+
* @return $this
324+
*/
325+
public function removeConditionsByType($type){
326+
return $this->getConditionsByType($type)->each(function($condition){
327+
$this->removeCartCondition($condition->getName());
328+
});
329+
}
330+
307331

308332
/**
309333
* removes a condition on a cart by condition name,
@@ -559,4 +583,4 @@ protected function itemHasConditions($item)
559583
{
560584
return count($item['conditions']) > 0;
561585
}
562-
}
586+
}

0 commit comments

Comments
 (0)