MAGENTO : Add image field in custom module - magento

I'm creating a module and i want to add a picture in the edit page (back office), i do this :
$fieldset->addField('photo', 'image', array(
'label' => "image",
'required' => false,
'name' => 'image',
));
the input is present in the page but in my controller i don't have any information about this picture, does someone can tell me how i can do this ?
Thanks.

Refer the image upload article
http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/how_to_create_pdf_upload_in_backend_for_own_module

Related

How create and ACF form with preview button?

I hava a front end form i want to have a preview button for the form. problem is acf form generates the post id after submitting the form. So can't add a preview link
get_preview_post_link this can be used to get the preview link but it requires a iD to passed..
How can i add a preview button? may be ajax save the post as draft? and allow option to publish in the new page?
<?php
acf_form(array(
'post_id' => 'new_post',
'submit_value' => __("Create", 'acf'),
'return' => '%post_url%',
'updated_message' => __('added Successfully', 'acf'),
'post_title' => true,
'post_content' => false,
'new_post' => array(
'post_type' => 'l',
'post_status' => 'publish',
),
));
?>
Please help thanks

Magento Admin Grid - How to assign an action/function to a button?

I created a new module and I managed to list all the orders from the shop.
I also added a button (with this code).
$link= Mage::helper('adminhtml')->getUrl('adminhtml/order/sync/') .'id/$entity_id';
$this->addColumn('action_edit', array(
'header' => $this->helper('catalog')->__('Action'),
'width' => 15,
'sortable' => false,
'filter' => false,
'type' => 'action',
'actions' => array(
array(
'url' => $link,
'caption' => $this->helper('catalog')->__('Sync'),
),
)
));
I really don't know how to assign an action to this button. What I should create in my custom module ? A new controller?
I need to display something or get some data when I click this button...
thank you very much
I think you should write
public function YourActionNameAction()
{
}
in your Module controller file

Allow empty cms page content

When using a cms page in magento I sometimes need an empty content section. Most times this is for my homepage. But magento forces me to put something in content before it can be saved.
Is there a way to get magento to allow empty cms page content?
You can use an empty div or span
The Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content::_prepareForm() method dispatches the adminhtml_cms_page_edit_tab_content_prepare_form event. You can observe this event, grab the field from the form object which is passed into the event, and change its required property to false.
This is a quick and dirty fix, you should really override the admin class so you won't lose the change when you next upgrade.
Anyways, in file app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php, in function _prepareForm(), line 82, change:
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => true,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));
to
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => false,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));
add <div>‍</div> inside your empty elements to stop magento cms from removing them
Its not particularly elegant, but you can just enter and/or hide the content via CSS

Magento, load "Custom Options" without clicking on associated tab

I got a small issue with Magento :
I need to load the content of "Custom Options" during page load, not when I click on the associated tab, for a product creation. This is currently working with Ajax.
I need this because when you open the tab, it loads automatically some new options.
Tabs from General to Gift Options are loaded automatically, and the rest is load on click on the tab.
I found the class who create the content : app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php and the function : _prepareLayout().
For "Custom Options" tab you got something like that :
$this->addTab('customer_options', array(
'label' => Mage::helper('catalog')->__('Custom Options'),
'url' => $this->getUrl('*/*/options', array('_current' => true)),
'class' => 'ajax',
));
And for the autoloaded tab content you got :
$this->addTab('group_'.$group->getId(), array(
'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
->setGroupAttributes($attributes)
->toHtml()),
));
I don't figure how to use the addTab function with "content", not "url" and "class" for the "Custom Options" tab.
Does anyone already deal with that ?
Thanks a lot !
With the help of Magento Community I found that :
$this->addTab('customer_options', array(
'label' => Mage::helper('catalog')->__('Custom Options'),
'content' => $this->_translateHtml($this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_options',
'admin.product.options')->toHtml()),
));
Works like a charm.
Cheers.

Magento admin grid sending data from Action to Controller

I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?
I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.
Add this code to your Grid.php:
$this->addColumn('action',
array(
'header' => Mage::helper('yourmodulename')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('yourmodulename')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().
The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.
The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');
In terms of documentation/tutorials, have a read of this article on the website of #AlanStorm as it might help.
HTH,
JD

Resources