Back to PhocacartRegion class

Method storeRegions

public static
storeRegions
(mixed $regionsArray, mixed $id, mixed $table = 'shipping')

Method storeRegions - Source code

public static function storeRegions($regionsArray, $id, $table = 'shipping')
{
    if ($table == 'shipping') {
        $t = '#__phocacart_shipping_method_regions';
        $c = 'shipping_id';
    } else {
        if ($table == 'payment') {
            $t = '#__phocacart_payment_method_regions';
            $c = 'payment_id';
        } else {
            if ($table == 'zone') {
                $t = '#__phocacart_zone_regions';
                $c = 'zone_id';
            }
        }
    }
    if ((int) $id > 0) {
        $db = Factory::getDBO();
        $query = ' DELETE ' . ' FROM ' . $t . ' WHERE ' . $c . ' = ' . (int) $id;
        $db->setQuery($query);
        $db->execute();
        if (!empty($regionsArray)) {
            $values = array();
            $valuesString = '';
            foreach ($regionsArray as $k => $v) {
                //$values[] = ' ('.(int)$id.', '.(int)$v[0].')';
                // No multidimensional in J4
                $values[] = ' (' . (int) $id . ', ' . (int) $v . ')';
            }
            if (!empty($values)) {
                $valuesString = implode(',', $values);
                $query = ' INSERT INTO ' . $t . ' (' . $c . ', region_id)' . ' VALUES ' . (string) $valuesString;
                $db->setQuery($query);
                $db->execute();
            }
        }
    }
}