@@ -521,6 +521,92 @@ public function test_get_calculated_value_of_a_condition()
521521 $ this ->assertEquals (25 , $ conditions ['Item Gift Pack 25.00 ' ]->getCalculatedValue ($ subTotal ),'First condition calculated value must be 5 ' );
522522 }
523523
524+ public function test_get_conditions_by_type ()
525+ {
526+ $ cartCondition1 = new CartCondition (array (
527+ 'name ' => 'SALE 5% ' ,
528+ 'type ' => 'sale ' ,
529+ 'target ' => 'subtotal ' ,
530+ 'value ' => '-5% ' ,
531+ ));
532+ $ cartCondition2 = new CartCondition (array (
533+ 'name ' => 'Item Gift Pack 25.00 ' ,
534+ 'type ' => 'promo ' ,
535+ 'target ' => 'subtotal ' ,
536+ 'value ' => '-25 ' ,
537+ ));
538+ $ cartCondition3 = new CartCondition (array (
539+ 'name ' => 'Item Less 8% ' ,
540+ 'type ' => 'promo ' ,
541+ 'target ' => 'subtotal ' ,
542+ 'value ' => '-8% ' ,
543+ ));
544+
545+ $ item = array (
546+ 'id ' => 456 ,
547+ 'name ' => 'Sample Item 1 ' ,
548+ 'price ' => 100 ,
549+ 'quantity ' => 1 ,
550+ 'attributes ' => array (),
551+ );
552+
553+ $ this ->cart ->add ($ item );
554+
555+ $ this ->cart ->condition ([$ cartCondition1 , $ cartCondition2 , $ cartCondition3 ]);
556+
557+ // now lets get all conditions added in the cart with the type "promo"
558+ $ promoConditions = $ this ->cart ->getConditionsByType ('promo ' );
559+
560+ $ this ->assertEquals (2 , $ promoConditions ->count (), "We should have 2 items as promo condition type. " );
561+ }
562+
563+ public function test_remove_conditions_by_type ()
564+ {
565+ // NOTE:
566+ // when add a new condition, the condition's name will be the key to be use
567+ // to access the condition. For some reasons, if the condition name contains
568+ // a "dot" on it ("."), for example adding a condition with name "SALE 35.00"
569+ // this will cause issues when removing this condition by name, this will not be removed
570+ // so when adding a condition, the condition name should not contain any "period" (.)
571+ // to avoid any issues removing it using remove method: removeCartCondition($conditionName);
572+
573+ $ cartCondition1 = new CartCondition (array (
574+ 'name ' => 'SALE 5% ' ,
575+ 'type ' => 'sale ' ,
576+ 'target ' => 'subtotal ' ,
577+ 'value ' => '-5% ' ,
578+ ));
579+ $ cartCondition2 = new CartCondition (array (
580+ 'name ' => 'Item Gift Pack 20 ' ,
581+ 'type ' => 'promo ' ,
582+ 'target ' => 'subtotal ' ,
583+ 'value ' => '-25 ' ,
584+ ));
585+ $ cartCondition3 = new CartCondition (array (
586+ 'name ' => 'Item Less 8% ' ,
587+ 'type ' => 'promo ' ,
588+ 'target ' => 'subtotal ' ,
589+ 'value ' => '-8% ' ,
590+ ));
591+
592+ $ item = array (
593+ 'id ' => 456 ,
594+ 'name ' => 'Sample Item 1 ' ,
595+ 'price ' => 100 ,
596+ 'quantity ' => 1 ,
597+ 'attributes ' => array (),
598+ );
599+
600+ $ this ->cart ->add ($ item );
601+
602+ $ this ->cart ->condition ([$ cartCondition1 , $ cartCondition2 , $ cartCondition3 ]);
603+
604+ // now lets remove all conditions added in the cart with the type "promo"
605+ $ this ->cart ->removeConditionsByType ('promo ' );
606+
607+ $ this ->assertEquals (1 , $ this ->cart ->getConditions ()->count (), "We should have 1 condition remaining as promo conditions type has been removed. " );
608+ }
609+
524610 protected function fillCart ()
525611 {
526612 $ items = array (
0 commit comments