Skip to content

Instantly share code, notes, and snippets.

View ivanweiler's full-sized avatar
👾

Ivan Weiler ivanweiler

👾
View GitHub Profile
@ivanweiler
ivanweiler / magento-block-cache.php
Last active August 29, 2015 14:05
Magento block cache examples
<?php
class Inchoo_Edu_Block_Template extends Mage_Core_Block_Template
{
/*
* Block caching
*
*/
protected function _construct()
{
<?php
class Inchoo_Edu_Model_Resource_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
/*
* Collection that always caches all its queries
*
*/
protected function _construct()
{
$this->_init('inchoo_edu/dummy');
<?php
class Inchoo_Edu_Model_Example
{
/*
* Custom cache example
*
* @see: Directory, Adminhtml_Block, etc.
*
*/
{
"require": {
"magento/magento-composer-installer": "*",
"magento/product-community-edition": "0.1.0-alpha97"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.magento.com/"
}
@ivanweiler
ivanweiler / Mage_Checkout_Block_Onepage_Billing.php
Created June 17, 2015 10:00
Magento Checkout - fill address forms from Quote address (if possible) for guest customers
/**
* Mage_Checkout_Block_Onepage_Billing::getAddress() should be something like this
*
* Similar for Mage_Checkout_Block_Onepage_Shipping
*/
public function getAddress()
{
if (is_null($this->_address)) {
$this->_address = $this->getQuote()->getBillingAddress(); //always take address from quote
@ivanweiler
ivanweiler / gist:e312598ad1df25581c530a6adcd8cc8c
Last active June 26, 2017 10:42
bin/magento php cli options
php -d xdebug.remote_autostart=1 bin/magento
xdebug.ini
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.max_nesting_level = 500
#default formating
xdebug.overload_var_dump = 0
@ivanweiler
ivanweiler / log.php
Last active August 10, 2016 13:39
Mage::log
\Magento\Framework\App\ObjectManager::getInstance()
->get('\Psr\Log\LoggerInterface')
->debug(print_r($a, true));
//var/log/debug.log
@ivanweiler
ivanweiler / app_etc_local.di.xml
Last active April 18, 2017 07:45
Magento 2 log database queries
<?xml version="1.0"?>
<!--
/**
* Log Db Queries
* Copy to /app/etc/local.di.xml (di.xml glob follows {*di.xml, */*di.xml} pattern)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
<type name="Magento\Framework\DB\Logger\File">
@ivanweiler
ivanweiler / gist:c1c85922270a41fd8af62759d09822f0
Created March 20, 2018 11:22
Magento2 Apache/htaccess CORS headers
<VirtualHost *:80> # Or whatever VHost you're using
# Your other rules
RewriteEngine on
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ "index.html" [R=200,E=API:1,PT]
# This rewrite rule forces any OPTIONS request to return as a valid response.
# It sets the API environment variable for use below.
#
# You can try to put a placeholder file here for the response (index.html)
# Otherwise it'll look like an error page, but it'll return with a 200 response code.
@ivanweiler
ivanweiler / magento-api-examples.md
Last active April 3, 2018 06:04
Magento APIs for React workshop