change checkout page headings in Magento - magento

How can I change the checkout page headings in Magento?

Of course, the simplest way is to change this headings in translation file (Mage_Checkout.csv). But if you want to use some custom labels, and you don't want to conflict with native translations for other blocks on checkout, you should update those labels:
these classes are located in app/code/core/Mage/Checkout/Block/Onepage.
Billing.php
Shipping.php
Payment.php
Review.php
You can change label in _construct() method.
For example:
class Mage_Checkout_Block_Onepage_Review extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
$this->getCheckout()->setStepData('review', array(
'label' => Mage::helper('checkout')->__('Order Review'), // your custom label here
'is_show' => $this->isShow()
));
parent::_construct();
$this->getQuote()->collectTotals()->save();
}
}
You can override those classes.

Related

Magento Form with Tabs Fieldset Issue

I'm writing a custom Magento module for my store and I'm facing a weird issue with a fieldset in one form. The form is assigned to a tab, however the fieldset starts from the top of container, not from just below buttons area. Please see the image attached
I want it to display like:
This module is being developed on Magento 1.9.0.1 without any modification whatsoever, just the demo data.
Below is the code for all the classes:
Controller:
added form container and tabs to left column
class Koala_Socialmanager_Adminhtml_TwitterController extends Mage_Adminhtml_Controller_Action {
public function directTweetAction(){
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('koala_socialmanager/twitter_directTweet_tweet','directTweet'))
->_addLeft($this->getLayout()->createBlock('koala_socialmanager/twitter_directTweet_edit_tabs'));
$this->renderLayout();
Form container:
class Koala_Socialmanager_Block_Twitter_DirectTweet_Tweet extends Mage_Adminhtml_Block_Widget_Form_Container {
public function __construct()
{
$this->_blockGroup = 'koala_socialmanager';
$this->_controller = 'twitter_directTweet';
$this->_headerText = Mage::helper('koala_socialmanager')->__('Direct Tweets');
parent::__construct();
$this->_updateButton('save', 'label', Mage::helper('adminhtml')->__('Tweet Now!'));
}
}
Tabs:
class Koala_Socialmanager_Block_Twitter_DirectTweet_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs{
public function __construct(){
parent::__construct();
$this->setId('tweetTabs');
$this->setDestinationElementId('edit_form');
$this->setTitle(Mage::helper('koala_socialmanager')->__('Twitter'));
}
public function _beforeToHtml(){
$this->addTab('form_section_form',array(
'label' => Mage::helper('koala_socialmanager')->__("Tweet"),
'title' => Mage::helper('koala_socialmanager')->__("Tweet"),
'content' => $this->getLayout()->createBlock('koala_socialmanager/twitter_directTweet_edit_tabs_form')->initForm()->toHtml(),
'active' => true
));
$this->addTab('form_section_external_media',array(
'label' => Mage::helper('koala_socialmanager')->__("External Media"),
'title' => Mage::helper('koala_socialmanager')->__("External Media"),
'content' => $this->getLayout()->createBlock('koala_socialmanager/twitter_directTweet_edit_tabs_externalMedia')->initForm()->toHtml()
));
$this->addTab('form_section_magento_media',array(
'label' => Mage::helper('koala_socialmanager')->__("Magento Product Media"),
'title' => Mage::helper('koala_socialmanager')->__("Magento Product Media"),
'content' => $this->getLayout()->createBlock('koala_socialmanager/twitter_directTweet_edit_tabs_magentoProductMedia')->toHtml()
));
return parent::_beforeToHtml();
}
}
And form with fieldset:
class Koala_Socialmanager_Block_Twitter_DirectTweet_Edit_Tabs_Form extends Mage_Adminhtml_Block_Widget_Form {
public function __construct()
{
parent::__construct();
}
public function initForm(){
$form = new Varien_Data_Form();
$this->setForm($form);
$form->setHtmlIdPrefix('socialmanager');
$helper = Mage::helper('koala_socialmanager');
$fieldset = $form->addFieldset('base_fieldset', array(
'legend' => Mage::helper('koala_socialmanager')->__('Tweeter Message')
));
$fieldset->addField('statusUpdate', 'textarea', array(
'name'=>'tweet',
'label'=>$helper->__("Tweet this Message:"),
'after_element_html'=>'<div class="characterCounter">0</div>'
));
Mage::helper('koala_socialmanager')->getTwitterFormScript();
return $this;
I believe I'm missing something silly. Any help appreciated.
Cheers
Paul
I've solved the problem, still don't know the cause though. I simply rewritten everything to another folder changing the class names, created another action in controller called testAction, so all files from DirectTweet folder are located in Message folder, and guess what? when you display that form from testActoin it works as it should, when I display the old form from DirectTweet folder - fieldset is broken.
I have magento cache disabled all the time, I cleared all tmp, cache, session folders, cleared browser cache and had no luck with fixing it, so I'm wondering why the new "version" works even though there is no changes to the code apart from cosmetic ones (removing empty lines, or changed text for labels/headers).
For the last 20 minutes I was comparing file by file in phpstorm, and seriously no differences apart from class names and texts to output.... I'm to tired to think about it anymore.
Below desired output :)
Happy New Year
Paul

Magento rewrite an existing form and update an existing field

I want to update an existing form in Magento backend. Because I don't want to touch the original extension I copied the file and rewrote the class:
class Bleedo_xta_Block_Adminhtml_xta_Edit_Tab_information extends Hedox_xta_Block_Adminhtml_xta_Edit_Tab_information {
protected function _prepareForm() {
parent::_prepareForm();
$form = $this->getForm();
This works (if you found this article via Google, don't forget to insert this rewrite in your config.xml)
If I want to add a new field to this form you can easily do this by
$options = $form->getElement('options_form');
$options->addField('new_cost', 'text', array(
'name' => 'new_cost',
'label' => $this->__('New Cost'),
));
But how can I update an existing field? The problem is that I want to set an already existing field to "required". But if I'm using addField I get an error.
Thank you so much!
/* #var $elm Varien_Data_Form_Element_Text */
$elm = $this->getForm()->getElement('new_cost');
$elm->setData('required',1);

CakePHP - Where to put reusable custom validation rules?

I want to add a custom validation rule that can be reused across the application when necessary. Where is the best place to put it?
I know I can put them in AppModel but it's messy and pollutes/bloats the AppModel with methods that are only used occasionally for validation, and I find I need to prefix them all with validateUsername, validateCustom, etc. to keep them clearly organised from the other methods in the AppModel. I feel like there is a better way of doing this in the OOP structure.
Is there a way to specify custom rules as static methods of a Lib class, for example?
e.g.
app/Lib/Validate.php
class Validate {
public function username($value) {
$value = array_shift($value);
return preg_match('/^[A-Z0-9_-]+$/i', $value);
}
}
And then use the rules only in the models when you need to:
app/Model/MyModel.php
App::uses('Validate', 'Lib');
class MyModel extends AppModel {
public $validate = array(
'username' => array(
'rule' => 'Validate::username',
'message' => 'Username contains invalid characters'
)
);
}
You could do this with a Behavior. http://book.cakephp.org/2.0/en/models/behaviors.html There is a setup callback you could use to attach validation rules or create your own custom functions. You can then attach the Behaviors as needed to models.

Magento: Add Widget tool onto product and category WYSIWYG

On the WYSIWYG editor for CMS pages in Magento there's a tool to add Magento widgets to the editor. I'd like this also to be available for the WYSIWYG on the product and category descriptions.
I'm struggling to find where the editor is even loaded at the moment. Could anyone let me know what I might have to do or at least point me in the right direction?
Thanks in advance.
After enabling add_widgets and add_variables in class Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content as per #David Manner's answer, you will likely find that whilst this will certainly enable these in the WYSIWYG editor and function properly, it will only render the raw widget/variable code in the front end (rather than the appropriate markup).
You can fix with the following:-
Navigate to /app/design/frontend/package/theme/template/catalog/category/view.phtml
Find <?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
Add the following below this line:-
<?php
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$_description = $processor->filter($_description);
?>
This will render in the frontend correctly then.
Under the class Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content there are two flags in the config array 'add_widgets' and 'add_variables'. Both of these are set to false by default.
Setting these to true will then be caught in the Mage_Widget_Model_Observer class function prepareWidgetsPluginConfig on the event cms_wysiwyg_config_prepare.
I would suggest rewriting the Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content to fit your needs, but setting add_widgets and add_variables to true should work for both categories and products.
After read all answers I found elegant solution. This solution rewrite only one Block class and doesn't change any template file.
Rewrite Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content
<config>
...
<global>
<blocks>
...
<adminhtml>
<rewrite>
<catalog_helper_form_wysiwyg_content>Agere_Wysiwyg_Block_Widget_Anywhere</catalog_helper_form_wysiwyg_content>
</rewrite>
</adminhtml>
</blocks>
...
</global>
</config>
Change only two flags in the config array 'add_widgets' and 'add_variables' to true
class Agere_Wysiwyg_Block_Widget_Anywhere extends Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content {
protected function _prepareForm() {
//return parent::_prepareForm();
$form = new Varien_Data_Form(array('id' => 'wysiwyg_edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
$config['document_base_url'] = $this->getData('store_media_url');
$config['store_id'] = $this->getData('store_id');
$config['add_variables'] = true;
$config['add_widgets'] = true;
$config['add_directives'] = true;
$config['use_container'] = true;
$config['container_class'] = 'hor-scroll';
$form->addField($this->getData('editor_element_id'), 'editor', array(
'name' => 'content',
'style' => 'width:725px;height:460px',
'required' => true,
'force_load' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig($config)
));
$this->setForm($form);
return $this;
}
}
Create handler that will process content from category or product
class Agere_Wysiwyg_Helper_Filter extends Mage_Core_Helper_Abstract {
public function categoryAttribute($mainHelper, $result, $params) {
return $this->process($result);
}
public function productAttribute($mainHelper, $result, $params) {
return $this->process($result);
}
public function process($result) {
/** #var Mage_Cms_Helper_Data $helperCms */
$helperCms = Mage::helper('cms');
$processor = $helperCms->getPageTemplateProcessor();
return $processor->filter($result);
}
}
Finally create Observer wich add handlers for out wysiwyg
class Agere_Wysiwyg_Model_Observer extends Varien_Event_Observer {
public function addWysiwygHandler(Varien_Event_Observer $observer) {
/** #var Mage_Catalog_Helper_Output $_helperOutput */
/** #var Agere_Wysiwyg_Helper_Filter $_helperFilter */
$_helperOutput = Mage::helper('catalog/output');
$_helperFilter = Mage::helper('agere_wysiwyg/filter');
$_helperOutput->addHandler('categoryAttribute', $_helperFilter);
$_helperOutput->addHandler('productAttribute', $_helperFilter);
}
}
Full snap of code see by link https://github.com/popovsergiy/magento-wysiwyg
Think a better way is to create a new observer that listening on the same event, and make the module depending on Mage_Widget. Then our observer will be running after Mage_Widget

Magento: How to know many blocks are cached

i cached my custom block inherit of Mage_Core_Block_Template. I cached the bloc with the next constructor:
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => 120,
'cache_tags' => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG),
));
}
Right, i want verify that this block is cached. How i can list all block cached in my Magento.
I want a similar instruction:
var_dump($this->getLayout()->getUpdate()->getHandles());exit;
to see all layout , in blocks cached.
thx.
You can specify cache_key for your block:
protected function _construct()
{
$this->addData(array(
'cache_key' => 'some_static_or_dynamic_key', // can be static or dynamic
'cache_lifetime' => 120,
'cache_tags' => array(
Mage_Core_Model_Store::CACHE_TAG,
Mage_Cms_Model_Block::CACHE_TAG),
)
);
}
And then you can ensure that block is cached by calling:
Mage::app()->loadCache('your_cache_key');
Here is good article about blocks caching.
To see if Magento created your cache, you could search for the file that contains in it's name your tags in the var folder. Also make sure you have your cache activated for this to work.

Resources