Skip to content

Commit

Permalink
multi-store support
Browse files Browse the repository at this point in the history
  • Loading branch information
zsoltoroszlany82 committed Nov 11, 2024
1 parent 30f6c34 commit df01b28
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 116 deletions.
135 changes: 111 additions & 24 deletions src/upload/admin/controller/extension/feed/ps_google_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function index()
$this->load->model('setting/setting');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('feed_ps_google_base', $this->request->post);
$this->model_setting_setting->editSetting('feed_ps_google_base', $this->request->post, $this->request->get['store_id']);

$this->session->data['success'] = $this->language->get('text_success');

Expand All @@ -55,6 +55,31 @@ public function index()
$data['error_warning'] = '';
}

if (isset($this->error['input_tax_country'])) {
$data['error_input_tax_country'] = $this->error['input_tax_country'];
} else {
$data['error_input_tax_country'] = array();
}

if (isset($this->error['input_tax_region'])) {
$data['error_input_tax_region'] = $this->error['input_tax_region'];
} else {
$data['error_input_tax_region'] = array();
}

if (isset($this->error['input_tax_rate_id'])) {
$data['error_input_tax_rate_id'] = $this->error['input_tax_rate_id'];
} else {
$data['error_input_tax_rate_id'] = array();
}

if (isset($this->request->get['store_id'])) {
$store_id = (int) $this->request->get['store_id'];
} else {
$store_id = 0;
}


$data['breadcrumbs'] = array();

$data['breadcrumbs'][] = array(
Expand All @@ -69,51 +94,55 @@ public function index()

$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'], true)
'href' => $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store_id, true)
);

$data['action'] = $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'], true);
$data['action'] = $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store_id, true);

$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true);

$data['user_token'] = $this->session->data['user_token'];

$data['data_feed'] = HTTP_CATALOG . 'index.php?route=extension/feed/ps_google_base';

if (isset($this->request->post['feed_ps_google_base_status'])) {
$data['feed_ps_google_base_status'] = $this->request->post['feed_ps_google_base_status'];
$data['feed_ps_google_base_status'] = (bool) $this->request->post['feed_ps_google_base_status'];
} else {
$data['feed_ps_google_base_status'] = $this->config->get('feed_ps_google_base_status');
$data['feed_ps_google_base_status'] = (bool) $this->model_setting_setting->getSettingValue('feed_ps_google_base_status', $store_id);
}

if (isset($this->request->post['feed_ps_google_base_skip_out_of_stock'])) {
$data['feed_ps_google_base_skip_out_of_stock'] = $this->request->post['feed_ps_google_base_skip_out_of_stock'];
$data['feed_ps_google_base_skip_out_of_stock'] = (bool) $this->request->post['feed_ps_google_base_skip_out_of_stock'];
} else {
$data['feed_ps_google_base_skip_out_of_stock'] = $this->config->get('feed_ps_google_base_skip_out_of_stock');
$data['feed_ps_google_base_skip_out_of_stock'] = (bool) $this->model_setting_setting->getSettingValue('feed_ps_google_base_skip_out_of_stock', $store_id);
}

if (isset($this->request->post['feed_ps_google_base_tax'])) {
$data['feed_ps_google_base_tax'] = $this->request->post['feed_ps_google_base_tax'];
if (isset($this->request->post['feed_ps_google_base_login'])) {
$data['feed_ps_google_base_login'] = $this->request->post['feed_ps_google_base_login'];
} else {
$data['feed_ps_google_base_tax'] = $this->config->get('feed_ps_google_base_tax');
$data['feed_ps_google_base_login'] = $this->model_setting_setting->getSettingValue('feed_ps_google_base_login', $store_id);
}

if (isset($this->request->post['feed_ps_google_base_taxes'])) {
$data['feed_ps_google_base_taxes'] = (array) $this->request->post['feed_ps_google_base_taxes'];
if (isset($this->request->post['feed_ps_google_base_password'])) {
$data['feed_ps_google_base_password'] = $this->request->post['feed_ps_google_base_password'];
} else {
$data['feed_ps_google_base_taxes'] = (array) $this->config->get('feed_ps_google_base_taxes');
$data['feed_ps_google_base_password'] = $this->model_setting_setting->getSettingValue('feed_ps_google_base_password', $store_id);
}

if (isset($this->request->post['feed_ps_google_base_login'])) {
$data['feed_ps_google_base_login'] = $this->request->post['feed_ps_google_base_login'];
if (isset($this->request->post['feed_ps_google_base_tax'])) {
$data['feed_ps_google_base_tax'] = (bool) $this->request->post['feed_ps_google_base_tax'];
} else {
$data['feed_ps_google_base_login'] = $this->config->get('feed_ps_google_base_login');
$data['feed_ps_google_base_tax'] = (bool) $this->model_setting_setting->getSettingValue('feed_ps_google_base_tax', $store_id);
}

if (isset($this->request->post['feed_ps_google_base_password'])) {
$data['feed_ps_google_base_password'] = $this->request->post['feed_ps_google_base_password'];
if (isset($this->request->post['feed_ps_google_base_taxes'])) {
$data['feed_ps_google_base_taxes'] = $this->request->post['feed_ps_google_base_taxes'];
} else {
$data['feed_ps_google_base_password'] = $this->config->get('feed_ps_google_base_password');
$base_taxes = $this->model_setting_setting->getSettingValue('feed_ps_google_base_taxes', $store_id);

if (!is_array($base_taxes)) {
$base_taxes = (array) json_decode((string) $base_taxes, true);
}

$data['feed_ps_google_base_taxes'] = $base_taxes;
}

$this->load->model('localisation/language');
Expand All @@ -122,10 +151,38 @@ public function index()

$data['languages'] = $languages;

$data['store_id'] = $store_id;

$data['stores'] = [];

$data['stores'][] = [
'store_id' => 0,
'name' => $this->config->get('config_name') . ' ' . $this->language->get('text_default'),
'href' => $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'] . '&store_id=0'),
];

$this->load->model('setting/store');

$stores = $this->model_setting_store->getStores();

$store_url = HTTP_CATALOG;

foreach ($stores as $store) {
$data['stores'][] = [
'store_id' => $store['store_id'],
'name' => $store['name'],
'href' => $this->url->link('extension/feed/ps_google_base', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id']),
];

if ((int) $store['store_id'] === $store_id) {
$store_url = $store['url'];
}
}

$data['data_feed_urls'] = [];

foreach ($languages as $language) {
$data['data_feed_urls'][$language['language_id']] = HTTP_CATALOG . 'index.php?route=extension/feed/ps_google_base&language=' . $language['code'];
$data['data_feed_urls'][$language['language_id']] = rtrim($store_url, '/') . '/index.php?route=extension/feed/ps_google_base&language=' . $language['code'];
}

$this->load->model('localisation/tax_rate');
Expand Down Expand Up @@ -154,6 +211,29 @@ protected function validate()
$this->error['warning'] = $this->language->get('error_permission');
}

if (!$this->error && (!isset($this->request->post['store_id']) || !isset($this->request->get['store_id']))) {
$this->error['warning'] = $this->language->get('error_store_id');
}

if (!$this->error) {
if (isset($this->request->post['feed_ps_google_base_tax'], $this->request->post['feed_ps_google_base_taxes'])) {
foreach ($this->request->post['feed_ps_google_base_taxes'] as $row_id => $data) {
if (utf8_strlen(trim($data['country'])) === 0 || utf8_strlen(trim($data['country_id'])) === 0) {
$this->error['input_tax_country'][$row_id] = $this->language->get('error_tax_country');
}

if (utf8_strlen(trim($data['region'])) === 0) {
$this->error['input_tax_region'][$row_id] = $this->language->get('error_tax_region');
}

if (utf8_strlen(trim($data['tax_rate_id'])) === 0) {
$this->error['input_tax_rate_id'][$row_id] = $this->language->get('error_tax_rate_id');
}
}
}
}


return !$this->error;
}

Expand Down Expand Up @@ -287,6 +367,12 @@ public function category()
{
$this->load->language('extension/feed/ps_google_base');

if (isset($this->request->get['store_id'])) {
$store_id = (int) $this->request->get['store_id'];
} else {
$store_id = 0;
}

if (isset($this->request->get['page'])) {
$page = (int) $this->request->get['page'];
} else {
Expand All @@ -296,6 +382,7 @@ public function category()
$limit = 10;

$filter_data = array(
'store_id' => $store_id,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
Expand All @@ -321,7 +408,7 @@ public function category()
$pagination->total = $category_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $this->url->link('extension/feed/ps_google_base/category', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true);
$pagination->url = $this->url->link('extension/feed/ps_google_base/category', 'store_id= ' . $store_id . '&user_token=' . $this->session->data['user_token'] . '&page={page}', true);

$data['pagination'] = $pagination->render();

Expand Down Expand Up @@ -381,7 +468,7 @@ public function removeCategory()
} else {
$this->load->model('extension/feed/ps_google_base');

$this->model_extension_feed_ps_google_base->deleteCategory($this->request->post['category_id']);
$this->model_extension_feed_ps_google_base->deleteCategory($this->request->post);

$json['success'] = $this->language->get('text_success');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Kraj';
$_['entry_tax_rate'] = 'Sazba daně';
$_['entry_tax_ship'] = 'Doprava daně';
$_['entry_active_store'] = 'Aktivní obchod';

// Error
$_['error_permission'] = 'Upozornění: Nemáte oprávnění upravovat Google Base feed!';
$_['error_store_id'] = 'Upozornění: Formulář neobsahuje identifikátor obchodu!';
$_['error_currency'] = 'Upozornění: Vyberte měnu ze seznamu';
$_['error_upload'] = 'Soubor se nepodařilo nahrát!';
$_['error_filetype'] = 'Neplatný typ souboru!';
$_['error_currency'] = 'Upozornění: Vyberte měnu ze seznamu';
$_['error_tax_country'] = 'Prosím, vyberte zemi pro daň.';
$_['error_tax_region'] = 'Pole pro daňový kraj nesmí být prázdné.';
$_['error_tax_rate_id'] = 'Prosím, vyberte sazbu daně pro daň.';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Region';
$_['entry_tax_rate'] = 'Steuersatz';
$_['entry_tax_ship'] = 'Versandsteuer';
$_['entry_active_store'] = 'Aktiver Shop';

// Error
$_['error_permission'] = 'Warnung: Sie haben keine Berechtigung, den Google Base Feed zu ändern!';
$_['error_store_id'] = 'Warnung: Das Formular enthält keine store_id!';
$_['error_currency'] = 'Warnung: Wählen Sie eine Währung aus der Liste aus';
$_['error_upload'] = 'Die Datei konnte nicht hochgeladen werden!';
$_['error_filetype'] = 'Ungültiger Dateityp!';
$_['error_currency'] = 'Warnung: Wählen Sie eine Währung aus der Liste aus';
$_['error_tax_country'] = 'Bitte wählen Sie ein Land für die Steuer aus.';
$_['error_tax_region'] = 'Das Feld für die Steuerregion darf nicht leer gelassen werden.';
$_['error_tax_rate_id'] = 'Bitte wählen Sie einen Steuersatz für die Steuer aus.';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Region';
$_['entry_tax_rate'] = 'Tax Rate';
$_['entry_tax_ship'] = 'Shipping tax';
$_['entry_active_store'] = 'Active Store';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Google Base feed!';
$_['error_store_id'] = 'Warning: Form does not contain store_id!';
$_['error_currency'] = 'Warning: Select a currency from the list';
$_['error_upload'] = 'File could not be uploaded!';
$_['error_filetype'] = 'Invalid file type!';
$_['error_currency'] = 'Warning: Select a currency from the list';
$_['error_tax_country'] = 'Please select country for the tax.';
$_['error_tax_region'] = 'The tax region field cannot be left empty.';
$_['error_tax_rate_id'] = 'Please select tax rate for the tax';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Region';
$_['entry_tax_rate'] = 'Tax Rate';
$_['entry_tax_ship'] = 'Shipping tax';
$_['entry_active_store'] = 'Active Store';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Google Base feed!';
$_['error_store_id'] = 'Warning: Form does not contain store_id!';
$_['error_currency'] = 'Warning: Select a currency from the list';
$_['error_upload'] = 'File could not be uploaded!';
$_['error_filetype'] = 'Invalid file type!';
$_['error_currency'] = 'Warning: Select a currency from the list';
$_['error_tax_country'] = 'Please select country for the tax.';
$_['error_tax_region'] = 'The tax region field cannot be left empty.';
$_['error_tax_rate_id'] = 'Please select tax rate for the tax';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Región';
$_['entry_tax_rate'] = 'Tasa de Impuesto';
$_['entry_tax_ship'] = 'Impuesto de Envío';
$_['entry_active_store'] = 'Tienda activa';

// Error
$_['error_permission'] = 'Advertencia: ¡No tienes permiso para modificar el feed de Google Base!';
$_['error_store_id'] = 'Advertencia: ¡El formulario no contiene store_id!';
$_['error_currency'] = 'Advertencia: Selecciona una moneda de la lista';
$_['error_upload'] = '¡El archivo no se pudo subir!';
$_['error_filetype'] = '¡Tipo de archivo no válido!';
$_['error_currency'] = 'Advertencia: Selecciona una moneda de la lista';
$_['error_tax_country'] = 'Por favor, selecciona un país para el impuesto.';
$_['error_tax_region'] = 'El campo de región del impuesto no puede quedar vacío.';
$_['error_tax_rate_id'] = 'Por favor, selecciona una tasa de impuesto para el impuesto';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Région';
$_['entry_tax_rate'] = 'Taux de taxe';
$_['entry_tax_ship'] = 'Taxe sur l\'expédition';
$_['entry_active_store'] = 'Magasin actif';

// Error
$_['error_permission'] = 'Avertissement : Vous n\'avez pas l\'autorisation de modifier le flux Google Base !';
$_['error_store_id'] = 'Avertissement : Le formulaire ne contient pas d\'ID de magasin !';
$_['error_currency'] = 'Avertissement : Sélectionnez une devise dans la liste';
$_['error_upload'] = 'Le fichier n\'a pas pu être téléchargé !';
$_['error_filetype'] = 'Type de fichier invalide !';
$_['error_currency'] = 'Avertissement : Sélectionnez une devise dans la liste';
$_['error_tax_country'] = 'Veuillez sélectionner un pays pour la taxe.';
$_['error_tax_region'] = 'Le champ de région fiscale ne peut pas être laissé vide.';
$_['error_tax_rate_id'] = 'Veuillez sélectionner un taux de taxe pour la taxe';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Régió';
$_['entry_tax_rate'] = 'Adókulcs';
$_['entry_tax_ship'] = 'Szállítási adó';
$_['entry_active_store'] = 'Aktív áruház';

// Error
$_['error_permission'] = 'Figyelmeztetés: Nincs jogosultsága a Google Base feed módosításához!';
$_['error_store_id'] = 'Figyelmeztetés: A űrlap nem tartalmazza a áruház azonosítóját!';
$_['error_currency'] = 'Figyelmeztetés: Válasszon pénznemet a listából';
$_['error_upload'] = 'A fájl feltöltése nem sikerült!';
$_['error_filetype'] = 'Érvénytelen fájltípus!';
$_['error_currency'] = 'Figyelmeztetés: Válasszon pénznemet a listából';
$_['error_tax_country'] = 'Kérem, válassza ki az adó országát.';
$_['error_tax_region'] = 'Az adóregionális mező nem maradhat üresen.';
$_['error_tax_rate_id'] = 'Kérem, válassza ki az adókulcsot az adóhoz.';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
$_['entry_region'] = 'Regione';
$_['entry_tax_rate'] = 'Aliquota Fiscale';
$_['entry_tax_ship'] = 'Tassa di spedizione';
$_['entry_active_store'] = 'Negozio attivo';

// Error
$_['error_permission'] = 'Attenzione: Non hai permesso di modificare il feed di Google Base!';
$_['error_store_id'] = 'Attenzione: Il modulo non contiene store_id!';
$_['error_currency'] = 'Attenzione: Seleziona una valuta dalla lista';
$_['error_upload'] = 'Impossibile caricare il file!';
$_['error_filetype'] = 'Tipo di file non valido!';
$_['error_currency'] = 'Attenzione: Seleziona una valuta dalla lista';
$_['error_tax_country'] = 'Seleziona il paese per la tassa.';
$_['error_tax_region'] = 'Il campo regione fiscale non può essere lasciato vuoto.';
$_['error_tax_rate_id'] = 'Seleziona l\'aliquota fiscale per la tassa';
Loading

0 comments on commit df01b28

Please sign in to comment.