I need add to my module selectable stores. This module I want to use for importing products from remote xml file.
I have added:
In admin/view/template/module/my_module.tpl
Code: Select all
<div class="form-group">
<div class="col-sm-10">
<div class="well well-sm" style="height: 150px; overflow: auto;">
<div class="checkbox">
<label>
<?php if (in_array(0, $my_module_store)) { ?>
<input type="checkbox" name="my_module_store[]" value="0" checked="checked" />
<?php echo $text_default; ?>
<?php } else { ?>
<input type="checkbox" name="my_module_store[]" value="0" />
<?php echo $text_default; ?>
<?php } ?>
</label>
</div>
<?php foreach ($stores as $store) { ?>
<div class="checkbox">
<label>
<?php if (in_array($store['store_id'], $my_module_store)) { ?>
<input type="checkbox" name="my_module_store[]" value="<?php echo $store['store_id']; ?>" checked="checked" />
<?php echo $store['name']; ?>
<?php } else { ?>
<input type="checkbox" name="my_module_store[]" value="<?php echo $store['store_id']; ?>" />
<?php echo $store['name']; ?>
<?php } ?>
</label>
</div>
<?php } ?>
</div>
</div>
</div>
Code: Select all
$data['text_default'] = $this->language->get('text_default');
$this->load->model('setting/store');
$this->load->model('module/my_module');
$data['stores'] = $this->model_setting_store->getStores();
if (isset($this->request->post['my_module_store'])) {
$data['my_module_store'] = $this->request->post['product_store'];
} elseif (isset($this->request->get['product_id'])) {
$data['my_module_store'] = $this->model_catalog_my_module->getProductStores($this->request->get['product_id']);
} else {
$data['my_module_store'] = array(0);
}
Code: Select all
public function addProduct($data){
if (isset($data['my_module_store'])) {
foreach ($data['my_module_store'] as $store_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
}
}
}
public function getProductStores($product_id) {
$my_module_store_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
foreach ($query->rows as $result) {
$my_module_store_data[] = $result['store_id'];
}
return $my_module_store_data;
}
Please help to find solution!
Thank you in advance.