Skip to content

Instantly share code, notes, and snippets.

<?php
$suffixes = array('');
// ...
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
return $file;
}
}
@code-poel
code-poel / ExecutableFinder.php
Last active August 29, 2015 14:08
ExecutableFinder
<?php
public function find($name, $default = null, array $extraDirs = array())
{
if (ini_get('open_basedir')) {
// ...
} else {
$dirs = array_merge(
explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
$extraDirs
@code-poel
code-poel / PhpExecutableFinder.php
Last active August 29, 2015 14:08
PhpExecutableFinder
<?php
public function find($includeArgs = true)
{
// ...
$dirs = array(PHP_BINDIR);
// ...
return $this->executableFinder->find('php', false, $dirs);
@code-poel
code-poel / Transactions.php
Last active August 29, 2015 14:06
Magento transactions...
<?php
$transaction = Mage::getModel('core/resource_transaction');
$transaction->addObject($model_a)
$transaction->addObject($model_b)
$transaction->save();
@code-poel
code-poel / Create_Gift_Card_Account.php
Last active August 29, 2015 14:06
Create a new, active, gift card account.
<?php
try
{
$proxy = new SoapClient('./api/v2_soap/?wsdl');
$sessionId = $proxy->login('XXXXX', 'XXXXX');
$result = $proxy->giftcardAccountCreate(
$sessionId,
array(
@code-poel
code-poel / layout.xml
Last active August 29, 2015 14:06
Magento price template overrides via layout.xml.
<?xml version="1.0"?>
<!--
http://magento.stackexchange.com/questions/4748/how-rendering-of-price-phtml-in-catalog-product-listing-page-is-happening
http://magento.stackexchange.com/questions/14124/overriding-price-phtml-template-using-addpriceblocktype-in-magento-ce-1-7-0-2
-->
<layout>
<default>
@code-poel
code-poel / Create_Configurable_Products.php
Last active August 29, 2015 14:06 — forked from magento-team/2500 config products
Create 2500 dummy configurable products in a Magento installation for testing purposes.
<?php
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
@code-poel
code-poel / Magento_Example.php
Last active August 29, 2015 14:05
Get all active category names.
<?php
public function getAllCategoryNames()
{
$names = array();
// Build out a category collection and add the name attribute to the select.
$model = Mage::getModel('catalog/category');
$collection = $model->getCollection();
$collection->addAttributeToSelect('name');
@code-poel
code-poel / Magento_Test.php
Last active August 29, 2015 14:05
Get a configurable product's children with custom attributes attached...
<?php
$configurable = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$collection = $configurable->getUsedProductCollection();
$collection->addAttributeToSelect('*');
$collection->addFilterByRequiredOptions();
foreach ($collection as $product) {
print_r($product->debug());
}
@code-poel
code-poel / lib_Varien_Autoload.php
Last active August 29, 2015 13:57
Magento Autoload
<?php
static public function register()
{
spl_autoload_register(array(self::instance(), 'autoload'));
}
/**
* Load class source code
*
* @param string $class