Reputation: 12877
I need 2 things done for Magento that should have been done by the official team.
How can I add links to individual product pages for at the end of each product row at Catalog -> Manage Products? Just like WordPress, authors / administrators can easily click to open the post page for each post in the post list. I'm not even sure which phtml file I should edit.
How to add a “Edit Product” link on the individual product page that leads to the editor of the product when privileged administrator is logged in? Just like WordPress, the meta lines of each post page should have a “Edit Post” link that leads to the editor of the post. I know I should edit catalog/product/view.phtml but how to programmatically get the backend editor link of the current product?
Can someone please tell me how I can achieve these 2 things? Thanks a lot!
Upvotes: 0
Views: 3730
Reputation: 89
The below might help you get some of the way, allows you to view product in frontend from backend product edit page:
http://inchoo.net/ecommerce/magento/view-product-in-frontend-from-magento-admin/
Upvotes: 1
Reputation: 12877
Finally got the first problem resolved myself. Detailed instructions can be found here: http://www.magentogoreview.com/add-view-product-page-link-to-products-list-at-catalog-manage-products~280
But still looking for the answer of the second problem. Will update this when I have it.
Upvotes: 1
Reputation: 3694
I can totally understand why have you requested the logic, but unfortunately it will be not so easy to achieve... Though you can easily get to work step 1, step 2 will be a little problematic, since Magento in opposite to WP has separate sessions for Frontend and Admin parts. So on Frontend you wouldn't be able to identify logged in site administrator, and therefor - show him the link. But let's address things in order:
To achieve step 1 you'll need to modify 2 files. Please remember, that it's better not to modify files in core, but instead move them to local folder, preserving the directory structure. First change: Mage_Adminhtml_Block_Catalog_Product_Edit::_prepareLayout
(file app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit.php). Just before the return statement return parent::_prepareLayout();
add next code:
$this->setChild('view_product',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('catalog')->__('View Product'),
'onclick' => "popWin('".$this->getProduct()->getProductUrl(false)."', 'popwin','width=800,height=600,resizable=yes,scrollbars=yes')",
'class' => 'save'
))
);
Then open app\design\adminhtml\default\default\template\catalog\product\edit.phtml template and add next code <?php echo $this->getChildHtml('view_product')?>
inside the <?php if($this->getProductId()): ?>
case. So it will look like this:
<?php if($this->getProductId()): ?>
<?php echo $this->getDeleteButtonHtml() ?>
<?php if($this->getProductSetId() && $this->getIsConfigured()): ?>
<?php echo $this->getDuplicateButtonHtml() ?>
<?php endif; ?>
<?php echo $this->getChildHtml('view_product')?>
<?php endif; ?>
Step 1 is complete, now you should be able to see View Order button on your Product Management screen.
Now since Magento can't see administrators on Frontend, you can create Frontend Administrator customer group to handle that. You can create a customer group in "Customer/Customer Groups" node. Then in catalog/product/view.phtml add next code at the bottom of the file:
<?php if (Mage::helper('customer')->isLoggedIn()):?>
<?php /** @var $customer Mage_Customer_Model_Customer */?>
<?php $customer = Mage::helper('customer')->getCustomer();?>
<?php if ($customer->getGroupId() == /your_new_group_id/):?>
<a href="<?php echo Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/catalog_product/edit', array('id' => $this->getProduct()->getId()))?>" target="_blank">
<?php echo $this->__('Edit Product')?></a>
<?php endif;?>
<?php endif;?>
Just don't forget to change /your_new_group_id/ with actual Administrators customer group id. Also - if you're not logged in into Admin panel, it will ask you to log in, since as I've mentioned before the sessions are not connected.
Good luck!
Upvotes: 0
Reputation: 2790
1 - When you click on line he just redirect you to edit product page. But if you want put on link on each product line to edit page, its hard thing to do. Ill think about if i found something i edit here.
2- On your phtml file, you can call:
<a href="<?php echo Mage::getBaseUrl().'/admin/catalog_product/edit/id/'.$_product->getId()?>">Link to edit product.</a>
Upvotes: 0