Back to PhocacartShipping class

Method removeShipping

public static
removeShipping
(mixed $type = 0)

Method removeShipping - Source code

/*
 * Important function - when e.g. user changes the address or change the items in cart, the shipping method
 * needs to be removed, because user can get shipping advantage when he orders 10 items but after changing
 * cart to e.g. one item, shipping cannot stay the same, the same happens with countries and region
 */
public static function removeShipping($type = 0)
{
    if ($type == 0 || $type == 1) {
        $session = Factory::getSession();
        $session->set('guestshipping', false, 'phocaCart');
        $session->set('guestshippingparams', false, 'phocaCart');
    }
    if ($type == 0) {
        $db = Factory::getDBO();
        $user = array();
        $vendor = array();
        $ticket = array();
        $unit = array();
        $section = array();
        $dUser = PhocacartUser::defineUser($user, $vendor, $ticket, $unit, $section);
        $pos_shipping_force = 0;
        if (PhocacartPos::isPos()) {
            $app = Factory::getApplication();
            $paramsC = PhocacartUtils::getComponentParameters();
            $pos_shipping_force = $paramsC->get('pos_shipping_force', 0);
            if ((int) $pos_shipping_force > 0) {
                $pos_shipping_force = PhocacartShipping::isShippingMethodActive($pos_shipping_force) === true ? (int) $pos_shipping_force : 0;
            }
        }
        $query = 'UPDATE #__phocacart_cart_multiple SET shipping = ' . (int) $pos_shipping_force;
        // Remove shipping params too
        if ((int) $pos_shipping_force == 0) {
            $query .= ', params_shipping = \'\'';
        }
        $query .= ' 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;
}