No Delete button when editing an item in Magento Grid - magento

I've successfully created my first admin grid. It works fine when adding a new item. However, when I want to edit an item, strangely, the DELETE button is missing. Even worse, when I click the SAVE button, it creates a new item instead of saving the current item. What have I done wrong?
I'm not sure what file to look at, thus I don't know which code must be posted here. If I put all the code from all files, it will be too much. Please advise.
Update: Not sure why, but now the SAVE button doesn't recreate any more. So I can edit an item peacefully. However, the DELETE button is still missing.

Late in the game, but hopefully this will help a Googler.
Is your _objectId property correctly set to the corresponding parameter in the URL?
$this->_objectId = 'id';
Where ID refers to this part of the URL:
/module/adminhtml_controller/edit/id/1/
See the parent class Mage_Adminhtml_Block_Widget_Form_Container::__construct:
...
$objId = $this->getRequest()->getParam($this->_objectId);
if (! empty($objId)) {
$this->_addButton('delete', array(
'label' => Mage::helper('adminhtml')->__('Delete'),
'class' => 'delete',
'onclick' => 'deleteConfirm(\''. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
.'\', \'' . $this->getDeleteUrl() . '\')',
));
}
...
We can see that if $objId is empty, no delete button will be added.

After struggling around, the culprit was because I put parent::__construct(); at the top (right after the __construct() method. Instead, it should be put AFTER the $this->_controller line. Geezz...

***Remove or rename add new save continue delete button from magento admin
If you don’t want to show the ‘Add New’ button in the Grid. The Add New button is present in top right corner of Grid Page.
Rename ‘Add New’ button
Here are the steps to rename the ‘Add New’ text to anything you required (for example, ‘Add Report’):-
Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.phenter code herep
Add the following code in the constructor of this file:-
$this->addButtonLabel = Mage::helper('yourmodulename')->_('Add Report');
Remove ‘Add New’ button
Here are the steps to remove the ‘Add New’ button:-
Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
Add the following code in the constructor of this file (it should be just below the call to parent constructor):-
parent::__construct();
$this->_removeButton('add');
In edit.php
parent::__construct();
$this->_removeButton('delete');
$this->_removeButton('save');
$this->_removeButton('back');
in grid.php
parent::__construct();
$this->_removeButton('add');

Try on your Grid.php:
public function getRowUrl($row){
return $this->getUrl('*/*/form', array('id' => $row->getId()));
}

Related

Joomla Component Creating an override for the trash button

I'm trying to override the trash button in the administrator back end in Joomla
I'm putting into the controller:
public function trash( $task = 'trash', $alt = 'trash', $check = true ){
echo "here";
exit();
}
(I've also tried it with task = remove)
But I can't get it to work. Joomla ignores this and simply deletes the field.
I've already put in a save override and save2copy but I can't figure out why this won't work. Can someone help?
thanks
I found the problem - thanks to those who've thought about it.
I'd used an auto component generator and when they had created the class they hadn't included a constructor function. So I added one and it now works fine.

Don't want remove wishlist items when click 'Add all to cart' button - magento

I change in code follow this http://www.magentocommerce.com/boards/viewthread/197868/
to keep items in wishlist when user add item to cart.
But If user add all to cart instead of each item. All product will be remove from wishlist.
I want to keep it in wishlist. Have any know how to fix it?
I try to open app\code\core\Mage\Wishlist\Controller\Abstract.php and comment out lines
$item->delete();
But nothing better.
I'd appriciate your helping.
Try this,
Step 1:
While adding allitems from wishlist to cart, there is no way to rewrite abstract file. so copy the file from
app\code\core\Mage\Wishlist\Controller\Abstract.php
to
app\code\local\Mage\Wishlist\Controller\Abstract.php
Then find inside Abstract.php
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
set $isOwner to false.Update the code as
$isOwner = false;
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Step 2:
While adding individual items from wishlist to cart.
Follow the below steps
Rewrite the Mage_Wishlist_IndexController to local codepool
Then find the code in the rewrited controller file
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Update the code as
$isOwner = false;
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Now wislist items will retain even after add to cart.
Refer this link
Tought about that too, but figured out that the deletion happens on line 108 in Mage_wishlist_Controller_Abstract
// Add to cart
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->
}
In your Wishlist the $isOwner is set to true and that's the reason why your items get removed.
set $isOwner is set to false to stop the items get removed
The way I solved this instead of overwriting or editing a abstract core file like some comments suggest I instead did a rewrite of the Wishlist controller:
Mage/Wishlist/controllers/IndexController.php
If you look in the cartAction function on you will find the following line $item->addToCart($cart, true);. The second parameter being sent here decides if the item should be deleted from the wishlist or not. If you in your rewritten controller set this to false the items will persist in the wishlist even though you add them to your cart.

Execute action (task) in a toolbar button joomla 2.5

i am trying to modify the com_phocamaps to add the "Copy marker" action.
I have created the button modifying function addToolbar with this line JToolBarHelper::customX( 'phocamapsmarker.copy', 'copy.png', 'copy_f2.png', 'Copy Marker' ); in the com_phocamaps/views/phocamapsmarkers/view.html.php but i don´t know where i have to set the action to execute de COPY task.
When I click this new button, Joomla throws a 500 Error.
I want to implement a litle function to copy the marker and set Publish = 0 to change the map.
Thanks
you need to write that function in controller
go to administrator\components\com_phocamaps\controllers\phocamapsmarker.php
and write this function
function copy(){
// your code here
}

MVCContrib grid value is always null when HTML.ActionLink is clicked

I'm trying to implement a simple listview / detailview feature in one of our apps. I'm using the MVCContrib Grid (which btw is awesome!) to show the list of items. There's an edit link next to every row on the grid that allows the user to edit the item. When the users click the edit link I execute a Get that returns the details form used to editing the item. For some reason I cannot get the clicked customerId to be sent to the controller. The controller just gets null every time I click the edit link.
My grid is configure like so:
Html.Grid(Model.CheckAccounts)
.Columns(column.For(c => {Html.ActionLink(
"Edit",
"CustomerDetails",
"CustomerManagementController",
new {Id=customer.Id}));
column.For(c => c.Name);
column.For(a => c.AccountNumber);
}).Render();
Here's My controller Action:
[HttpGet]
public ActionResult CustomerDetails(long? Id )
{
//fetch the customer from repo...
//return it to the client
return View(model);
}
I'm totally confused since all the samples and blogs I've seen, access data from the grid the same way I'm doing it. Can someone help?
I hate to answer my own question but I was able to fix this by changing the action link to:
{Html.ActionLink(
"Edit",
"CustomerDetails",
"CustomerManagement",
new {Id=customer.Id}));
I realized the wrong action link was being generated after looking at the "?Length=24" queryString parameter at the end of the URL.
The grid is working as expected now.

Hide a group in catalog product?

Please help me if anybody know how this work can be done.
I want to hide the website tab in catalog Product, but its functionality should exist. That is, I have made all the check boxes automatically checked,so i dont want to show this tab anybody...but at the time of adding product..check boxes values would be saved.
Not exactly sure how you would do this, but basically you need to bind an Observer in the adminhtml render sequence that calls Mage_Adminhtml_Block_Widget_Tabs::removeTab($tabId) where $tabId is the Id of the websites tab (I think it's just "websites"). The trick is to find the right event to bind your Observer to, #Joseph's list of events should get you started. I would try something like adminhtml_block_html_before.
Your observer would also set the values on the product at the same time.
Good luck,
JD
In ProductController.php
Websites
*/
if (!isset($productData['website_ids'])) {
$productData['website_ids'] = array();
}
$productData['website_ids']=$this->getStoreWebsiteId(); //newly added
//newly added
public function getStoreWebsiteId(){
$selectWebsite="SELECT * from core_website WHERE website_id!=0";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$connection->fetchAll($selectWebsite);
foreach($value as $websiteDetails){
$websiteId[]=$websiteDetails['website_id'];
}
return $websiteId;
}

Resources