Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / autoshipping.php
Last active October 17, 2017 07:04
Set shipping method and rate if they do not exist yet in Magento
<?php
/**
* Has shipping been applied to quote?
*
* @var bool
*/
protected $_hasShipping = false;
/**
@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 <herve.guetin@gmail.com> <@herveguetin>
*/
class Reindex
{
/**
* @var \Magento\Indexer\Console\Command\IndexerReindexCommand
@herveguetin
herveguetin / next_business_day.php
Last active August 26, 2017 18:22
Retrieve the next business or calendar day in Magento with an optional leadtime. Magento weekend days config is taken into account.
<?php
/**
* Retrieve the next business day with an optional leadtime.
* If leadtime = 1 => find the next business day
* If leadtime = 2 => find the "next next" business day
* etc...
*
* @param int $leadtime
* @return string|bool
*/
@herveguetin
herveguetin / create_group_prices_magento.php
Created June 10, 2015 06:59
Create/update group prices programmatically in Magento
<?php
class Namespace_Module_Model_Price_Import extends Mage_Core_Model_Abstract
{
/**
* DB Connection
*
* @var Varien_Db_Adapter_Interface
*/
protected $_conn;
@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'
@herveguetin
herveguetin / create_order_status.php
Last active March 1, 2017 10:28
This is how to create an new order status in Magento
<?php
// Create new order status
$data = array(
'status' => 'status_code',
'label' => 'Default Label'
);
$status = Mage::getModel('sales/order_status');
$status->setData($data)->save();
// Assign to some order state
@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 <barryvdh@gmail.com>
* @see https://github.com/barryvdh/laravel-ide-helper
*/
namespace {
@herveguetin
herveguetin / new
Last active February 3, 2017 14:22
new again
@herveguetin
herveguetin / cart_price_rule_1_steps.txt
Last active January 13, 2017 06:08
Programmatically create a cart price rule in Magento
This is a quick an easy hack to programmatically create a cart price rule.
1. Temporarely edit Mage_Adminhtml_Promo_QuoteController::saveAction()
2. Around line 123, you will find $data = $this->getRequest()->getPost();
3. Below this line create a new line containing :
var_export($data);
die();
@herveguetin
herveguetin / customer_group_massupdate_magento.php
Created June 12, 2015 09:50
Affect all Magento customers to a group
<?php
$customerGroupId = SOME_CUSTOMER_GROUP_ID;
$table = Mage::getModel('customer/customer')->getResource()
->getWriteConnection()
->getTable('customer/entity');
$query = "UPDATE {$table} SET group_id = {$customerGroupId} WHERE group_id != {$customerGroupId}";
$conn->query($query);
?>