@@ -382,15 +382,38 @@ public function removeItemCondition($itemId, $conditionName)
382
382
383
383
$ tempConditionsHolder = $ item ['conditions ' ];
384
384
385
- foreach ($ tempConditionsHolder as $ k => $ condition )
385
+ // if the item's conditions is in array format
386
+ // we will iterate through all of it and check if the name matches
387
+ // to the given name the user wants to remove, if so, remove it
388
+ if ( is_array ($ tempConditionsHolder ) )
386
389
{
387
- if ( $ condition -> getName () == $ conditionName )
390
+ foreach ( $ tempConditionsHolder as $ k => $ condition )
388
391
{
389
- unset($ tempConditionsHolder [$ k ]);
392
+ if ( $ condition ->getName () == $ conditionName )
393
+ {
394
+ unset($ tempConditionsHolder [$ k ]);
395
+ }
390
396
}
397
+
398
+ $ item ['conditions ' ] = $ tempConditionsHolder ;
391
399
}
392
400
393
- $ item ['conditions ' ] = $ tempConditionsHolder ;
401
+ // if the item condition is not an array, we will check if it is
402
+ // an instance of a Condition, if so, we will check if the name matches
403
+ // on the given condition name the user wants to remove, if so,
404
+ // lets just make $item['conditions'] an empty array as there's just 1 condition on it anyway
405
+ else
406
+ {
407
+ $ conditionInstance = "Darryldecode \\Cart \\CartCondition " ;
408
+
409
+ if ($ item ['conditions ' ] instanceof $ conditionInstance )
410
+ {
411
+ if ($ tempConditionsHolder ->getName () == $ conditionName )
412
+ {
413
+ $ item ['conditions ' ] = array ();
414
+ }
415
+ }
416
+ }
394
417
}
395
418
396
419
$ this ->update ($ itemId , array (
@@ -591,6 +614,17 @@ protected function saveConditions($conditions)
591
614
*/
592
615
protected function itemHasConditions ($ item )
593
616
{
594
- return count ($ item ['conditions ' ]) > 0 ;
617
+ if ( ! isset ($ item ['conditions ' ]) ) return false ;
618
+
619
+ if ( is_array ($ item ['conditions ' ]) )
620
+ {
621
+ return count ($ item ['conditions ' ]) > 0 ;
622
+ }
623
+
624
+ $ conditionInstance = "Darryldecode \\Cart \\CartCondition " ;
625
+
626
+ if ( $ item ['conditions ' ] instanceof $ conditionInstance ) return true ;
627
+
628
+ return false ;
595
629
}
596
630
}
0 commit comments