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

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.

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 confirmation popup on invoice creation

I am trying to add a confirmation popup on to a existing button in the Magento Admin. When you press capture it shout ask if you are sure. I have found the code of the button in the adminhtml folder and dont know further. I have found out that you can use the onclick parameter to start a js function but that parameter is already set by magento.
Here is the code of the button
if ($this->_isAllowedAction('capture') && $this->getInvoice()->canCapture()) {
$this->_addButton('capture', array(
'label' => Mage::helper('sales')->__('Capture'),
'class' => 'save',
'onclick' => 'setLocation(\''.$this->getCaptureUrl().'\')'
)
);
}
'onclick' => "confirmSetLocation('Are you sure you want to do this?', '{$this->getUrl('*/*/delete')}')",
You have to replace 'onclick' => 'setLocation(\''.$this->getCaptureUrl().'\')'
with 'onclick' => "confirmSetLocation('{$message}', '{$this->getCaptureUrl()}')",

How to get a list of cms pages in Magento?

What i'm trying todo
I have created an admin form where the user needs to select a CMS page from a drop down.
What i have tried
$form->addField('cms_page_id', 'select', array(
'label' => Mage::helper('custom/data')->__('CMS Page'),
'class' => 'required-entry',
'required' => true,
'name' => 'cms_page_id',
'values' => Mage::getSingleton('cms/page')->toOptionArray(),
'value' => $this->getCmsPageId()
));
The idea is the code gets the an option array from the CMS model. However "toOptionArray" is an invalid function for the 'cms/page' model.
My Question
How can I get an option array of CMS pages for use in an admin form in Magento?
With your code you are loading a new cms page model. To get a collection use following code and toOptionArray() will at least return something:
Mage::getModel('cms/page')->getCollection()->toOptionArray()
CMS Pages array with Links
$cms_arr = Mage::getModel('cms/page')->getCollection()->toOptionArray();
$cms_pages[""] = "-Select CMS Page-";
foreach($cms_arr as $cms){
$url = $this->getUrl($cms["value"]);
$cms_pages[$url] = $cms["label"];
}

MAGENTO : Add image field in custom module

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

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

Resources