Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / singleton_instances_magento2.php
Last active Oct 25, 2018
Injecting interfaces, singleton, factory, models in Magento 2
View singleton_instances_magento2.php
<?php
class SomeClass
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $configInterface;
/**
* @var \Magento\Framework\App\Config
@herveguetin
herveguetin / load_model_magento2.php
Created Oct 25, 2018
Load model from DB in Magento 2
View load_model_magento2.php
<?php
class SomeClass
{
/**
* @var \Magento\Catalog\Model\ResourceModel\Product
*/
private $productResource;
/**
* @var \Magento\Catalog\Model\ProductFactory
*/
@herveguetin
herveguetin / SomeClass.php
Created Oct 25, 2018
Directive interpolation in Magento 2
View SomeClass.php
class SomeClass
{
public function __construct(
\Magento\Framework\Filter\Template $templateFilter
)
{
$this->templateFilter = $templateFilter;
}
public function getDirectiveContent()
@herveguetin
herveguetin / m2_reindexall_programmatically.php
Last active Sep 20, 2017
Reindexing programmatically in Magento 2
View m2_reindexall_programmatically.php
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Hervé Guétin <herve.guetin@gmail.com> <@herveguetin>
*/
class Reindex
{
/**
* @var \Magento\Indexer\Console\Command\IndexerReindexCommand
View lumen_ide_helper.php
<?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 <barryvdh@gmail.com>
* @see https://github.com/barryvdh/laravel-ide-helper
*/
namespace {
@herveguetin
herveguetin / add_column_after.php
Created Apr 26, 2016
Add a column after another one in Magento 2
View add_column_after.php
<?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 Oct 27, 2015
In Magento, when adding a product to wishlist, force redirection to wishlist page after customer login
View wishlist_force_redirection_after_login_magento.php
<?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 Jan 13, 2017
Get HTML for a standalone layout in Magento
View standalone_layout.php
<?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 Jun 24, 2015
Create category tree in Magento
View setup.php
<?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'
You can’t perform that action at this time.