Post by kestas » Wed May 18, 2016 6:13 pm

Hello,

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>
admin/controller/module/my_module.php

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);
		}
admin/model/module/my_module.php

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;
		
	}
 
Seems I miss something. I can't save selected stores. Always default store are selected.

Please help to find solution!

Thank you in advance.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by straightlight » Thu May 19, 2016 10:44 pm

The latest version of OC already provides the possibility of selecting stores handled by the startup folder. The store ID is now a days generic according to the selection by the browser.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Qphoria » Fri May 20, 2016 2:42 am

straightlight wrote:The latest version of OC already provides the possibility of selecting stores handled by the startup folder. The store ID is now a days generic according to the selection by the browser.
Not sure what you mean here.
kestas wrote:I need add to my module selectable stores.
I have a mod called Ext2Store that lets you assign certain modules to a certain store.
So you could limit Latest on store 1, featured to store 2, bestseller to store 1 and 2
Same goes with payments and shipping. You could set UPS on store 1, fedex on Store 2

This works at a more global scale rather than adding it to each individual module.

The reality is, these types of settings should be done at the extension "list" level in the core. It should not be up to the individual modules to add store selection, geo zone assignment, and status. These are all core level settings that apply to all modules and should be set at the main controller level. Otherwise what if a customer wants to set a module for a certain geozone and the developer forgot to code that in? Common code shouldn't need to be repeated by all developers. It's redundant and repetitive.

But to answer your question, if you can't save, double check your html in the browser inspector and add some debug to the model step where you save. I see addProduct but not editProduct function

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by straightlight » Fri May 20, 2016 6:38 am

Qphoria wrote:
straightlight wrote:The latest version of OC already provides the possibility of selecting stores handled by the startup folder. The store ID is now a days generic according to the selection by the browser.
Not sure what you mean here.
In catalog/controller/startup/startup.php file, the following is present:

Code: Select all

if (isset($this->request->get['store_id'])) {
			$this->config->set('config_store_id', $this->request->get['store_id']);
		} else if ($query->num_rows) {
			$this->config->set('config_store_id', $query->row['store_id']);
		} else {
			$this->config->set('config_store_id', 0);
		}
which means that the store ID can be passed over the browser and verified by the first if statement.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 3 guests