How to get back-office root url fromt the front-controller in prestashop 1.7 - prestashop

I am looking for generating admin root url( like: http://localhost/prestashop174/admin084oazcuj/index.php ) from a front-office controller in prestashop 1.7.

Try _PS_ADMIN_DIR_ instead of PS_ADMIN_DIR , because of the PS_ADMIN_DIR is not defined by PrestaShop, and could be undefined
if (!$link) {
$link = Context::getContext()->link;
}
$link->getAdminBaseLink() . basename(_PS_ADMIN_DIR_)
or
$this->context->link->getAdminBaseLink() . basename(_PS_ADMIN_DIR_)

You can get link of admin in front controller by using Link class
$this->context->link->getAdminBaseLink() . basename(_PS_ADMIN_DIR_)

Related

how to Generating an admin controller link in Prestashop using {{url entity= }?

I am Migrating a module from 1.6 to 1.7 so i need to remove {$link->getAdminLink('AdminModules')} from my tpl file and i should use {url} helper.
because of this: $link is deprecated (even if it’s still passed to smarty, it will be removed at some point), use {url} helper
here is link: http://doc.prestashop.com/display/PS17/Migrating+a+module+from+1.6+to+1.7
please help me out, thanks
$stat = PS_ADMIN_DIR;
$admin_folder = substr(strrchr($stat, "\ "), 1);
$admin_url =_PS_BASE_URL_.__PS_BASE_URI__.$admin_folder;
$token = Tools::getAdminTokenLite('AdminModules');
$this->context->smarty->assign('token', $token);
$this->context->smarty->assign('admin_url', $admin_url );
that's how i get proper admin controller url.
hope it will help you.
You can generate an admin controller link from in a *.tpl file with the same syntax we use in php, for example:
<a href"{Context::getContext()->link->getAdminLink('AdminMymoduleBooksManager', true)}&updateymodule_book=&mymodule_book_id={$id_book}">edit a book in my admin controller<a/>
You can replace {$link->getAdminLink('AdminModules')} by:
{url entity='sf' route='admin_module_catalog'}
{url entity='sf' route='admin_module_manage'}
or {url entity='sf' route='admin_module_notification'}
depending on what tab you want to redirect your users to.

Error using Laravel resource controller update method within a grouped route

I have a Laravel app which I'm using to create a RESTful API.
I'm having some issues with the edit/update methods in my resource controller when using a grouped route.
WHen I remove the route grouping the controller works as expected.
My routes look like:
Route::group(array('prefix' => 'api/v1'), function()
{
Route::resource('/trip', 'TripController');
});
So using this my RESTFul endpoints should look like:
GET /api/v1/trip/{resource}
GET /api/v1/trip/{resource}/edit
PUT /api/v1/trip/update/{resource}
GET /api/v1/trip/create
POST /api/v1/trip/store/{resource}
etc.
All work except the Edit and Update endpoints.
When I hit /api/v1/trip/{resource}/edit I get the following error
Unable to generate a URL for the named route "trip.update" as such route does not exist.
My Controller Edit method is just a quick form for testing. It looks like:
public function edit($id)
{
$oTrip = new Trip;
$oTrip = $oTrip->find($id);
echo Form::model($oTrip, array(
'route' => array('trip.update', $oTrip->id),
'method' => 'PUT'
));
echo Form::text('headline');
echo Form::text('description');
echo Form::submit('Click Me!');
echo Form::close();
}
Laravel seems to be unable to find trip.update when in the grouped route.
I think there is a problem with the Group prefix api/v1
When I comment out the group code just to read:
Route::resource('/trip', 'TripController');
...and access the uri just as /trip/{resource}/edit without the api/v1 prefix everything works fine as expected.
Is there something I'm missing?
I would really like to get this working with the grouping and api/v1 prefix.

PHPBB adding custom page in a new directory

My version of PHPBB is installed /board of my site
I am trying to make a custom page inside a new directory called store the file is called decals.php
decals.php
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
page_header('Store - Decals');
$template->set_filenames(array(
'body' => 'store_decals_body.html',
));
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
the store_decals_body.html is uploaded to my styles directory and i cant seem to get mysite.com/board/store/decals.php to work. It always put me to mysite.com/board
Have I overlooked something here?
If you have the PHP file in a subdirectory, change the root path accordingly:
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';

Error while using REST api in magento

I have set up magento locally in my system using XAMPP
I have created a file in root directory named dm.php with the contents
<?php
/**
* Example of products list retrieve using Customer account via Magento REST API. OAuth authorization is used
*/
$callbackUrl = "http://localhost/dm.php";
$temporaryCredentialsRequestUrl = "http://localhost/mage2/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/mage2/oauth/authorize';
$accessTokenRequestUrl = 'http://localhost/mage2/oauth/token';
$apiUrl = 'http://localhost/mage2/api/rest';
$consumerKey = 'enhksf7u33p3snubewb6zcq0z9c63bvv';
$consumerSecret = 'p7e835cdcxofokeep749jgzz4l1e306p';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
try {
$authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} else if ($_SESSION['state'] == 1) {
$oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
header('Location: ' . $callbackUrl);
exit;
} else {
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/products";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);
}
} catch (OAuthException $e) {
print_r($e);
}
But this is giving me the following error
Fatal error: Class 'OAuth' not found in D:\Webserver\xampp\htdocs\dm.php on line 19
Can anybody shed some light on this
Thanks
Since oauth is not possible to install in xampp windows i changed the contents of my dm.php file to this.
<?php
$ch = curl_init('http://localhost/mage2/api/rest/customers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$customers = curl_exec($ch);
echo $customers;
?>
Now i am getting an error like this
{"messages":{"error":[{"code":403,"message":"Access denied"}]}}
What am i doing wrong?
First of all
Go to magento admin panel System->Webservice->RESt Roles->Guest->Resources Access ->SET ALL
Similarly Go to System->Webservice->RESt Attribute->Guest->Resources Access ->SET ALL
Then Hit this url http://****/chanchal/magento/api/rest/products in web Browser and check what error it shows....
According to me it must show product in your website in xml format.
Please let me know..
EDIT:
I configured a localhost just now and got this output refer the Screenshot. Be sure there is product in your magento.
Similarly follow the above steps for admin,customer then create a Ouath consumer from admin panel , Install RESTClient For Mozilla Firefox And follow Here
These for steps are necessary for the setup..the link might help you..
Authentication Endpoints
1./oauth/initiate - this endpoint is used for retrieving the Request Token.
2./oauth/authorize - this endpoint is used for user authorization (Customer).
3./admin/oauth_authorize - this endpoint is used for user authorization (Admin).
4./oauth/token - this endpoint is used for retrieving the Access Token.
Let me know if you have any issues.
Best of luck
A bit of code modifications will easily solve this error 403 forbidden.
What magento engine does is that it uses the default guest user to provide access to the REST api methods. The guest user does not have much powers so it should be better to change this functionality of magento. There are 2 ways of doing this:
1) Quick and dirty fix: in the file /app/code/core/Mage/Api2/Model/Auth.php, change the value of: DEFAULT_USER_TYPE = 'guest' to DEFAULT_USER_TYPE = 'admin'. In the file /app/code/core/Mage/Api2/Model/Auth/Adapter.php, change this line from return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => null); to this:
return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => '1');
This way the authentication system will not be broken.
2) Proper and long run fix: Override the two functionalities using the magento overriding mechanism to have a better solution in accordance to magento standards. This way the core files will be intact.
We use this link to install oauth for php. Its good and easy to add extension for php.
install oauth php
I hope it helps to all and would solved 'OAuth' not found fatal error.
I had the same issue and was struggling for a week but just try insatlling new version of xammp or wamp with supports ouath.The better solution was ,I installed Ammps 1.9 and in php5.4 I resolved the extension of oauth but still make sure that you select the proper php for extension oauth is supported (php5.4)
For installing Oauth : http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html
Installing PHP Extension for Oauth :
1. Download php_oauth.dll file and add it under C:\xampp\php\ext\
2. add [PHP_OAUTH] extension=php_oauth.dll in php.ini

Symfony and uploadify

I want to use uploadify with Symfony 1.4, but so far I couldn't.
Uploadify loads correctly, I choose my files, it says that the files were successfully uploaded, but the are nowhere.
(I'm doing this on localhost)
Is there anybody who met this problem before?
Thanks, Tom
$file = $request->getParameter('file');
$filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());
$file->save(sfConfig::get('sf_upload_dir').'/'.$filename);
in my project session stored in cookies so I found solution by create extra session storage class
class MySessionStorage extends sfSessionStorage
{
public function initialize($options = null)
{
$request = sfContext::getInstance()->getRequest();
// work-around for uploadify
if ($request->getParameter('uploadify') == "onUpload")
{
$sessionName = $options["session_name"];
if($value = $request->getParameter($sessionName))
{
session_name($sessionName);
session_id($value);
}
}
parent::initialize($options);
}
}
then changed factories.yml to
all:
storage:
class: MySessionStorage
and then "uploader" param will like this
uploader : '<?php echo url_for("attachments/upload?uploadify=onUpload&" . session_name() . "=" . session_id(), true)?>',
I can only guess that it's because you're trying to upload while logged into a system, but flash does not inherit session data from the browser, this means you will always be denied permission to whatever function you are trying to access since symfony thinks you're not logged in.
So you need to manually set variables in order for flash to use the same login session as the browser:
jQuery Code (needs to be in a php file, will not work in a js file):
$('#file_upload').uploadify({
.... config here
'scriptData': { '<?php echo session_name() ?>': '<?php echo session_id() ?>' }
});