Skip to content

Instantly share code, notes, and snippets.

@enru
enru / find_m2_images.sh
Created January 31, 2022 13:09
shell cmd to list core Magento 2 files containing theme images
for img in `grep "<image id=" vendor/magento/theme-frontend-blank/etc/view.xml | \
awk -F= '{ print $2 }' | \
sed 's/ type//' | \
tr -d '"'`; do \
echo $img; \
grep --exclude view.xml -rl $img vendor/magento/ ; \
done
# outputs:
@enru
enru / gist:1da6193c25eb7516b813
Last active November 25, 2015 13:01
mysql files by size
SELECT table_schema as `Database`, table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) ASC;
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
@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
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 / 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 / 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';
// 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 / 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>
@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();