0
votes

I have some difficulties understanding what is wrong in the logic applied on a custom module when I want to use some custom URLs

So, I use the hookModuleRoutes inside my custom module "pages" like this:

    public function hookModuleRoutes($params){
    $my_link = array(
        'module-vpages-dpage' => array(
            'controller' => 'dpage',
            'rule' => '{id_country:-}flower-delivery{-:country}{-:city}.html',
            'keywords' => array(
                'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
                'setCountry' => array('regexp' => '[0-9]+', 'param' => 'setCountry'),
                'country' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'country'),
                'city' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'city'),
                'module_action' => array('regexp' => '[\w]+', 'param' => 'module_action')
            ),
            'params' => array(
                'fc' => 'module',
                'module' => 'vpages',
            )
        )
    );
    return $my_link;
}

And the module controller that should work:

    class vpagesdpageModuleFrontController extends ModuleFrontController
{
    public $errors = array();
    public $display_column_left = false;
    public $display_column_right = false;
    public $ssl = true;
    public $php_self = 'dpage'; 

        
    public function __construct()
    {
        parent::__construct();
        $this->page_name = 'dpage';
        $this->context = Context::getContext();
    }

    public function initContent()
    {
        parent::initContent();

        $this->context->cookie->__set('productbycountry_id',Tools::getValue('id_country')); 
        $sql     = "SELECT DISTINCT ps_country_lang.id_country, ps_country_lang.name as country, city FROM ps_cms_target_world
                    LEFT JOIN ps_country_lang ON ps_cms_target_world.id_country = ps_country_lang.id_country
                    WHERE ps_country_lang.id_country=" . Tools::getValue('id_country') . "
                    ORDER BY country ASC";
        //die($sql);
        $cPages  = Db::getInstance()->ExecuteS($sql);                
        
        $get_url  = Db::getInstance()->ExecuteS('SELECT domain,physical_uri FROM '._DB_PREFIX_.'shop_url ');
        $protocol = (isset($_SERVER['HTTPS']) ? "https" : "http") ;
        $site_url = "$protocol://".$get_url[0]['domain'].$get_url[0]['physical_uri']."modules";

        $controller_url = $this->context->link->getModuleLink('vpages', 'vPagesController', array(), true);
        $this->context->smarty->assign(array(
            'link' => $this->context->link,
            'controller_url' => $controller_url,
            'cPages' => $cPages,
            'SITEURL' => $site_url
        ));
        
        $country = urldecode(Tools::getValue('country'));        
        $city = urldecode(Tools::getValue('city'));
        if(isset($city) && !empty($city)) $title = " - " . $city; 
        
        $this->context->smarty->assign('meta_title', 'Flower delivery to ' . $country . $title);
       
        //$this->setTemplate('dPage.tpl'); 
        $this->setTemplate('module:vpages/views/templates/front/dPage.tpl');
    }


}

The urls are properly created but when I try to access the content of that page I will end up in a 404 error page Am I doing something wrong? I think I miss something pretty obvious but cannot understand what..

I already did my research and still I am not able to find a solution for my issue.. It seems that the $route['controller'] is 'product' instead of the custom module

Thank you!

1
What is your frontController file name? - Mahdi Shad
What url do you search for? a url to access the front controllerer of your custom url? - Crezzur
The target url is the following: mysite.com/en/40-flower-delivery-Andorra.html or en/40-flower-delivery-Andorra-Andorra+la+Vella.html depending on the parameters - rosuandreimihai
that custom url should be handled by the hookmoduleroutes but it doesn't - rosuandreimihai

1 Answers

0
votes

I think that you have to add 'controller' to your params:

'params' => [
                'fc' => 'module',
                'module' => 'vpages',
                'controller' => 'dpage',
            ]