Prestashop backoffice module - prestashop-1.7

I have created a Prestashop Backoffice module but on clicking module tab in menu , I am getting error enter image description here 404 page not found?
I want to create a template on clicking module tab and display some text there.

You need to add the entry of the back-office controller in the Menu. You can use the following code to add the controller in the tab:
For Prestashop 1.7:
$parentTab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$parentTab->name[$lang['id_lang']] = $this->l('ShipRocket');
}
$parentTab->class_name = 'AdminShiprocket';
$parentTab->module = $this->name;
$parentTab->active = 1;
$parentTab->id_parent = Tab::getIdFromClassName('SELL');
$parentTab->icon = 'rocket';
$parentTab->add();
You have to use the controller=AdminShiprocketController in the URL which is wrong. You need to use controller=AdminShiprocket to render the controller.
Also, add the controller file in /modules/module_name/controllers/admin/.
The filename should be: AdminShiprocketController.php

Related

Joomla template - is on homepage

I want to create a joomla 3.x template which shows a different UI on the homepage than on all the oder pages.
This works fine with the following code:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
$isHomePage = $menu->getActive() == $menu->getDefault($lang->getTag());
When I click on a menu item $isHomePage is "false" and I can show a different layout.
But when I open an article from the featured articles-list on my home-page, the menu item is still the home page but the user does see the article.
How do I get the information, if the user is really on the home page?
As per my understanding, the home page condition getting true on inside page is due to the fact that if an article does not have any menu it gets it from the current menu. So clicking on home page article link carries home page menu id.
There are some alternative that I can suggest -
1) Checking for URL - Check if current URL is equal to site page URL.
$uri = JUri::getInstance();
$currentUrl = trim($uri->toString(),'/');
$homeUrl = trim(JUri::root(),'/');
$isHomePage = $currentUrl == $homeUrl;
2) Check for homepage parameter with inner pages parameters. For example, if your homepage is of the article and having id X, check from request params check option and id param to com_content and id == X.
I hope this might be helpful.

Joomla MVC Module delete model

I'm a newbie on Joomla developing and I'm trying to fix an old administration module made by 'someone before me'. Module's been developed using MVC Components, it has several CRUDs and I'm stucked at deleting an item. The template view adds the toolbar icon like this:
JToolbarHelper::deleteList('', 'paises.delete', JTOOLBAR_DELETE);
It also has at the list controller (DistribuidoresControllerPaises), the getModel function:
public function getModel($name = 'Pais', $prefix = 'DistribuidoresModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
The model class:
class DistribuidoresModelPais extends JModelAdmin
When selecting an item on the list, and clicking the trash button an empty page opens with this ending:
administrator/index.php?option=com_distribuidores&view=pais
If I come back to grid, the item still remains.
Any suggestion?
Thanks in advance
You can debug this by enabling debugging from Joomla configuration or you can try to to check with exit with in "delete" function of "paises" controller and can check you get item ids in post request or not.
Also you are using view "pais" also using model "pais" then why you are using "paises" controller for delete function, you should use "pais" controller to delete.
Also provide delete function which you are using to delete items, it may contain some issue.

Where is Itemid used to flag active menu item in Joomla 2.5.6?

Can anyone please help me with the process flow through which the Joomla Itemid parameter ends up being the highlighted menu item?
I have embedded a 3rd party application in Joomla and by temporarily changing the php environment within the application.
I am able to get joomla html and insert the 3rd party html by replacing a token.
Simplified Code:
if ($_SERVER['REQUEST_METHOD'] == 'GET' ) {
$_SERVER['REQUEST_METHOD'] = '';
}
$_SERVER['REQUEST_URI'] = '/joomla/index.php?view=mycom&option=com_mycom&Itemid=103';
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = '/joomla/index.php';
$_SERVER['QUERY_STRING'] = 'view=mycom&option=com_mycom&Itemid=103';
ob_start();
require_once '/joomla/index.php';
$joomlaHTML = ob_get_clean();
echo str_replace($replacementToken, $thirdPartyHTML, $joomlaHTML);
In v1.5.x, the menu item with ID 103 is properly highlighted but in v2.5.6, it isn't and the Home item is always highlighted. I think it used to be highlighted correctly in v1.6.x and earlier versions of 2.5.x as well but not sure.
I wanted to find how the process flows (where this is set) so I can see what tweaks I need to make.
DELETED WRONG INFO
Thanks Dayo! you saved my day with this:
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
I don't fully understand the breadcrumb part, but I managed to get it working by editing my component's controller.php to read:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
// force fix the breadcrumb
$app = JFactory::getApplication('site');
$pathway =& $app->getPathway();
$bcrumbs = &JPathway::getInstance('site');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* MyCom Component Controller
*/
class MyComController extends JController
{
}
Look in the following File
Check the
/modules/mod_menu/mod_menu.php
File and you will see two functions has been called "getActive" and "getDefault"
Which can be find in following file
/libraries/joomla/application/menu.php
I think it can be customized easily now

Custom module in magento with multiple tab in admin

I have created a module in "Magento"in this module I have successfully added mutiple tab as tab appear on product page when we add a product(ex.general,inventory).
In my module I want to apply a feature on selected products.for this I want to show product listing as it as appear when we click on related product (When we add new product).
For this I did the same coding as it is on catalogue controller.
But still there is a error occur.
I have added following code on my controller page
public function relatedAction()
{
$gridBlock = $this->getLayout()->createBlock('customoption/adminhtml_edit_tab_related')
->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'related')));
$iTemplateId = $this->getRequest()->getParam('template_id');$product2tpl = Mage::getResourceModel('customoption/customoption');
$productsArray = $product2tpl->getTemplateProducts($iTemplateId);
$serializerBlock = $this->_createSerializerBlock('links[related]', $gridBlock, $productsArray);
$this->_outputBlocks($gridBlock, $serializerBlock);
}
I have also extend the class Mage_Adminhtml_Controller_Action and following error occure when click on related tab.
"Call to a member function setGridUrl() on a non-object"
Please guide me where i am wrong.
Thanks in advance.

How do you use JRoute in Joomla to route to a Search menu item?

I am trying to create a a box in a template in Joomla! that will display all of the keywords and link them to their appropriate search page. I have a menu item set, however, I don't want to hard-code the menu item into the template, so I want to use the JRoute object to generate the SEF url.
I am using this function:
JRoute::_('index.php?option=com_search&searchword='.$keyword);
or this:
JRoute::_('index.php?option=com_search&view=search&searchword='.$keyword);
however, this generates a url like this:
/component/search/?searchword=africa
when it ought to create a search url like this:
/searchmenuitem?searchword=africa
I have searched extensivly online and havn't found a solution to this problem. Any ideas would be greatly appreciated.
Ok, so some additional information for you.. I am only experiencing the problem when I try and route the URL from a template in com_content. If I try and route the url from a template in com_search everything works perfectly. So, what is it about com_content that is causing this to not work properly?
thanks!
david
In joomla administration page go to the menu item you've chosen for the search results page and get the id of that menu item (itemId).
Than you can try using:
JRoute::_('index.php?option=com_search&view=search&Itemid=256&searchword=asdsadasdsa');
or even
JRoute::_('index.php?Itemid=256&searchword=asdsadasdsa');
both should result in: /searchmenuitem.html?searchword=asdsadasdsa
EDIT:
To make it more comforable you could add itemId as a param to your template.
There is another way, where u can get the itemId from the database (this method is required on multilingual websites). Let me know if you want it.
EDIT2:
Here it is:
$db =& JFactory::getDBO();
$lang =& JFactory::getLanguage()->getTag();
$uri = 'index.php?option=com_search&view=search';
$db->setQuery('SELECT id FROM #__menu WHERE link LIKE '. $db->Quote( $uri .'%' ) .' AND language='. $db->Quote($lang) .' LIMIT 1' );
$itemId = ($db->getErrorNum())? 0 : intval($db->loadResult());
I use this kind of method to get a menu item id of specific component and view
function getSearchItemId() {
$menu = &JSite::getMenu();
$component = &JComponentHelper::getComponent('com_search');
//get only com_search menu items
$items = $menu->getItems('componentid', $component->id);
foreach ($items as $item) {
if (isset($item->query['view']) && $item->query['view'] === 'search') {
return $item->id;
}
}
return false;
}
Then I use this method to get the sef url
function getRouteUrl($route)
{
jimport('joomla.application.router');
// Get the global site router.
$config = &JFactory::getConfig();
$router = JRouter::getInstance('site');
$router->setMode($config->getValue('sef', 1));
$uri = &$router->build($url);
$path = $uri->toString(array('path', 'query', 'fragment'));
return $path;
}
This just works in any template.
use like this
$itemid = getSearchItemId();
//returns valid sef url
$url = getRouteUrl('index.php?Itemid='.$itemid);
You really do not need to do sql on the menu table to get ids. Just search the menu object.
Try to create new menu in the joomla backend called for instance 'hidden-menu'. It will never be shown in the front. But it will be used by JRoute Then add to this menu new menuitem called 'searchmenuitem' with link to com_search. That is all. Now you can call
JRoute::_('index.php?option=com_search&view=search&searchword=asdsadasdsa');
and it will be ceonverted into this
/searchmenuitem.html?searchword=asdsadasdsa

Resources