Skip to content

Instantly share code, notes, and snippets.

@Vinai
Vinai / install-0.1.0.php
Last active November 30, 2016 18:25 — forked from kojiromike/install-0.1.0.php
Example Magento1 install script with some explanation.
<?php
// I almost never use $installer = $this; instead I prefer to use the following
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
// This is just an example of instantiating the setup class in the script. Of
// course I choose the appropriate setup class and resource on a case by case basis.
// That way it is very visible what setup class is being used. It can also be
// switched within a single setup script, for example to add attributes to
@Vinai
Vinai / use-and-autoload.php
Created October 9, 2014 21:51
PHP use statements don't have to refer to existing classes
<?php
namespace Random\Example;
spl_autoload_register(function($class) {
echo "Autoload triggered for class $class\n";
});
echo "Importing class with use upcoming...\n";
use Some\Example\Nonexistant\Class\Which\Will\Not\Trigger\The\Autoloader;
@Vinai
Vinai / activate-customer-group.php
Created September 12, 2014 10:14
Programatically activate all customers of a specific customer group for the Magento CustomerActivation extension found at https://github.com/Vinai/customer-activation
<?php
$groupId = 1;
Mage::getResourceModel('customer/customer_collection')
->addAttributeToFilter('group_id', $groupId)
->setDataToAll('customer_activated', 1)
->save();
@Vinai
Vinai / example.php
Created June 20, 2014 08:34
Loading individual attribute values on catalog/product instances.
<?php
require('htdocs/app/Mage.php');
umask(0);
Mage::setIsDeveloperMode(true);
Mage::app();
$attributeCode = 'description'; // any attribute code
// load model without only static attribute values
@Vinai
Vinai / bootstrap.php
Last active January 29, 2019 22:50
Simple Magento integration test PHPUnit bootstrap
<?php
/**
* Simple Magento integration test PHPUnit bootstrap
*/
chdir(__DIR__ . '/../..');
$mageFile = 'htdocs/app/Mage.php';
umask(0);
<?php
umask(0);
ini_set('memory_limit','512M');
set_time_limit(0);
if(file_exists('app/Mage.php')) require 'app/Mage.php';
else require '../../app/Mage.php';
// Init without cache so we get a fresh version
Mage::app('admin','store', array('global_ban_use_cache' => TRUE));
@Vinai
Vinai / 2_keyboard_shortcuts.md
Created October 17, 2013 08:26
Here are some things you can do with Gists in GistBox.

Create documentation for your projects. Like so:


Most popular keyboard shortcuts within GistBox

  • Up/Down - Previous/Next Gist
  • Ctrl+e - Edit a selected Gist
  • Ctrl+s - Save Gist
@Vinai
Vinai / Client.php
Last active December 25, 2015 05:09
PHPUnit bootstrap example for OrderManagement
<?php
class Training_OrderIntegrationClient_Model_Client
{
protected $_socket;
/**
* Workaround to make class testable
*
@Vinai
Vinai / example.php
Created October 7, 2013 15:58
Set Product Group Price using setData()
$product->setData('group_price', array(
array(
'website_id' => 0,
'cust_group' => $customerGroupId,
'price' => 19.99
)
));
@Vinai
Vinai / boris-mage.php
Last active September 10, 2016 15:33
PHP REPL with initialized Magento environment
#!/usr/bin/env php
<?php
//
// PHP REPL with initialized Magento environment
//
// Thanks to https://github.com/d11wtq/boris
//
// Drop this script in your $PATH and run it anywhere in a Magento directory tree to start the REPL
//