Module route with rewrite redirect to product on Prestahop - prestashop

I created a custom route for an artist page:
public function hookModuleRoutes($params)
{
return [
'module-artists-artist' => [
'controller' => 'artist',
'rule' => 'artists/{id_artist}',
'keywords' => [
'id_artist' => ['regexp' => '[0-9]+', 'param' => 'id_artist'],
],
'params' => [
'fc' => 'module',
'module' => 'artists',
'controller' => 'artist'
],
],
];
}
If I test with /artists/1, this works. But I want to add the link_rewrite property. So I modified the configuration like this:
public function hookModuleRoutes($params)
{
return [
'module-artists-artist' => [
'controller' => 'artist',
'rule' => 'artists/{id_artist}-{rewrite}',
'keywords' => [
'id_artist' => ['regexp' => '[0-9]+', 'param' => 'id_artist'],
'rewrite' => ['regexp' => '[_a-zA-Z0-9\pL\pS-]*'],
],
'params' => [
'fc' => 'module',
'module' => 'artists',
'controller' => 'artist'
],
],
];
}
But when I try /artists/1-baxter, I'm redirected to the product page of product with ID 1. My artist controller is never called.
[Debug] This page has moved
Please use the following URL instead: http://localhost:8000/fr/estampes/1-est-ce-que-etre
How can I solve it?

This is because URLs generated by your pattern also match the product URL pattern, which has higherprecedence. PrestaShop doesn't check whether product exists, it just redirects directly to ProductController. Page patterns in PrestaShop differ from each other so that URLs can be quickly recognized to be associated with X controller. You can confirm this by checking the default patterns.
You can check the product URL pattern in back-office: SEO & URLs or in DispatcherCore class. Anyway, if you want an easy fix I'd suggest making this pattern:
artists/{id_artist}/{rewrite}

Related

Yii2 How disable Redis

I made the deply of my application (Yii2) in the production environment of the client and there he uses REDIS in another application (Laravel).
However in my Yii2 application I have nothing using or instantiating REDIS, however when running the error appears below. How do I disable REDIS in the application?
Example web.php
'session' => [
'name' => '_siscoopSessionId',
'savePath' => __DIR__ . '/../runtime',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
UPDATE
My db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=srv-probat;dbname=siscoop',
'username' => 'intranet',
'password' => '*****',
'charset' => 'utf8',
];
Solution:
Remove all this code:
'session' => [
'name' => '_appnameSessionId',
'savePath' => DIR . '/../runtime',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],

In Laravel Backpack need to list users with specific role

please check the details below, where I have a Organizations module. Where I can create a organization with a owner with role "organization".
The third input is a dropdown where we need to select the user with role "organization"
protected function addOrganizationFields(){
$this->crud->addFields([
[
'name' => 'name',
'label' => __('Organization Name'),
'type' => 'text',
],
[
'name' => 'billing_information',
'label' => __('Billing Information'),
'type' => 'textarea',
],
[
'name' => 'owner_id',
'label' => __('Organization Owner'),
'type' => 'select2',
'entity' => 'owners_list',
'attribute' => 'name',
'model' => "App\User",
]
]);
}
In the organization module I wrote this code.
public function owners_list(){
return User::whereHas('roles', function($q){
$q->where('name', 'member');
})->get();
}
in the Organization model relationship I wrote this.
But showing the list of all users in the drop-down.
Can anybody please tel me what is to be done.
You can eliminate options from your select2 field using the “options” attribute mentioned in the docs - https://backpackforlaravel.com/docs/4.1/crud-fields
[
'name' => 'owner_id',
'label' => __('Organization Owner'),
'type' => 'select2',
'entity' => 'owners_list',
'attribute' => 'name',
'model' => "App\User",
// add something like this
'options' => (function ($query) {
return $query->whereHas('roles', function($q){
$q->where('name', 'member');
})->get();
}), // force the related options to be a custom query, instead of all(); you can use this to filter the results show in the select
]

Get full url of current webpage in Yii2

How to get the full URl in address bar to my Yii2 Model using yii\helpers\Url ?
I use $currentUrl = Yii::$app->request->url; but it return site/submit which is defined already in my UrlManager :
'urlManager' => [
'enableStrictParsing' => true,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/' => 'site/index',
'site/submit' => 'site/submit',
'admin' => 'admin/index',
'admin/login' => 'admin/login',
'admin/index' => 'admin/index',
'admin/logout' => 'admin/logout',
'/<url:.+>' => 'site/index',
'defaultRoute' => 'site/index',
],
],
Best regards,
Yii::$app->request->absoluteUrl
Plz follow this yii2 document
Yii::app()->createAbsoluteUrl(Yii::app()->request->url)

I need some understanding of the routing of a multi module Phalcon application

I need some help with a multi module Phalcon application. I followed the instructions as per https://github.com/phalcon/mvc/tree/master/multiple but cannot get the variable routing working for the non default module.
$router = new Router();
$router->setDefaultModule("admin");
$router->setDefaultAction('index');
This works for the admin module:
$router->add("/:controller/:action/:params", array(
'module' => 'admin',
'controller' => 1,
'action' => 2,
'params' => 3
));
This works only works for the api module (the not default module) when set manually:
$router->add("/api", array(
'module' => 'api',
'controller' => 'index'
));
$router->add("/api/user", array(
'module' => 'api',
'controller' => 'user',
'action' => 'index'
));
But this won't work for the api module:
$router->add("/api/:controller/:action/:params", array(
'module' => 'api',
'controller' => 1,
'action' => 2,
'params' => 3
));
I then get an error like below when I use /api or /api/user:
\www\site\public\index.php:104:string 'admin\controllers\ApiController handler class cannot be loaded'
But when I access /api/user/index it works. It looks like for the not default module it forgets the setDefaultAction
You're missing routes with default controller, actions:
$router->add("/api/:controller", array(
'module' => 'api',
'controller' => 1,
'action' => 'index',
));
$router->add("/api", array(
'module' => 'api',
'controller' => 'index',
'action' => 'index',
));
Phalcon needs routes to be strictly specified, otherwise it's not going to resolve them. We're paying this price for routing's high performance.
Try to set namespace
'namespace' => 'App\Modules\Api\Controllers']
Your first pattern is a catch-all which sends all routes to the admin controller. Have you tried putting the admin module route at the end?
Alternatively, you could use a pattern that includes the module:
$router->add("/:module/:controller/:action/:params", array(
'module' => 1,
'controller' => 2,
'action' => 3,
'params' => 4
));

yii2 custom REST api issue

I have tried all the way to make these run but no use.There is lots of problem and confusion i m going through.
I have make api which return all the countries which is working fine.Now need to write api function to list all the states of perticular country.
api : http://phpserver:8090/ssn-project/newzit/api/web/state/customstate?country_id=102
StateController.php
class StateController extends ActiveController{
public $modelClass = 'api\modules\state\models\State';
public function actionCustomState($country_id)
{
$model = new $this->modelClass;
$result = $model::find()
->where(['country_id' => $country_id])
->all();
return $result;
}
}
main.php
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => ['country/country','state/state','category/category','seller/seller'],
'extraPatterns' => [
'GET CustomState' => 'CustomState',
],
]
],
]
Am I doing anything wrong.Please help
What do you mean by 'controller' => ['country/country','state/state','category/category','seller/seller'] ? This will be treated as module/controller. You have placed all controllers inside different modules? With this logic, your api url will be
http://phpserver:8090/ssn-project/newzit/api/web/state/state/customstate?country_id=102
instead of
http://phpserver:8090/ssn-project/newzit/api/web/state/customstate?country_id=102
Found the solution.
made 'pluralize'=>false and used custom-state in url
My main.php
'rules' => [
[
'pluralize'=>false,
'class' => 'yii\rest\UrlRule',
'controller' => ['country/country','state/state','category/category','seller/seller','contactus/contactus'],
'extraPatterns' => [
'GET custom-state' => 'custom-state',
],
]
],
Thank you.