Skip to content

Instantly share code, notes, and snippets.

@rgranadino
rgranadino / gist:8695018
Created January 29, 2014 19:24
updating db resource connection info in magento - special cases only?
<?php
$dbConfig = Mage::getConfig()->getNode('global/resources/report_database/connection');
if (!$dbConfig) {
return;
}
/* @var $db Magento_Db_Adapter_Pdo_Mysql */
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
$db->closeConnection();
//update values
$dbConfig = $dbConfig->asArray();
@rgranadino
rgranadino / memleak.php
Last active August 29, 2015 13:55
Magento Memory Leak
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
require 'app/Mage.php';
Mage::app('admin', 'store');
/* @var $customers Mage_Customer_Model_Resource_Customer_Collection */
$customers = Mage::getResourceModel('customer/customer_collection');
$customers->addAttributeToSelect('*');
$customers->setPageSize((isset($argv[1]) && is_numeric($argv[1]))?$argv[1]:2000);
@rgranadino
rgranadino / gist:8744147
Created January 31, 2014 22:00
sample asset path data structure
Array
(
[gallery] => Array
(
[1810] => Array
(
[path] => g/0000430/11.jpg
[orig_path] => /1/1/11.jpg
)
<!DOCTYPE html>
<html>
<head><title>Script Block Test</title></head>
<body>
<?php if (isset($_GET['mode']) && $_GET['mode'] == 'inline'): ?>
<script type="text/javascript">
var domReadyQueue = [];
var x=function(){return {on: function(){}};};
<?php
/**
* @package Develpr_Sqs
* @author Kevin Mitchell <kevin@develpr.com>
* @copyright Massachusetts Institute of Technology License (MITL)
* @license http://opensource.org/licenses/MIT
*/
require(Mage::getBaseDir('lib') . '/develpr_sqs/aws.phar');
$autoloadFuncs = spl_autoload_functions();
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 30;
@rgranadino
rgranadino / gist:13b863c725a26d3373d5
Created July 16, 2014 19:26
magento soap order list limited by increment ID
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<urn:salesOrderList soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sessionId xsi:type="xsd:string">?</sessionId>
<filters xsi:type="urn:filters">
<complex_filter SOAP-ENC:arrayType="ns1:complexFilter[0]" xsi:type="ns1:complexFilterArray">
<item xsi:type="ns1:complexFilter">
<key xsi:type="xsd:string">increment_id</key>
<value xsi:type="ns1:associativeEntity">
<?php
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'SOME SKU');
$attributes = $product->getTypeInstance(true)->getSetAttributes($product);
/* @var $mediaGalleryAttribute Mage_Catalog_Model_Resource_Eav_Attribute */
$mediaGalleryAttribute = $attributes['media_gallery'];
//FILL IN $path somehow
$mediaGalleryAttribute->getBackend()->addImage($product, $path, null, false, false);
$product->save();
@rgranadino
rgranadino / gist:a3dfe55f21b347682144
Created December 4, 2014 23:55
really force magento orders complete
<?php
/* @var $collection Mage_Sales_Model_Resource_Order_Collection */
$collection = Mage::getResourceModel('sales/order_collection');
$reflection = new ReflectionMethod( Mage_Sales_Model_Order, '_setState');
$reflection->setAccessible(true);
foreach ($collection as $order) {
/* @var $order Mage_Sales_Model_Order */
$reflection->invoke($order, 'complete', 'bulk_complete', 'force complete', false, false);
$order->save();
}
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<sales>
<quote>
<item>
<product_attributes>
<reel_enable/>
</product_attributes>
</item>