Friday, May 10, 2013

List of Magento Admin Form Fields


Text Field
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$fieldset->addField('title', 'text', array(
    'label'     => $this->__('Title'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => 'This is text...',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "alert('On Click');",
    'onchange'  => "alert('On Change');",
    'style'     => "border:5px",
    'after_element_html' => '<small>Comment<small>',
    'tabindex'  => 1
));
Text Area
1
2
3
4
5
6
7
8
9
10
11
12
13
$fieldset->addField('textarea', 'textarea', array(
    'label'     => $this->__('TextArea'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Password
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$fieldset->addField('password', 'password', array(
    'label'     => $this->__('Password'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "",
    'value'     => 'mojojojo',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Obscure Password
1
2
3
4
5
6
7
8
9
10
11
12
$fieldset->addField('obscure', 'obscure', array(
    'label'     => $this->__('Obscure'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'obscure',
    'value'     => '04021993',
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Radio Button
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$fieldset->addField('radio', 'radio', array(
    'label'     => $this->__('Radio'),
    'name'      => 'title',
    'value'     => '1',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",         
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
$fieldset->addField('radio2', 'radios', array(
    'label'     => $this->__('Radios'),
    'name'      => 'title',
    'values'    => array(
                      array('value'=>'1','label'=>'Radio1'),
                      array('value'=>'2','label'=>'Radio2'),
                      array('value'=>'3','label'=>'Radio3'),
                 ),
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'value'     => '2',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Checkbox
1
2
3
4
5
6
7
8
9
10
11
$fieldset->addField('checkbox', 'checkbox', array(
    'label'     => $this->__('Checkbox'),
    'name'      => 'Checkbox',
    'checked'   => false,
    'value'     => '1',
    'disabled'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 3
));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$fieldset->addField('checkboxes', 'checkboxes', array(
    'label'     => $this->__('Checkboxes'),
    'name'      => 'Checkbox',
    'value'     => '2',
    'values'    => array(
                      array('value'=>'1','label'=>'Checkbox1'),
                      array('value'=>'2','label'=>'Checkbox2'),
                      array('value'=>'3','label'=>'Checkbox3'),
                 ),
    'onclick'   => "",
    'onchange'  => "",
    'disabled'  => false,
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 4
));
Dropdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$fieldset->addField('select', 'select', array(
    'label'     => $this->__('Select'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '1',
    'values'    => array('-1'=>'Please Select','1' => 'Option1', '2' => 'Option2', '3' => 'Option3'),
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Dropdown v2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$fieldset->addField('select2', 'select', array(
    'label'     => $this->__('Select v2'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'value'     => '4',
    'values'    => array(
                          '-1'=>'Please Select..',
                          '1' => array(
                                   'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
                                   'label' => 'Size'   
                                 ),
                          '2' => array(
                                   'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
                                   'label' => 'Color'  
                                 ),                                         
                     ),
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Multiselect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$fieldset->addField('multiselect2', 'multiselect', array(
    'label'     => $this->__('Select Type2'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'onclick'   => "return false;",
    'onchange'  => "return false;",
    'disabled'  => false,
    'readonly'  => false,
    'value'     => '3',
    'values'    => array(
                          '-1'=> array( 'label' => 'Please Select..', 'value' => '-1'),
                          '1' => array(
                                   'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
                                   'label' => 'Color'   
                                 ),
                          '2' => array(
                                   'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
                                   'label' => 'Size'  
                                 ),                                         
                     ),
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 10
));
Multiline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$fieldset->addField('multiline', 'multiline', array(
    'label'     => $this->__('Multi Line'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => 'Hello galaxy!',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "border:5px",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));
Label
1
2
3
$fieldset->addField('label', 'label', array(
    'value'     => $this->__('Label Text'),
));
Link
1
2
3
4
5
6
7
$fieldset->addField('link', 'link', array(
    'label'     => $this->__('Link'),
    'style'     => "",
    'href'      => 'http://www.brymayor.com/',
    'value'     => 'My Blog',
    'after_element_html' => '<small>Comment</small>',
));
Note
1
2
3
$fieldset->addField('note', 'note', array(
    'text'     => $this->__('Hello galaxy!'),
));
Submit Button
1
2
3
4
5
6
7
$fieldset->addField('submit', 'submit', array(
    'label'     => $this->__('Submit'),
    'required'  => true,
    'value'     => 'Submit',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 15
));
Time
1
2
3
4
5
6
7
8
9
10
11
12
13
$fieldset->addField('time', 'time', array(
    'label'     => $this->__('Time Title'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '04,00,00',
    'onclick'   => "",
    'disabled'  => false,
    'readonly'  => false,
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 3
));
File Upload
1
2
3
4
5
6
7
8
$fieldset->addField('file', 'file', array(
    'label'     => $this->__('Uploader'),
    'value'     => 'Uploader',
    'disabled'  => false,
    'readonly'  => false,
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 5
));
Image Upload
1
2
3
$fieldset->addField('image', 'image', array(
    'value'     => 'http://brymayor.com/wp-content/uploads/2013/02/default-logo.png',
));
Date
1
2
3
4
5
6
7
$fieldset->addField('date', 'date', array(
    'label'     => $this->__('Date'),
    'after_element_html' => '<small>Comment</small>',
    'image'     => $this->getSkinUrl('images/grid-cal.gif'),
    'format'    => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
    'tabindex'  => 2
));

All the different type of form fields available in Magento can be found in lib/Varien/Data/Form/Element.

Thursday, April 25, 2013

Paypal payment integration in php source code example

Paypal Integration in PHP example source code 

In php web development payment gateway integration is one of the most important part. For developing any e-commerce based website or any interview this particular module is must. A php developer who does not know any payment gateway integration has already moved to the waiting list.
As its so important, better we should learn it very carefully. I can promise it will not only Increase our confidence in work but also helps to get a good salary package.
The name which comes first among payment gateways is Paypay . It’s a totally free payment gateway and its really easy to integrate in your php system.
For Implementing paypal in your own core php the only class file you need is paypal.class.php .

Visit this following link and enjoy!!!!

Tuesday, April 16, 2013

Magento Session Storage: Which to Choose and Why?


In this article I will compare the four different built-in methods for Magento session management. These are: file-storage (the default), database, memcached and tmpfs-backed file-storage.
Admittedly, the tmpfs-backed file-storage method is only tenuously ‘built-in’, to use it you have to mount an in-memory filesystem but I wanted to benchmark it here anyway, and cover some of the benefits and limitations it offers.
So we’ll look firstly at each of the four methods being compared – particularly what they are good for (and not good for), and then I’ll get straight in to some benchmarks.
Not at all coincidentally, I’ll be using my new Magento Speed Testing tool to benchmark each session storage option. <plug> I just launched the premium subscription last week, you can now performance test your own Magento store from multiple data-centers globally for only $5/month. Give it a try on your own store, the results may surprise you. </plug>

30 Second Introduction to Sessions (and Session Storage)

When you go back to a Magento store a few days after browsing it, and the items you added to cart are still in the cart – that’s sessions!
Sessions are user-specific data that is stored on the server for each client. The server maps clients to their sessions with a cookie (or in dire, cross-domain cases, by a SID in the url).
How quickly data can be put in and got out of the session storage, how volatile it is, and how it is distributed in a clustered environment are all important considerations when choosing how to store sessions.
Thankfully Magento provides multiple options out-of-the-box. Let’s take a look at those…

Filesystem Session storage

Remember that innocuous setting during Magento install that asks you if you want to store your sessions on disk or in the database? Well if you are like me, you normally choose filesystem, not knowing any better and having never bothered to test or research the consequences (until now)
The benefits of file-based sessions for Magento are simplicity, stability and durability. It’s simple because you don’t have to do anything to set it up. It’s stable because most modern filesystems use journaling to make sure that in the event of a system crash your session data is consistent. It’s also durable, because a system restart will not cause you to lose your session data. Coming back to a webstore a week later and not having your items in your cart is annoying, right?
To enable file-based storage, choose it during installation or in your app/etc/local.xml file simply make sure you have a session_save tag like this:
1
<session_save><![CDATA[files]]></session_save>
Note: Look in app/etc/local.xml.additional for examples but ignore the comment about empty defaulting to files, you need the word files in there.
I have performance benchmarked filesystem storage in the Benchmark section below.

Database Session storage

Database session storage is the other storage type, the one you probably didn’t choose during install, and forgot to circle back round and find out if you should have. With database session storage the session data is stored in the Magento MySQL database. The connection used is the same as the core connection.
One of the key benefits of using database sessions is the clustered environment support. In a filesystem based session storage scheme, if you have more than one Magento frontend node in a cluster, they will need to share session data (unless you use a loadbalancer with sticky sessions) and the database gives you that capability quite easily.
Databases also have good stability and durability during crashes and reboots.
One of the problems with database session storage is that it adds more load to the database. On large catalog sites with many SKUs, or busy sites with lots of sessions, this can hurt the database performance.
To use the database for session storage simply have this in your local.xml:
1
<session_save><![CDATA[db]]></session_save>
Check out the benchmarks below to see how well database session storage performs.

Memcached Session storage

Memcached session storage takes a bit more setup than either of the previous two options, which is probably why it’s not considered a ‘normal’ option during Magento install. For starters you need a Memcached server running.
Once you have it up and running, the memcached session storage offers a number of benefits. Firstly it is very cluster friendly. The session data can be shared by any number of webnodes, and to make things even better you can easily add more memcached server nodes so that even your session storage can be scaled to handle many 1000′s of concurrent sessions*. Secondly, it is (or can be) separate of the database and web node entirely, which offloads the work of storing sessions from busy nodes in a high-traffic environment.
The memcached server is not tolerant to failures, if your system crashes or dies the data in memory will be lost. Being a separate server does allow the session storage to be kept running during a web or database node restart though – something you cannot do with the tmpfs storage option below.
In terms of speed, the memcached keeps all it’s data in memory (think a giant hashtable), so it should be fast. However, there is the overhead of an extra tcp connection, so we’ll see in the benchmark section if that has an effect or not.
Quick tip: sharing one memcached server with multiple stores is tricky, you need to use different ports or unix sockets. So if you need multiple stores and are not comfortable with that sort of socket setup, assume you may need to run a separate memcached instance for each store.
To use a memcached session store in Magento you’ll need to have this in your app/etc/local.xml:
1
2
<session_save><![CDATA[memcache]]></session_save>
<session_save_path><![CDATA[tcp://localhost:11211?persistent=1&weight=2&timeout=10&retry_interval=10]]></session_save_path>
Note: Adjust the server:port in the url above to match your environment. I’m assuming you have memcached running.
(*then all you need is to own a webstore that has 1000′s of concurrent shoppers…)

tmpfs-backed Filesystem Session storage

This is not really a good idea for storing sessions, it’s highly volatile and unstable two things you probably don’t want for ecommerce store sessions. It’s also not scalable either as it relies on the machine’s physical memory, and you can only stick so much of that in – you might need it for the web server too. It will also not help at all in a clustered environment as it is machine specific.
Despite all it’s limitations I really wanted to test tmpfs sessions more out of curiosity than anything, I have a hunch that it will make quite a performance boost. Let’s see how it does in the benchmark section below.
If you’re keen to try this, I’ll assume you know what you’re doing on the system side of things. Mount var (orvar/sessions) as a tmpfs and set Magento to use file based session storage like in the first option above.

Benchmarks

Benchmarks have been performed with Magento Speed Test on a lightly-optimized Magento 1.5 install with a few hundred products. The store was running on a combined web+DB node, EC2 large instance.
Here are the results of each sessions storage for varying numbers of concurrent users.
Session Storage Transaction throughput (Transactions/s) for a varying number of concurrent users
FilesystemDatabaseMemcachedtmpfs Filesystem
10 users4.793.564.025.10
30 users5.185.525.955.92
75 users5.835.295.645.84
Session Storage Average Response Time (s) for a varying number of concurrent users
FilesystemDatabaseMemcachedtmpfs Filesystem
10 users1.532.141.831.42
30 users4.594.334.114.07
75 users10.2311.3310.5210.33

Conclusion

I’ve looked at the benefits and limitations of each Magento session storage option, and tested the performance of each with varying numbers of concurrent users.
I was a quite surprised at how little each option affected the store’s performance. I guess it shows you that session storage is not so much about performance as it is about stability, and suitability for your requirements (cluster vs non-cluster, large catalog database etc).
I am working on a follow up article that simulates the effect of a week’s worth of sessions (in a long-lived session setup) because I have a hunch that the filesystem begins to slow down as the number of sessions being stored gets higher. It will be interesting to see if that is true and if it is also true for the DB or memcached options.
I hope this article will help you to make an informed decision which option to choose during install, and understand what can be achieved by tweaking the settings.
On an unrelated note; my latest round of changes including the ‘Run this test again’ button on Magento Speed Test make repeatably testing small performance tweaks like this on a store really easy. Try it out on your own site for free!
Lastly, it’s been a while since I posted an article here at Magebase, I hope this article is on the mark for our many new readers, any feedback most welcome.