fadzly
fadzly
Reputation Top 1%
fadzly
13 Snippets  (58th place)
Published
1 Channel
Created
2 Channels
Following
Thursday at 9:13:47 AM
Last Visit
Aug 4, 2014
Registered
7300 points  (14th place)
Reputation
Top 10% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Junior Topic Hub
Junior Trend Maker
Serious Trend Maker
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Serious Autobiographer
Serious Famous Coder
Senior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by fadzly

public by fadzly created Jan 19, 2017  11586  0  4  0

Saving date in Magento

Saving date in Magento
Mage::getModel('plansetter/dailyscheduledraft')
                                    ->setId()
                                    ->setScheduleDate(Mage::getModel('core/date')->gmtDate(null, date("d-m-Y")))
;

public by fadzly created Nov 1, 2016  4033  0  5  0

Get magento locale date/time from GMT timestamp / current time

Get magento locale date/time from GMT timestamp / current time
date("d-m-Y H:i:s", Mage::getModel('core/date')->timestamp(time()))
;

public by fadzly created Feb 4, 2016  3838  1  6  0

Creating a PNG image in PHP from scratch and output correct headers

$font = 25;
		$string = 'My Text';
		$im = @imagecreatetruecolor(strlen($string) * $font / 1.5, $font);
		imagesavealpha($im, true);
		imagealphablending($im, false);
		$white = imagecolorallocatealpha($im, 255, 255, 255, 127);
		imagefill($im, 0, 0, $white);
		$lime = imagecolorallocate($im, 204, 255, 51);
		imagestring($im, $font, 0, 0, $string , $lime);
		header("Content-type: image/png");
		imagepng($im);
		imagedestroy($im);
;

public by fadzly created Apr 22, 2015  2735  1  5  -1

Custom Magento system.xml (Sytem->Configuration) model

<field>
	<label></label>
	<button_label>New Button</button_label>
	<frontend_model>mymodule/adminhtml_config_buttons_custombutton</frontend_model>
	<sort_order>3</sort_order>
	<show_in_default>1</show_in_default>
	<show_in_website>1</show_in_website>
	<show_in_store>1</show_in_store>
</field>
;

public by fadzly created Mar 5, 2015  1668  1  5  1

PHP ? Operator (ternary operator)

PHP
/* most basic usage */
$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true

/* another basic usage */
$message = 'Hello '.($user->is_logged_in() ? $user->get('first_name') : 'Guest');

/* shorthand usage */
$message = 'Hello '.($user->get('first_name') ?: 'Guest');

/* echo, inline */
echo 'Based on your score, you are a ',($score > 10 ? 'genius' : 'nobody');

/* a bit tougher */
$score = 10;
$age = 20;
echo 'Taking into account your age and score, you are: ',($age > 10 ? ($score < 80 ? 'behind' : 'above average') : ($score < 50 ? 'behind' : 'above average')); // returns 'You are behind'
;