Skip to content

Instantly share code, notes, and snippets.

<?php
include 'app/Mage.php';
Mage::app();
echo '<pre>';
print_r(Mage::getConfig()->getNode()->xpath('//global//rewrite'));
@ryaan-anthony
ryaan-anthony / remove-images.php
Last active August 29, 2015 14:03
Magento - remove all images
<?php
include_once("app/Mage.php");
umask(0);
Mage::app('admin');
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product){
@ryaan-anthony
ryaan-anthony / createIfDoesntExist.php
Last active August 29, 2015 14:06
Magento - create entity if doesnt exist
/**
* Load object data and create if doesnt exist
*
* @param integer $id
* @return Mage_Core_Model_Abstract
*/
public function createIfDoesntExist($id, $field=null)
{
$this->load($id, $field);
<?php
class Import_Csv
{
public function load($filepath)
{
if(!file_exists($filepath)){
throw new Exception("File \"{$filepath}\" not found.");
exit;
@ryaan-anthony
ryaan-anthony / gist:9c3ffc3d75dc9c754f3d
Last active August 29, 2015 14:10
Magento - remove broken images
<?php
include_once("app/Mage.php");
umask(0);
Mage::app('admin');
$collection = Mage::getResourceModel('catalog/product_collection');
<?php
Product::create([
'sku' => 'foo',
'name' => 'Standard Foo',
'price' => 8.99,
'special_price' => 6.99,
'categories' => ['category' => [1,3,5]]
]);
<?php
function array_walk_depth(array &$arr, $depth, $callback)
{
$depth--;
foreach($arr as $key => &$val){
if($depth) array_walk_depth($val, $depth, $callback);
<?php
class Dude implements Woah, Whoa{}
interface Woah
{
const WOAH = true;
}
interface Whoa
{
const WHOA = true;
<?php
include 'app/Mage.php';
Mage::app();
$file = fopen("skus.csv", "r");
while ($data = fgetcsv($file, 1000, ",")) {
$old = $data[0];
$new = $data[1];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $old);
if($product && $product->getId()){
$product->setSku($new);
<frontend>
<events>
<!-- logs -->
<controller_action_predispatch>
<observers><log><type>disabled</type></log></observers>
</controller_action_predispatch>
<controller_action_postdispatch>
<observers><log><type>disabled</type></log></observers>
</controller_action_postdispatch>
<customer_login>