Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / singleton_instances_magento2.php
Last active October 25, 2018 20:45
Injecting interfaces, singleton, factory, models in Magento 2
<?php
class SomeClass
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $configInterface;
/**
* @var \Magento\Framework\App\Config
@herveguetin
herveguetin / load_model_magento2.php
Created October 25, 2018 20:28
Load model from DB in Magento 2
<?php
class SomeClass
{
/**
* @var \Magento\Catalog\Model\ResourceModel\Product
*/
private $productResource;
/**
* @var \Magento\Catalog\Model\ProductFactory
*/
@herveguetin
herveguetin / SomeClass.php
Created October 25, 2018 17:48
Directive interpolation in Magento 2
class SomeClass
{
public function __construct(
\Magento\Framework\Filter\Template $templateFilter
)
{
$this->templateFilter = $templateFilter;
}
public function getDirectiveContent()
@herveguetin
herveguetin / m2_reindexall_programmatically.php
Last active September 20, 2017 21:49
Reindexing programmatically in Magento 2
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Hervé Guétin <[email protected]> <@herveguetin>
*/
class Reindex
{
/**
* @var \Magento\Indexer\Console\Command\IndexerReindexCommand
@herveguetin
herveguetin / lumen_ide_helper.php
Created February 16, 2017 21:18 — forked from barryvdh/lumen_ide_helper.php
Lumen IDE Helper
<?php
/**
* A helper file for Laravel 5, to provide autocomplete information to your IDE
* Generated for Laravel Lumen (5.1.1) (Laravel Components 5.1.*) on 2015-08-18.
*
* @author Barry vd. Heuvel <[email protected]>
* @see https://github.com/barryvdh/laravel-ide-helper
*/
namespace {
@herveguetin
herveguetin / new
Last active February 3, 2017 14:22
new again
@herveguetin
herveguetin / add_column_after.php
Created April 26, 2016 13:46
Add a column after another one in Magento 2
<?php
namespace My\Module\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UpgradeSchemaInterface;
/**
* @codeCoverageIgnore
*/
@herveguetin
herveguetin / wishlist_force_redirection_after_login_magento.php
Created October 27, 2015 14:24
In Magento, when adding a product to wishlist, force redirection to wishlist page after customer login
<?php
// 1. Observe the following event: controller_action_predispatch_wishlist_index_add which calls, for example, the `forceReferer()` method
// 2. In your observer class, implement the `forceReferer()` method
/**
* When adding a product to wishlist,
* force redirection to wishlist page after customer login
*
*/
public function forceReferer(Varien_Event_Observer $observer)
@herveguetin
herveguetin / standalone_layout.php
Last active January 13, 2017 06:08
Get HTML for a standalone layout in Magento
<?php
/**
* Retrieve content of a standalone layout
*
* @return string
* @throws Mage_Core_Exception
*/
public function getStandaloneLayoutHtml()
{
$layout = Mage::getModel('core/layout'); // Instanciate a brand new layout (not using the singleton from Mage::app()->getLayout())
@herveguetin
herveguetin / setup.php
Created June 24, 2015 09:13
Create category tree in Magento
<?php
$tree = array(
'Category A' => array(
'Category A-B' => array(
'Category A-B-A',
'Category A-B-B'
),
'Category A-C' => array(
'Category A-C-A',
'Category A-C-B'