Hello i am working on prestrashop its new for and i am trying to develop a module in admin panel i create a model calss sizeguide but when i click on add its showing the error ,
Fatal error: Class 'sizeguide' not found in classes\controller\AdminController.php on line 1614
i did try to fix it but i am not able to fix it even class is showing in class_index.php like this .
'Sizeguide' => array (
'path' => '',
'type' => 'class',
'override' => false,
),
'SizeguideCore' => array (
'path' => 'classes/Sizeguide.php',
'type' => 'class',
'override' => false,
),
please help me to fix this issue thanks in advance.
A moduleadmincontroller it's a little bit different of a modulefrontcontroller.
I'll write some guidelines.
Naming
The class name should be like this AdminCONTROLLERNAMEController.
For example:
class AdminGalleryController
The complete declaration should be:
class AdminGalleryController extends ModuleAdminController
{
// some stuff
}
Add 'controller' in DB
The new admin controller must be added in database, otherwise the dispatcher didn't find it.
This snippet add the new admin controller in the database:
$tab = new Tab();
foreach (Language::getLanguages() as $language) {
$tab->name[$language['id_lang']] = $tabName;
}
$tab->class_name = 'AdminGallery';
$tab->module = /*yourmodulename*/;
$tab->id_parent = 0;
/*
* If you want to add as a child of some admin controller
* that is in the backoffice menu you have to use this code:
* (int)Tab::getIdFromClassName('AdminCatalog');
* With that code you add your controller as a child of 'AdminCatalog' controller
*/
$tab->save()
Usually this snippet should be added in install method of your module.
After that to answer to your question, your class should not be in class_index.php, your model should be placed in your module and be loaded by him.
For example in your module constructor you can add this snippet:
public function __construct()
{
/* ... */
require_once( _PS_MODULE_DIR_ . DIRECTORY_SEPARATOR . $this->name . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'Sizeguide.php' );
/* ... */
}
Related
I built an extension and I would like to add plugin options at the time of adding the plugin to the page
Extension Name : hotels
in Hotel model ,
<?php
class Hotel{
... get set methods ...
}
?>
in HotelController.php
<?php
namespace TYPO3\Hotels\Controller;
class HotelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController{
public function listAction(){
// $this->view->assign('result', array('test' => 'hello, u r in list')); }
}
?>
in ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'TYPO3.' . $_EXTKEY,
'hotels',
array('Hotel' => 'list,single,display,update,save,preview,edit')
);
in ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'hotels',
'list of Hotels'
);
$pluginSignature = str_replace('_','',$_EXTKEY) . '_hotels';
$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] ='pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/flexform_myhotel.xml');
Somehow, I think i'm missing something. This gives an error :
I can see the option in backend side at time of adding extension but when i want to show (view) that Page where I add that extension , generates an error .
----> The default controller for extension "Hotels" and plugin "hotels" can not be determined. Please check for TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your ext_localconf.php.
Please Guide me
In TYPO3 6.x, you are advised to use namespaced classes and tell the configurePlugin method your vendor name.
As you didnt include any of your controller code, I'll try to sketch it:
At first, make sure, you use a namespaced controller class-remember to set a Vendor name.
Make sure, your actions are named with the *Action suffix
EXT: myext/Classes/Controller/HotelController
namespace MyVendor\MyExt\Controller;
class HotelController {
/**
* #return void
*/
public function listAction(){
}
}
Next, mention the namespace in configurePlugin like this:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'MyVendor.' . $_EXTKEY,
// UpperCamelCase please, refer to [1]
'Hotels',
array('Hotel' => 'list,single,display,update,save,preview,edit')
);
This allows the class locator to resolve the classes correctly.
To verify it, make sure you re-install your extension.
PS: Please use the namespaced classes whenever possible in 6.x. The old Tx_* classes are only aliases and put additional load on your interpreter.
1 - TYPO3 API Docs for ExtensionUtility::configurePlugin()
Update:
There is a multitude of possible errors.
You wired a FlexForm. Did you set the switchableControllerActions appropriately?
One thing I saw more than once: The f:link.action (or f:uri.action respectively) doesnt like to be without an appropriate controller attribute
You clearly missed the namespace concept :) Rename your ControllerClass to HotelController and the file must live in Classes/Controller/HotelController.php, then do the adjustments to configurePlugin() to reflect the vendorName as I described
Try it.
in ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'TYPO3.' . $_EXTKEY,
'hotels',
array(
'Hotel' => 'list,single,display,update,save,preview,edit'
),
// non-cacheable actions
array(
'Hotel' => 'list',
)
);
in ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'hotels',
'list of Hotels'
);
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$pluginSignature = strtolower($extensionName). '_hotels';
if (TYPO3_MODE === 'BE') {
/**
* Registers a Backend Module
*/
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'TYPO3.' . $_EXTKEY,
'web', // Make module a submodule of 'web'
'hotels', // Submodule key
'', // Position
array(
'Hotel' => 'list,single,display,update,save,preview,edit'
),
array(
'access' => 'user,group',
'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.gif',
'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_hotels.xlf',
)
);
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Hotels List');
#Clear cache and remove typo3temp data
I have a Yii 1.x component loaded in the configuration file like so
$config['components']['simplesamlphp'] = array(
'class' => 'application.components.yii-simplesamlphp.components.Simplesamlphp',
'autoloadPath' => SAML_DIR.'/test2/lib/_autoload.php',
'authSource' => 'default-sp',
);
I need to make the autoloadPath property dynamic based on who the user is in the controller. Is this possible? And if so how do I overwrite it?
Probably the best way is to extend Simplesamlphp and configure property in init():
class MySimplesamlphp extends Simplesamlphp {
public $adminAutoloadPath;
public $nonAdminAutoloadPath;
public function init() {
if (Yii::app()->user->isAdmin()) {
$this->autoloadPath = $this->adminAutoloadPath;
} else {
$this->autoloadPath = $this->nonAdminAutoloadPath;
}
parent::init();
}
}
And use new component in config:
$config['components']['simplesamlphp'] = array(
'class' => 'MySimplesamlphp',
'adminAutoloadPath' => SAML_DIR.'/test2-admin/lib/_autoload.php',
'nonAdminAutoloadPath' => SAML_DIR.'/test2/lib/_autoload.php',
'authSource' => 'default-sp',
);
I figured it out overriding yii components is fairly easy even if you dont initialize it in the config.
$component = array(
'class' => 'application.components.yii-simplesamlphp.components.Simplesamlphp',
'autoloadPath' => SAML_DIR.'/'.$tenant_path.'/lib/_autoload.php',
'authSource' => 'default-sp',
); //where $tenant_path is the directory of the component i need based on the tenant
Yii::app()->setComponent('simplesamlphp',$component);
then use the component in your controller like so
Yii::app()->simplesamlphp;
Note that you will only have access to the component within your controller method so all i did was move the that code to its own class and call it when i needed to create a new instance of the component
I created new resources with this code:
class WebserviceRequest extends WebserviceRequestCore {
public static function getResources(){
$resources = parent::getResources();
// if you do not have class for your table
$resources['test'] = array('description' => 'Manage My API', 'specific_management' => true);
$resources['categoryecommerce'] = array('description' => 'o jacie marcin', 'class' => 'CategoryEcommerce');
$mp_resource = Hook::exec('addMobikulResources', array('resources' => $resources), null, true, false);
if (is_array($mp_resource) && count($mp_resource)) {
foreach ($mp_resource as $new_resources) {
if (is_array($new_resources) && count($new_resources)) {
$resources = array_merge($resources, $new_resources);
}
}
}
ksort($resources);
return $resources;
}
}
And new class:
class CategoryEcommerceCore extends ObjectModelCore {
public $category_id;
public $category_core_id;
public static $definition = array(
'table' => "category_ecommerce",
'primary' => 'category_id',
'fields' => array(
'category_core_id' => array('type' => self::TYPE_INT),
)
);
protected $webserviceParameters = array();
}
Webservice is override properly. My class WebserviceRequest is copying to
/override/classes/webservice/WebserviceRequest
but class isn't copying to /override/classes/ when i installing my module.
How to add new resourcess with own logic ? I want to add categories within relation to my table.
Regards
Martin
As soon as there is literally nothing regarding the API except Webkul tutorial... I tried to implement the "Webkul's" tutorial, but also failed. However seems that it's better to use hooks instead of overrides. I used my "reverse engineering skills" to determine the way to create that API, so-o-o-o, BEHOLD! :D
Let's assume you have a custom PrestaShop 1.7 module. Your file is mymodule.php and here are several steps.
This is an install method wich allows you to register the hook within database (you can uninstall and reinstall the module for this method to be executed):
public function install() {
parent::install();
$this->registerHook('addWebserviceResources');
return true;
}
Add the hook listener:
public function hookAddWebserviceResources($resources) {
$added_resources['test'] = [
'description' => 'Test',
'specific_management' => true,
];
return $added_resources;
}
That specific_management option shows you are going to use WebsiteSpecificManagement file instead of database model file.
Create WebsiteSpecificManagement file, called WebsiteSpecificManagementTest (Test - is CamelCased name of your endpoint). You can take the skeleton for this file from /classes/webservice/WebserviceSpecificManagementSearch.php. Remove everything except:
setObjectOutput
setWsObject
getWsObject
getObjectOutput
setUrlSegment
getUrlSegment
getContent (should return $this->output; and nothing more)
manage - you should rewrite it to return/process the data you want.
Add
include_once(_PS_MODULE_DIR_.'YOURMODULENAME/classes/WebserviceSpecificManagementTest.php');
to your module file (haven't figured out how to include automatically).
Go to /Backoffice/index.php?controller=AdminWebservice and setup the new "Auth" key for your application, selecting the test endpoint from the permissions list. Remember the key.
Visit /api/test?ws_key=YOUR_KEY_GENERATED_ON_STEP_4 and see the XML response.
Add &output_format=JSON to your URL to see the response in JSON.
You have to use something like $this->output = json_encode(['blah' => 'world']) within manage method at WebsiteSpecificManagementTest.
I try to add a new controller which has one action called confirmAgbAction.
<?php
namespace Eddcapone\MyExtension\Controller;
/**
* CustomController
*/
class CustomController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* action list
*
* #return void
*/
public function confirmAgbAction()
{
echo "<p>HALLO WELT</p>";
}
}
I even added it to ext_localconf.php
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Eddcapone.' . $_EXTKEY,
'Myfilelist',
array(
'Category' => 'list,show',
'File' => 'show',
'Download' => 'download',
'Custom' => 'confirmAgb'
),
// non-cacheable actions
array(
'Category' => 'list,show',
'File' => 'topFive',
'Download' => 'download',
'Custom' => 'confirmAgb'
)
);
This is how I call the action in the template:
<f:link.action controller="Custom" action="confirmAgb" pluginName="Myfilelist" class="mbButton">Download</f:link.action>
However, i always get:
#1313855173: The controller "Custom" is not allowed by this plugin. Please check for TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your ext_localconf.php.
There are two common possibilities for your error:
You use a flexform to embed your plugin. Either you have not added Custom->confirmAgb to the allowed calls in your flexform or you have added it but did not update the plugin (plugin configuration only updates when you save the plugin/tt_content element)
You have two plugins on the page and the error is triggered by the other plugin because there the controller->action combination is not allowed.
PS: try adding this to your TS (setup.txt) and the plugins now should pick the default action if the given one is not found:
plugin.tx_yourextensionmvc.callDefaultActionIfActionCantBeResolved = 1
There could be more uncommon cases
You should absolutely avoid using $_EXTKEY in configurePlugin and other Extbase contexts. Extbase requires the Vendor.ExtensionName format - $_EXTKEY is in the lowercase_underscored format. Defining those parameters as hardcoded values should solve your problem with resolving controllers for your given plugin.
To be precise: use Eddcapone.Myextension as extension name parameter in your command(s) to register/configure plugins.
I built an extension and I would like to add plugin options at the time of adding the plugin to the page
Extension Name : hotels
in Hotel model ,
<?php
class Hotel{
... get set methods ...
}
?>
in HotelController.php
<?php
namespace TYPO3\Hotels\Controller;
class HotelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController{
public function listAction(){
// $this->view->assign('result', array('test' => 'hello, u r in list')); }
}
?>
in ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'TYPO3.' . $_EXTKEY,
'hotels',
array('Hotel' => 'list,single,display,update,save,preview,edit')
);
in ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'hotels',
'list of Hotels'
);
$pluginSignature = str_replace('_','',$_EXTKEY) . '_hotels';
$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] ='pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/flexform_myhotel.xml');
Somehow, I think i'm missing something. This gives an error :
I can see the option in backend side at time of adding extension but when i want to show (view) that Page where I add that extension , generates an error .
----> The default controller for extension "Hotels" and plugin "hotels" can not be determined. Please check for TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your ext_localconf.php.
Please Guide me
In TYPO3 6.x, you are advised to use namespaced classes and tell the configurePlugin method your vendor name.
As you didnt include any of your controller code, I'll try to sketch it:
At first, make sure, you use a namespaced controller class-remember to set a Vendor name.
Make sure, your actions are named with the *Action suffix
EXT: myext/Classes/Controller/HotelController
namespace MyVendor\MyExt\Controller;
class HotelController {
/**
* #return void
*/
public function listAction(){
}
}
Next, mention the namespace in configurePlugin like this:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'MyVendor.' . $_EXTKEY,
// UpperCamelCase please, refer to [1]
'Hotels',
array('Hotel' => 'list,single,display,update,save,preview,edit')
);
This allows the class locator to resolve the classes correctly.
To verify it, make sure you re-install your extension.
PS: Please use the namespaced classes whenever possible in 6.x. The old Tx_* classes are only aliases and put additional load on your interpreter.
1 - TYPO3 API Docs for ExtensionUtility::configurePlugin()
Update:
There is a multitude of possible errors.
You wired a FlexForm. Did you set the switchableControllerActions appropriately?
One thing I saw more than once: The f:link.action (or f:uri.action respectively) doesnt like to be without an appropriate controller attribute
You clearly missed the namespace concept :) Rename your ControllerClass to HotelController and the file must live in Classes/Controller/HotelController.php, then do the adjustments to configurePlugin() to reflect the vendorName as I described
Try it.
in ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'TYPO3.' . $_EXTKEY,
'hotels',
array(
'Hotel' => 'list,single,display,update,save,preview,edit'
),
// non-cacheable actions
array(
'Hotel' => 'list',
)
);
in ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'hotels',
'list of Hotels'
);
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$pluginSignature = strtolower($extensionName). '_hotels';
if (TYPO3_MODE === 'BE') {
/**
* Registers a Backend Module
*/
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'TYPO3.' . $_EXTKEY,
'web', // Make module a submodule of 'web'
'hotels', // Submodule key
'', // Position
array(
'Hotel' => 'list,single,display,update,save,preview,edit'
),
array(
'access' => 'user,group',
'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.gif',
'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_hotels.xlf',
)
);
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Hotels List');
#Clear cache and remove typo3temp data