Skip to content

Instantly share code, notes, and snippets.

View mshmsh5000's full-sized avatar

Matt Holford mshmsh5000

View GitHub Profile
@mshmsh5000
mshmsh5000 / gist:2421936
Created April 19, 2012 15:55
Magento: Load product from order item
<?php
if ('Mage_Sales_Model_Order_Item' == get_class($item)) {
$product = null;
$options = $item->getProductOptions();
if (!empty($options['info_buyRequest']) && !empty($options['info_buyRequest']['product'])) {
$product = Mage::getModel('catalog/product')->load($options['info_buyRequest']['product']);
if (!empty($product)) {
@mshmsh5000
mshmsh5000 / crawlsitemap.py
Created June 16, 2012 02:01
Sitemap-driven crawler
import xml.dom.minidom, urllib
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
@mshmsh5000
mshmsh5000 / magento-read-db-config.sh
Created July 30, 2012 14:15
Magento command-line script: Read raw MySQL connection info from local.xml
#!/bin/sh
MYSQLCMD=$(which mysql)
# Read Magento primary connection info
DBHOST=$(/PATH/TO/php -r "echo simplexml_load_file('/PATH/TO/app/etc/local.xml', NULL, LIBXML_NOCDATA)->global->resources->default_setup->connection->host;")
DBUSER=$(/PATH/TO/php -r "echo simplexml_load_file('/PATH/TO/app/etc/local.xml', NULL, LIBXML_NOCDATA)->global->resources->default_setup->connection->username;")
DBPASS=$(/PATH/TO/php -r "echo simplexml_load_file('/PATH/TO/app/etc/local.xml', NULL, LIBXML_NOCDATA)->global->resources->default_setup->connection->password;")
DBNAME=$(/PATH/TO/php -r "echo simplexml_load_file('/PATH/TO/app/etc/local.xml', NULL, LIBXML_NOCDATA)->global->resources->default_setup->connection->dbname;")
@mshmsh5000
mshmsh5000 / CategoryController.partial.php
Created August 23, 2012 18:52
Magento fix for parse_str() bug in CategoryController
/**
* Addresses this bug: http://www.magentocommerce.com/bug-tracking/issue/?issue=13203
*
* See app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
* Mage_Adminhtml_Catalog_CategoryController::saveAction(), starting around
* line 307
*/
if (isset($data['category_products']) &&
!$category->getProductsReadonly()) {
$products = array();
@mshmsh5000
mshmsh5000 / file1.php
Created August 30, 2012 19:10
Magento process locking - partial 1
<?php
class BigThings
{
/**
* Process all the things
*/
public function changeEverything()
{
$this->log("Starting...hold on to your hats.");
@mshmsh5000
mshmsh5000 / file1.php
Created August 30, 2012 19:11
Magento process locking - partial 1
<?php
class BigThings
{
/**
* Process all the things
*/
public function changeEverything()
{
$this->log("Starting...hold on to your hats.");
A headless Selenium testing system is an ideal addition to any development workflow. Selenium reduces testing time, and integrates into CI tools such as Jenkins. The benefits are great, but only *if* you can get your tests to run.
One of the most time consuming problems that can arise from a headless system is a failed test. How can you debug, when you can't see the browser? Ideally, you will test your scripts locally before running them on the headless system, but anyone who has even dabbled in the world of automation knows that a single procedure can yield very different results on different systems and in different environments. You can deal with the differences, but first you have to see them.
After much searching, I could not find a straight answer as to how to export this display to my Windows machine from our Linux server. It is really quite simple, and can be done in a few steps.
In order to display a headless Selenium test on a Windows machine from a Linux server, you must first be able to have
@mshmsh5000
mshmsh5000 / gist:4664829
Last active December 11, 2015 21:48
Magento: Temporary fix for failed configuration saves. See http://screencast.com/t/7yGn07BMGSY
<?php
// app/code/core/Mage/Adminhtml/Model/Config/Data.php: 135:
/**
* Get field backend model
*/
$backendClass = $fieldConfig->backend_model;
if (!$backendClass) {
$backendClass = 'core/config_data';
@mshmsh5000
mshmsh5000 / gist:5383710
Last active December 16, 2015 05:19
Topps_Content_Helper_Data::getWorld()
<?php
/**
* Load a world and its child channels. Typically detects world from
* current category, but can also be passed a category slug.
*
* This is a heavy method. It loads related media, content, etc.,
* sufficient to populate all content on the page.
*
* @param string $for_slug Identifier for the world to load.
@mshmsh5000
mshmsh5000 / gist:5383736
Created April 14, 2013 18:39
Topps_Content_Helper_Data::populateObjectWithCustomFields()
<?php
/**
* Populate an existing object with the results of a WP JSON API response,
* which includes a custom_fields object. These can be the same object. In
* this case, leave the second parameter blank or as null.
*
* @param stdClass $object
* @param stdClass $response_object JSON response.
* @param bool $load_relations Optional; pass false to disable
* loading all related content.