Custom module in magento with multiple tab in admin - magento

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.

Related

Prestashop backoffice module

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

Source model "megamenu/menutype" not found for attribute "menutype" on Magento 1.9

Our site is based on Magento 1.
We installed Mega menu extension which purchased from magestore team.
But, when we click the catalog/Manage categories on backend admin setting, we got this error.
How to solve this issue?
**There has been an error processing your request**
Source model "megamenu/menutype" not found for attribute "menutype"
/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php(386): Mage::exception('Mage_Eav', 'Source model "m...')
/app/code/core/Mage/Adminhtml/Block/Widget/Form.php(201): Mage_Eav_Model_Entity_Attribute_Abstract->getSource()
app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php(113): Mage_Adminhtml_Block_Widget_Form->_setFieldset(Array, Object(Varien_Data_Form_Element_Fieldset))
...
screenshot of error page
This issue was solved successfully.
Menutype was conflicted by old one.
We had used Peerforest_Megamenu extension on our site. Although we disabled the old mega menu extension, but this attribute was remained on our database.
So, when we installed new extension whose name is Magestore mega menu extension, that issue was occurred.
Furthermore. Peerforest_Megamenu had created some new attribute like megamenu/menutype on category table and these attribute required a model source to display the options.
When we disabled Peerforest_Megamenu, they couldn't find the their model source anymore.
I just created some new model source files for those attributes.
This is new menu type code block.
<?php
class Magestore_Megamenu_Model_Menutype extends
Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
protected $_options = array();
public function getAllOptions()
{
$this->_options[] = array('value' => 'megamenu-horizontal','label' => 'Mega Menu');
$this->_options[] = array('value' => 'megamenu-vertical','label' => 'Vertical');
return $this->_options;
}
}
Hope my answer will help others.
Thank you for your consideration.
Regards.

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.

spine.js: "Uncaught Unknown record"

I use spine.js in conjunction with the Spine.Ajax Module to load stuff via JSON from the Server. I've probably run into some syncronisation problem. I have a sidebar which just binds to the refresh and change events and then is rendered:
Survey.bind 'refresh change', #render
I also have set up some routes, which display a survey when the user accesses it via #/survey/:id. This is my controller:
class App.Surveys extends Spine.Controller
className: 'surveys'
constructor: ->
super
#append(#sidebar = new App.Sidebar) # Sidebar to select surveys
#append(#surveys = new App.SurveysStack) # Show survey details survey
#routes
'/surveys/:id': (params) ->
#sidebar.active(params)
#surveys.show.active(params)
Survey.fetch()
As you see, Survey.fetch() is called after the initialization, which does not pose a problem to the sidebar. However, it seems, that it poses a problems to the surveys Show controller (which is called by a Spine.Stack called App.SurveyStack):
class Show extends Spine.Controller
constructor: ->
super
#active #change
change: (params) =>
# There is a bug! If Survey is not fetched when we run this,
# this throws an error.
#item = Survey.find(params.id)
#render()
render: ->
#html #view("surveys/show")(#item)
I keep getting errors from the commented part of the source: Uncaught Unknown record. Can I make the Survey.find() function block until Survey.fetch() is done?
You are correct in your diagnosis that you can't find an item before you've fetched it from the server.
The easiest solution is to bind an event to the Survey.fetch() call like so:
Survey.bind 'refresh change', #method_to_call
Let me know if that helps!
Actually the solution that worked for me is to initialize the Spine.Route.setup() after the object has refreshed. Instead of the standard call in app/index.js.coffee, it would be:
App.Survey.one 'refresh', ->
Spine.Route.setup()

Is it good practice to add own file in lib/Varien/Data/Form/Element folder

I need to create module in Magento which will have few database tables. One of the function of the module is adding multiple images.
For example while being on the "Add new item" or "Edit item" page in the admin, from the left side I have tabs, one of them is "Item Images". When being clicked I want the content of this tab to be my own custom one.
After digging into the code, found out that the way it renders this content, Magento is using one of the Varien_Data_Form_Element classes for each element in the full form. I want to add my own class here that will render form elements the way I want.
Is this a good practice to do so, or there is some other more elegant way of adding own content in the admin forms?
EDIT: I must add that none of the existing classes is helping my problem.
SOLUTION EDIT:
I have a controller in my custom module that is in Mypackage/Mymodule/controllers/Adminhtml/Item.php. In the editAction() method which I am using for adding and creating new items, I am creating 2 blocks, one for the form and one left for the tabs:
$this->_addContent($this->getLayout()->createBlock('item/adminhtml_edit'))
->_addLeft($this->getLayout()->createBlock('item/adminhtml_edit_tabs'));
$this->renderLayout();
The Block/Adminhtml/Edit/Tabs.php block is creating 2 tabs on the left: General Info and Item Images, each of them are rendering different content on the right side using Block classes.
protected function _beforeToHtml()
{
$this->addTab('item_info', array(
'label' => Mage::helper('mymodule')->__('Item Info'),
'content'=> $this->getLayout()->createBlock('item/adminhtml_edit_tab_form')->toHtml(),
));
$this->addTab('item_images', array(
'label' => Mage::helper('mymodule')->__('Item Images'),
'active' => ( $this->getRequest()->getParam('tab') == 'item_images' ) ? true : false,
'content' => $this->getLayout()->createBlock('item/adminhtml_images')->toHtml(),
));
return parent::_beforeToHtml();
}
I wanted the tab item_images to render my own form elements and values, not the default varien form elements.
class Mypackage_Mymodule_Block_Adminhtml_Images extends Mage_Core_Block_Template
{
public function __construct()
{
parent::__construct();
$this->setTemplate('item/images.phtml'); //This is in adminhtml design
}
public function getPostId()
{
return $this->getRequest()->getParam('id');
}
public function getExistingImages()
{
return Mage::getModel('mymodule/item')->getImages($this->getPostId());
}
}
Then in the template app/design/adminhtml/default/default/template/item/images.phtml you can use these values:
//You can add your own custom form fields here and all of them will be included in the form
foreach($this->getExistingImages() as $_img):
//Do something with each image
endforeach;
//You can add your own custom form fields here and all of them will be included in the form
No, it's not. You should never edit or add to files that provided by a vendor. If you absolutely must replace a class file you should use the local code pool. For example, if you wanted to change the behavior of a text field,
lib/Varien/Data/Form/Element/Text.php
You should place a file in the local or community code pool
app/code/local/Varient/Data/Form/Element/Text.php
However, doing the replaces the class, and it becomes your responsibility to maintain compatibility with future versions. That means if Magento Inc. changes lib/Varien/Data/Form/Element/Text.php, you need to update your version to be compatible.
Based on what you said I'd look into creating a class rewrite for the Block class that renders the form.

Resources