I’m using Laravel 8 and using Darryldecode Package
Reference : https://packagist.org/packages/darryldecode/cart
to apply discount i’m using this method
$couponExists=Coupon::where('code',$couponcode)->first();
if($couponExists)
{
if($couponExists->type=='fixed')
{
$condition2 = new DarryldecodeCartCartCondition(array(
'name' => 'FIXED',
'type' => $couponcode,
'target' => 'total',
'value' => $couponExists->value,
'order' => 1,
'description' => 'Fixed coupon',
'more_data' => 'Fixed coupon'
));
Cart::condition($condition2);
if (auth()->guard('web')->check()) {
$userID = auth()->guard('web')->id();
Cart::session($userID)->condition($condition2);
}
else
{
Cart::session('token')->condition($condition2);
}
}
else
{
$condition = new DarryldecodeCartCartCondition(array(
'name' => 'PERCENT',
'type' => $couponcode,
'target' => 'total',
'value' => '15%',
'attributes' => array(
'description' => 'Percentage coupon',
'more_data' => 'Percentage coupon'
)
));
if (auth()->guard('web')->check()) {
$userID = auth()->guard('web')->id();
Cart::session($userID)->condition($condition);
}
else
{
Cart::session('token')->condition($condition);
}
}
}
and it is applied also but now i’m trying to remove that condition
$cartConditions = Cart::getConditions();
if(count($cartConditions) > 0)
{
foreach($cartConditions as $condition)
{
$targetName=$condition->getName();
$targetConditions=$condition->getTarget();
$targetType=$condition->getType();
Cart::removeCartCondition($targetName);
Cart::removeConditionsByType($targetType); }
Cart::clearCartConditions();
}
but the discount i applied is not getting removed through this code.
Any solution to fix this issue.
Thanks