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 9, 2024
1 parent 576afe6 commit 819b68c
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The extension streamlines the process of submitting relevant information to Goog
- **Automatic Updates**: Automatically updates the sitemap with any changes to your store’s content.
- **User-Friendly Setup**: Enjoy a seamless setup process through the OpenCart interface, designed for ease of use and efficiency.
- **Full Compatibility**: Fully compatible with OpenCart 3.x, ensuring smooth integration with your existing setup.
- **Multi-Store Support**: Customize product, category, manufacturer, and information pages to display per store, allowing for tailored sitemaps for each store within your multi-store setup.

---

Expand Down
2 changes: 1 addition & 1 deletion src/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ code package and also available on the project page: https://github.com/playfuls
<modification>
<name>Playful Sparkle - Google Sitemap</name>
<code>ps_google_sitemap</code>
<version>1.0.0</version>
<version>1.0.1</version>
<author>Playful Sparkle</author>
<link>https://github.com/playfulsparkle/oc3_google_sitemap.git</link>
</modification>
1 change: 1 addition & 0 deletions src/installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Key Features
* Automatic Updates: The sitemap updates automatically with any changes to your store’s content.
* User-Friendly Setup: Simple installation through the OpenCart interface for easy use.
* Full Compatibility: Works seamlessly with OpenCart 3.x.
* Multi-Store Support: Customize product, category, manufacturer, and information pages to display per store, allowing for tailored sitemaps for each store within your multi-store setup.

Installation Guide

Expand Down
58 changes: 49 additions & 9 deletions src/upload/admin/controller/extension/feed/ps_google_sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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_sitemap', $this->request->post);
$this->model_setting_setting->editSetting('feed_ps_google_sitemap', $this->request->post, $this->request->get['store_id']);

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

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


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 @@ -58,41 +66,41 @@ public function index()

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

$data['action'] = $this->url->link('extension/feed/ps_google_sitemap', 'user_token=' . $this->session->data['user_token'], true);
$data['action'] = $this->url->link('extension/feed/ps_google_sitemap', '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);

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

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

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

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

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

$this->load->model('localisation/language');
Expand All @@ -101,10 +109,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') . '&nbsp;' . $this->language->get('text_default'),
'href' => $this->url->link('extension/feed/ps_google_sitemap', '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_sitemap', '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_sitemap&language=' . $language['code'];
$data['data_feed_urls'][$language['language_id']] = rtrim($store_url, '/') . '/index.php?route=extension/feed/ps_google_sitemap&language=' . $language['code'];
}

$data['text_contact'] = sprintf($this->language->get('text_contact'), self::EXTENSION_EMAIL, self::EXTENSION_EMAIL, self::EXTENSION_DOC);
Expand All @@ -122,6 +158,10 @@ protected function validate()
$this->error['warning'] = $this->language->get('error_permission');
}

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

return !$this->error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Výrobce';
$_['entry_information'] = 'Informace';
$_['entry_data_feed_url'] = 'URL datového kanálu';
$_['entry_active_store'] = 'Aktivní obchod';

// Error
$_['error_permission'] = 'Upozornění: Nemáte oprávnění upravovat Google Sitemap feed!';
$_['error_store_id'] = 'Upozornění: Formulář neobsahuje identifikátor obchodu!';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Hersteller';
$_['entry_information'] = 'Information';
$_['entry_data_feed_url'] = 'Daten-Feed-Url';
$_['entry_active_store'] = 'Aktiver Shop';

// Error
$_['error_permission'] = 'Warnung: Sie haben keine Berechtigung, den Google Sitemap-Feed zu ändern!';
$_['error_store_id'] = 'Warnung: Das Formular enthält keine store_id!';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Manufacturer';
$_['entry_information'] = 'Information';
$_['entry_data_feed_url'] = 'Data Feed Url';
$_['entry_active_store'] = 'Active Store';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Google Sitemap feed!';
$_['error_store_id'] = 'Warning: Form does not contain store_id!';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Manufacturer';
$_['entry_information'] = 'Information';
$_['entry_data_feed_url'] = 'Data Feed Url';
$_['entry_active_store'] = 'Active Store';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify Google Sitemap feed!';
$_['error_store_id'] = 'Warning: Form does not contain store_id!';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Gyártó';
$_['entry_information'] = 'Információ';
$_['entry_data_feed_url'] = 'Adatfeed URL';
$_['entry_active_store'] = 'Aktív áruház';

// Error
$_['error_permission'] = 'Figyelmeztetés: Nincs jogosultsága a Google Oldaltérkép feed módosításához!';
$_['error_store_id'] = 'Figyelem: A űrlap nem tartalmazza a áruház azonosítóját!';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
$_['entry_manufacturer'] = 'Výrobca';
$_['entry_information'] = 'Informácie';
$_['entry_data_feed_url'] = 'URL dátového feedu';
$_['entry_active_store'] = 'Aktívny obchod';

// Error
$_['error_permission'] = 'Upozornenie: Nemáte oprávnenie na úpravu Google Sitemap feedu!';
$_['error_store_id'] = 'Upozornenie: Formulár neobsahuje identifikátor obchodu!';
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<div class="input-group">
<div class="input-group-addon">
{{ entry_active_store }}
<select name="store" id="input-store" class="form-select">
{% for store in stores %}&nbsp;&nbsp;
<option value="{{ store.href }}" {% if store.store_id == store_id %} selected{% endif %}>{{ store.name }}</option>
{% endfor %}
</select>
</div>
<button type="submit" form="form-feed" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
</div>
<h1>{{ heading_title }}</h1>
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
Expand Down Expand Up @@ -153,11 +163,16 @@
</div>
</div>

<input type="hidden" name="store_id" value="{{ store_id }}">
</form>
</div>
</div>
</div>
<script>
$('#input-store').on('change', function () {
window.location = $(this).val();
});
window.addEventListener("load", (event) => {
var btns = document.querySelectorAll('.btn-copy');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function index()
return;
}

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

$languages = $this->model_localisation_language->getLanguages();
Expand All @@ -41,7 +42,7 @@ public function index()

$this->config->set('config_language_id', $language_id);


$this->xml = new \XMLWriter();
$this->xml->openMemory();
$this->xml->startDocument('1.0', 'UTF-8');
Expand All @@ -51,7 +52,7 @@ public function index()
$this->xml->writeAttribute('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1');

#region Product
if ($this->config->get('feed_ps_google_sitemap_product')) {
if ($this->model_setting_setting->getSettingValue('feed_ps_google_sitemap_product', $this->config->get('config_store_id'))) {
$this->load->model('catalog/product');
$this->load->model('tool/image');

Expand Down Expand Up @@ -84,15 +85,15 @@ public function index()


#region Category
if ($this->config->get('feed_ps_google_sitemap_category')) {
if ($this->model_setting_setting->getSettingValue('feed_ps_google_sitemap_category', $this->config->get('config_store_id'))) {
$this->load->model('catalog/category');

$this->getCategories(0);
}
#endregion

#region Manufacturer
if ($this->config->get('feed_ps_google_sitemap_manufacturer')) {
if ($this->model_setting_setting->getSettingValue('feed_ps_google_sitemap_manufacturer', $this->config->get('config_store_id'))) {
$this->load->model('catalog/manufacturer');

$manufacturers = $this->model_catalog_manufacturer->getManufacturers();
Expand All @@ -106,7 +107,7 @@ public function index()
#endregion

#region Information
if ($this->config->get('feed_ps_google_sitemap_information')) {
if ($this->model_setting_setting->getSettingValue('feed_ps_google_sitemap_information', $this->config->get('config_store_id'))) {
$this->load->model('catalog/information');

$informations = $this->model_catalog_information->getInformations();
Expand Down

0 comments on commit 819b68c

Please sign in to comment.