fadzly
fadzly
Reputation Top 1%
fadzly
13 Snippets  (63rd place)
Published
1 Channel
Created
2 Channels
Following
7300 points  (17th 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  12710  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  4362  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  4113  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  4099  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  1927  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'
;