Skip to content

Instantly share code, notes, and snippets.

@andrew-smart
andrew-smart / config.xml
Created February 27, 2015 10:54
Expose a modules crontab schedule to system configuration (Magento 1.x)
<?xml version="1.0"?>
<config>
...
<crontab>
<jobs>
<[namespace]_cron>
<schedule>
<!--
/**
*
@andrew-smart
andrew-smart / module.xml
Last active August 29, 2015 14:17
Registration (module.xml) file sample (Magento 2.x)
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="[Vendor]_[ModuleName]" setup_version="0.0.0.1"/>
</config>
@andrew-smart
andrew-smart / config.php
Created July 9, 2015 12:35
HelloWorld sample config file (Magento 2)
<?php
return array(
'modules' => array(
...
'Magento_CurrencySymbol' => 1,
'Magento_Wishlist' => 1,
'Iweb_HelloWorld' => 1
)
);
@andrew-smart
andrew-smart / subs.php
Created September 4, 2015 18:19
Get product categories under a particular parent (Magento 1.x)
<?php
function getSubs($product, $parentId)
{
$cats = array();
// get the product category ids
$ids = $product->getCategoryIds();
// get all children of the parent $catId
@andrew-smart
andrew-smart / .htaccess
Created October 6, 2015 08:45
HTTP to HTTPS redirect
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@andrew-smart
andrew-smart / .gitignore
Last active December 10, 2015 14:37
Magento 2 .gitignore
/app/design/*/Magento
/app/etc
/app/*.*
/bin/
/dev/
/lib/
/phpserver/
/pub/
/setup/
/update/
@andrew-smart
andrew-smart / di.xml
Created January 18, 2016 08:46
Magento 2: Declare a plugin
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="[ObservedType]">
<plugin name="[pluginName]" type="[PluginClassName]" sortOrder="1" disabled="false" />
</type>
</config>
@andrew-smart
andrew-smart / magento2-create-project.sh
Created February 18, 2016 14:55
Create a new project in Magento 2
#!/usr/bin/env bash
name=$1
if [ -z "$name" ]; then
echo "\$name required"
exit 1
fi
path=$(eval echo "~/Sites/$name")
if [ -d "$path" ]; then
echo "$path already exists. Aborting"
@andrew-smart
andrew-smart / bin-magento.sh
Last active June 21, 2016 12:20
Run bin/magento from anywhere in your Magento 2 installation
#!/usr/bin/env bash
# Detect magento
#
# Adapted from Alan Storms approach
# to finding the Magento root by traversing up from the current
# directory checking for the existence of the di.xml file.
#
# Ref: https://github.com/astorm/pestle/blob/master/modules/pulsestorm/magento2/cli/library/module.php#L57
di="app/etc/di.xml"
@andrew-smart
andrew-smart / patch.sh
Created October 17, 2016 13:49
Magento 1.9.3 Free Shipping Sales Rule Fix
diff --git a/app/code/core/Mage/SalesRule/etc/config.xml b/app/code/core/Mage/SalesRule/etc/config.xml
index d5e7763..6a0e898 100644
--- a/app/code/core/Mage/SalesRule/etc/config.xml
+++ b/app/code/core/Mage/SalesRule/etc/config.xml
@@ -134,8 +134,8 @@
<totals>
<freeshipping>
<class>salesrule/quote_freeshipping</class>
- <after>subtotal,tax_subtotal</after>
- <before>shipping</before>