/*
* used for shipping method rules
* used for payment method rules
*/
public static function storeCountries($countriesArray, $id, $table = 'shipping')
{
if ($table == 'shipping') {
$t = '#__phocacart_shipping_method_countries';
$c = 'shipping_id';
} else {
if ($table == 'payment') {
$t = '#__phocacart_payment_method_countries';
$c = 'payment_id';
} else {
if ($table == 'zone') {
$t = '#__phocacart_zone_countries';
$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($countriesArray)) {
$values = array();
$valuesString = '';
foreach ($countriesArray as $k => $v) {
//$values[] = ' ('.(int)$id.', '.(int)$v[0].')'; NEW FORM
// No multidimensional in J4
$values[] = ' (' . (int) $id . ', ' . (int) $v . ')';
}
if (!empty($values)) {
$valuesString = implode(',', $values);
$query = ' INSERT INTO ' . $t . ' (' . $c . ', country_id)' . ' VALUES ' . (string) $valuesString;
$db->setQuery($query);
$db->execute();
}
}
}
}