Jump to content

Context::getContext() no funciona en admin module controller


JA MODULES

Recommended Posts

Hola,

 

Estoy teniendo un problema. He desarrollado un módulo que crea unas pestañas en el backoffice con sus controladores que extienden de ModuleAdminController.

 

class AdminObjectsController extends ModuleAdminController
{

 

}

 

Lo quiero hacer funcionar en multitienda.

 

En el controlador no funciona nada de esto para capturar la id de la tienda escogida:

 

$this->context->shop->id

Context::getContext()->shop->id

Shop::getCurrentShop()

 

En todos estos casos siempre retorna la tienda por defecto, es decir 1.

 

Espero que alguien me pueda ayudar.

 

Saludos

Link to comment
Share on other sites

Hola,

 

Gracias por su respuesta

 

No, esto tampoco funciona

 

class AdminObjectsController extends ModuleAdminController
{
    public $asso_type = 'shop';

    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'object';
        $this->className = 'Object';
        $this->lang = false;
        
        $this->context = Context::getContext();
        
        //d(Tools::getValue('setShopContext'));
        d($this->context->shop->getContext());

...

    }

}

 

Saludos

Link to comment
Share on other sites

Hola buenas tardes,

 

Lo tengo así y cuando cambio de tienda no recoge el id correcto:

 

class AdminSellersController extends ModuleAdminController
{
    public $asso_type = 'shop';

    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'seller';
        $this->className = 'Seller';
        $this->lang = false;
        
        $this->context = Context::getContext();
        
        $this->_where = 'AND a.id_shop = '.$this->context->shop->id;
        
        if (Tools::isSubmit('submitFilter')) {  
            //d($_POST);
            if (Tools::getValue('sellerFilter_id_seller') != '')
                $this->_where = 'AND a.id_seller = '.(int)Tools::getValue('sellerFilter_id_seller');
            
            if (Tools::getValue('sellerFilter_name') != '')
                $this->_where = 'AND a.name LIKE "%'.(string)Tools::getValue('sellerFilter_name').'%"';
            
            if (Tools::getValue('sellerFilter_shop') != '')
                $this->_where = 'AND a.shop LIKE "%'.(string)Tools::getValue('sellerFilter_shop').'%"';
            
            if (Tools::getValue('sellerFilter_active') != '')
                $this->_where = 'AND a.active = '.(int)Tools::getValue('sellerFilter_active');
            
            $arrayDateAdd = Tools::getValue('sellerFilter_date_add');
            if ($arrayDateAdd[0] != '' && $arrayDateAdd[1] != '') {
                $this->_where = 'AND a.date_add BETWEEN "'.$arrayDateAdd[0].'" AND "'.$arrayDateAdd[1].'"';
            }
            
            $arrayDateUpd = Tools::getValue('sellerFilter_date_upd');
            if ($arrayDateUpd[0] != '' && $arrayDateUpd[1] != '') {
                $this->_where = 'AND a.date_upd BETWEEN "'.$arrayDateUpd[0].'" AND "'.$arrayDateUpd[1].'"';
            }
        }
        
        if (Tools::getValue('sellerOrderway')) {  
            $this->_orderBy = (string)Tools::getValue('sellerOrderby');
            $this->_orderWay = (string)Tools::getValue('sellerOrderway');
        }

        $this->fields_list = array(
            'id_seller' => array(
                'title' => $this->l('ID'),
                'align' => 'center',
                'class' => 'fixed-width-xs'
            ),
            'name' => array(
                'title' => $this->l('Seller name'),
                'havingFilter' => true,
            ),
            'shop' => array(
                'title' => $this->l('Shop name'),
                'havingFilter' => true,
            ),
            'date_add' => array(
                'title' => $this->l('Date add'),
                'type' => 'datetime',
            ),
            'date_upd' => array(
                'title' => $this->l('Date update'),
                'type' => 'datetime',
            ),
            'active' => array(
                'title' => $this->l('Enabled'),
                'align' => 'center',
                'active' => 'status',
                'type' => 'bool',
                'orderby' => false,
                'class' => 'fixed-width-sm'
            )
        );
        $this->bulk_actions = array(
                'delete' => array(
                        'text' => $this->l('Delete selected'),
                        'confirm' => $this->l('Delete selected items?'),
                        'icon' => 'icon-trash'
                )
        );

        parent::__construct();
    }

 

...

 

}

Link to comment
Share on other sites

  • 1 month later...

Si das el tema como solucionado, edita el titulo del tema, editando el primer mensaje, pulsando en editar, y

después en "Usar editor completo", añadiendo la palabra "Solucionado" al titulo, esto ayudara, a mantener una mayor

organización en el foro.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...