/*
* Important function - when e.g. user changes the address or change the items in cart, the payment method
* needs to be removed or revised, because user can get payment advantage when he orders 10 items but after changing
* cart to e.g. one item, payment cannot stay the same, the same happens with countries and region
*/
public static function removePayment($type = 0, $removeCoupon = 1)
{
if ($type == 0 || $type == 1) {
$session = Factory::getSession();
$session->set('guestpayment', false, 'phocaCart');
$session->set('guestpaymentparams', false, 'phocaCart');
if ($removeCoupon == 1) {
$session->set('guestcoupon', false, 'phocaCart');
}
$session->set('guestloyaltycardnumber', false, 'phocaCart');
}
if ($type == 0) {
$db = Factory::getDBO();
$user = $vendor = $ticket = $unit = $section = array();
$dUser = PhocacartUser::defineUser($user, $vendor, $ticket, $unit, $section);
$set = array();
$pos_payment_force = 0;
if (PhocacartPos::isPos()) {
$app = Factory::getApplication();
$paramsC = PhocacartUtils::getComponentParameters();
$pos_payment_force = $paramsC->get('pos_payment_force', 0);
if ((int) $pos_payment_force > 0) {
$pos_payment_force = PhocacartPayment::isPaymentMethodActive($pos_payment_force) === true ? (int) $pos_payment_force : 0;
}
if ($removeCoupon == 1 && $pos_payment_force == 0) {
$set[] = 'coupon = 0';
}
} else {
if ($removeCoupon == 1) {
$set[] = 'coupon = 0';
}
}
$set[] = 'payment = ' . (int) $pos_payment_force;
// Remove shipping params too
if ((int) $pos_payment_force == 0) {
$set[] = 'params_payment = \'\'';
}
$sets = implode(', ', $set);
$query = 'UPDATE #__phocacart_cart_multiple SET ' . $sets . ' WHERE user_id = ' . (int) $user->id . ' AND vendor_id = ' . (int) $vendor->id . ' AND ticket_id = ' . (int) $ticket->id . ' AND unit_id = ' . (int) $unit->id . ' AND section_id = ' . (int) $section->id;
$db->setQuery($query);
$db->execute();
}
return true;
}