Skip to content

Instantly share code, notes, and snippets.

@rgranadino
rgranadino / gist:992651
Created May 26, 2011 06:36
Adding Static Block To Product View Page Via Layout Update
<reference name="product.info.additional">
<block type="cms/block" name="product.info.addtional.foo">
<action method="setBlockId"><block_id>my_block_identifier</block_id></action>
</block>
</reference>
@rgranadino
rgranadino / gist:1076337
Created July 11, 2011 17:29
Get Magento Layout XML
<?php
Mage::app()->getLayout()->getNode()->asNiceXml('/tmp/foo');
@rgranadino
rgranadino / gist:1217074
Created September 14, 2011 16:49
Load Attribute With Store Frontend Label
<?php
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */
//note for 1.6 collection class is Mage_Catalog_Model_Resource_Product_Attribute_Collection
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
->setItemObjectClass('catalog/resource_eav_attribute')
->setCodeFilter(ATTRIBUTE_CODE)
->addStoreLabel(Mage::app()->getStore()->getId())
->load();
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
$attribute = $collection->getFirstItem();
@rgranadino
rgranadino / gist:1725978
Created February 2, 2012 21:48
Fixing formatCurrency method in magento's js.js (pre 1.6) to not stomp out omniture's global 's' object
if (formatCurrency) {//Encapsulate formatCurrency to prevent global variable leaking....
formatCurrency = (function(f) {
var origMethod = Object.clone(f);
return function(price, format, showPlus) {
return origMethod(price, format,showPlus);
};
}(formatCurrency));
}
@rgranadino
rgranadino / .gitignore
Created May 7, 2012 23:33
magento (1.6.1.0) .gitignore
.buildpath
.htaccess
.htaccess.sample
.settings
.project
app/etc/local.xml
app/code/community/Find/
app/code/community/Phoenix/
app/code/core/
app/design/adminhtml/default/default/
@rgranadino
rgranadino / gist:3100752
Created July 12, 2012 20:29
php object comparison recursion example
class Foo {
public $x = null;
}
$a = new Foo();
$b = new Foo();
$c = new Foo();
$d = new Foo();
$a->x = $c;
@rgranadino
rgranadino / gwsdecoder.php
Created August 23, 2012 04:43
D-Link gws file decoder
#/usb/bin/php
<?php
//author rgranadino aug 22 2012
//tested on a D-Link DIR-615 B2 v2.25 firmware.
//this is a php translation of:
// http://www.shulerent.com/2009/08/21/cracking-the-d-link-settings-file/
$file = $argv[1];
if (!is_readable($file)) {
echo "Cannot read file: $file\n";
@rgranadino
rgranadino / gist:5977733
Created July 11, 2013 18:05
install dummy rice and beans product in magento
#!/usr/bin/env php
<?php
require 'app/Mage.php';
if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit(1);
}
$baseDir = getcwd();
//not sure if this is necessary, ported over from cron.php script
$_SERVER['SCRIPT_NAME'] = $baseDir.'/index.php';
@rgranadino
rgranadino / gist:6645104
Created September 20, 2013 23:07
Magento Sync Product Attributes
public function syncConfigProductAttributes(Mage_Catalog_Model_Product $product)
{
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
/* @var $productType Mage_Catalog_Model_Product_Type_Configurable */
$productType = $product->getTypeInstance(true);
$syncAttributes = array('short_description', 'description');
foreach ($productType->getUsedProductCollection($product) as $childProduct) {
//$childProduct->load($childProduct->getId());
/* @var $childProduct Mage_Catalog_Model_Product */
foreach ($syncAttributes as $attributeCode) {
<?php
class Email {
//...
public function setAttachments(array $files) {
$this->attachment_list = array();
foreach($files as $filename => $file) {
if (is_str($filename)) {
$this->addAttachment($file, $filename);
} else {