Skip to content

Instantly share code, notes, and snippets.

@enru
enru / ajaxtest.php
Created April 29, 2013 08:56
spits out page/post slug on WordPress autosave/edit
<?php
/*
Plugin Name: Ajaxtest
Plugin URI: http://enru.co.uk/
Description: spits out page/post slug on autosave/edit
Version: 0.1
Author: Neill Russell (@enru)
Author URI: http://enru.co.uk/
*/
@enru
enru / gist:10721487
Last active August 29, 2015 13:59
woocommerce add to cart & adjust price
<?php
// add product to cart with additional data
$woocommerce->cart->add_to_cart($post->ID, $quantity = 1, $variation_id = '', $variation = $entry[1], $cart_item_data = array(
'hire_price'=>123,
));
// make sure additional data sticks in the session
@enru
enru / gist:d788c8c6f59538ed9f96
Last active August 29, 2016 12:13
gets a Magento parent product url with hash to pre-select configurable product option
function getProductUrlWithAttributes($product, $storeId) {
$url = $product->setStoreId($storeId)->getProductUrl();
$urlHash = array();
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
if(isset($parentIds[0])) {
$parent = Mage::getModel('catalog/product')->load($parentIds[0]);
$url = $parent->setStoreId($storeId)->getProductUrl();
@enru
enru / google_simple_shopping.php
Last active May 14, 2018 09:33
magento google simple shopping configuration
<!-- Basic Product Information -->
<?
// only use products with enabled parents
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
if(isset($parentIds[0])) {
$status = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parentIds[0], 'status', 1);
if($status != 1) $myPattern=null;
}
?>
<g:id><? return substr($product->getId(), 0, 50); ?></g:id>
// dev wp config
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST']);
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
@enru
enru / gist:387e821f6da91c2cfe8f
Created October 7, 2014 12:45
wp site url update
UPDATE wp_posts SET post_content = replace(post_content, 'http://ONE', 'http://TWO');
UPDATE wp_posts SET guid = replace(guid, 'http://ONE', 'http://TWO');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://ONE', 'http://TWO');
UPDATE wp_options SET option_value = 'http://TWO' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'http://TWO' WHERE option_name = 'home';
@enru
enru / app_code_local_diff.sh
Created December 2, 2014 12:19
a Bash script to check what local modifications have been done to Magento in app/code/local
for f in `find app/code/local/Mage/ -type f`; do
original=`echo $f | sed 's/local/core/'`;
if [ -e $original ]; then
diff -u $original $f;
fi
done
@enru
enru / clearCache.php
Created December 15, 2014 08:34
clear magento cache
<?php
$mage_filename = './app/Mage.php';
require_once $mage_filename;
umask(0);
Mage::app('admin');
error_reporting(E_ALL);
Mage::app()->cleanCache();
Mage::dispatchEvent('adminhtml_cache_flush_system');
@enru
enru / update_wp_siteurl.sql
Created September 4, 2015 08:24
Update WordPress site URL
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.foo.com', 'http://www.bar.com');
UPDATE wp_posts SET guid = replace(guid, 'http://www.foo.com', 'http://www.bar.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.foo.com', 'http://www.bar.com');
UPDATE wp_options SET option_value = 'http://www.bar.com' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'http://www.bar.com' WHERE option_name = 'home';
enru@v1:~$ git diff app/code/core/Mage/Checkout/controllers/OnepageController.php
diff --git a/app/code/core/Mage/Checkout/controllers/OnepageController.php b/app/code/core/Mage/Checkout/controllers/OnepageController.php
index c1ea4a5..ab920ee 100644
--- a/app/code/core/Mage/Checkout/controllers/OnepageController.php
+++ b/app/code/core/Mage/Checkout/controllers/OnepageController.php
@@ -211,6 +211,10 @@ class Mage_Checkout_OnepageController extends Mage_Checkout_Controller_Action
public function successAction()
{
$session = $this->getOnepage()->getCheckout();
+//test