Skip to content

Instantly share code, notes, and snippets.

@Vinai
Vinai / activate-customer-group.php
Created September 12, 2014 10:14
Programatically activate all customers of a specific customer group for the Magento CustomerActivation extension found at https://github.com/Vinai/customer-activation
<?php
$groupId = 1;
Mage::getResourceModel('customer/customer_collection')
->addAttributeToFilter('group_id', $groupId)
->setDataToAll('customer_activated', 1)
->save();
@Vinai
Vinai / use-and-autoload.php
Created October 9, 2014 21:51
PHP use statements don't have to refer to existing classes
<?php
namespace Random\Example;
spl_autoload_register(function($class) {
echo "Autoload triggered for class $class\n";
});
echo "Importing class with use upcoming...\n";
use Some\Example\Nonexistant\Class\Which\Will\Not\Trigger\The\Autoloader;
@Vinai
Vinai / MCACE-22.patch
Created June 3, 2011 07:48
MCA-CE MCACE-22: Quotes with a Subtotal of 0.00 and a Shipping Method Cost > 0.00 can't be ordered
diff --git a/app/code/core/Mage/Payment/Block/Form/Container.php b/app/code/core/Mage/Payment/Block/Form/Container.php
index 9b505bb..ca4b95b 100644
--- a/app/code/core/Mage/Payment/Block/Form/Container.php
+++ b/app/code/core/Mage/Payment/Block/Form/Container.php
@@ -116,7 +116,7 @@ class Mage_Payment_Block_Form_Container extends Mage_Core_Block_Template
$quote = $this->getQuote();
$store = $quote ? $quote->getStoreId() : null;
$methods = $this->helper('payment')->getStoreMethods($store, $quote);
- $total = $quote->getBaseSubtotal();
+ $total = $quote->getBaseGrandTotal();
@Vinai
Vinai / gist:1205913
Created September 9, 2011 10:32
Bug with store cookie handling in Magento up to 1.6 if specifying a non-default store MAGE_RUN_CODE
--- a/app/code/core/Mage/Core/Model/App.php
+++ b/app/code/core/Mage/Core/Model/App.php
@@ -511,11 +511,7 @@ class Mage_Core_Model_App
if ($this->_currentStore == $store) {
$store = $this->getStore($store);
- if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) {
- $this->getCookie()->delete(Mage_Core_Model_Store::COOKIE_NAME);
- } else {
- $this->getCookie()->set(Mage_Core_Model_Store::COOKIE_NAME, $this->_currentStore, true);
@Vinai
Vinai / protected-execute-reasoning.md
Last active October 6, 2015 19:19
The reasons why or why not \Magento\Framework\App\Action\Action::execute should be used as a plugin extension point

To plug into or not plug into execute?

Background

Cyrill Schumacher asked in a tweet

Ur change to add abstract protected fnc exec() conflicts with the Plugin System or am I missing smthng?

This is about the protected visiblity of the method \Magento\Framework\App\Action\Action::execute().

@Vinai
Vinai / Client.php
Last active December 25, 2015 05:09
PHPUnit bootstrap example for OrderManagement
<?php
class Training_OrderIntegrationClient_Model_Client
{
protected $_socket;
/**
* Workaround to make class testable
*
<?php
umask(0);
ini_set('memory_limit','512M');
set_time_limit(0);
if(file_exists('app/Mage.php')) require 'app/Mage.php';
else require '../../app/Mage.php';
// Init without cache so we get a fresh version
Mage::app('admin','store', array('global_ban_use_cache' => TRUE));
@Vinai
Vinai / manage-workers.sh
Last active January 29, 2016 13:20
Little worker management UI script, just for fun. Ideas for improvements welcome!
#!/usr/bin/env bash
########################################################
declare -a workers=(commandConsumer.php eventConsumer.php)
########################################################
function main() {
init_vars
@Vinai
Vinai / boris-mage.php
Last active September 10, 2016 15:33
PHP REPL with initialized Magento environment
#!/usr/bin/env php
<?php
//
// PHP REPL with initialized Magento environment
//
// Thanks to https://github.com/d11wtq/boris
//
// Drop this script in your $PATH and run it anywhere in a Magento directory tree to start the REPL
//
@Vinai
Vinai / Magento_IntegrationTest_Config.php
Last active October 18, 2016 17:16
Simple Magento 1 bootstrap for PHPUnit.
<?php
class Magento_IntegrationTest_Config extends Mage_Core_Model_Config
{
private $modelTestDoubles = [];
private $resourceModelTestDoubles = [];
public function setModelTestDouble($modelClass, $testDouble)
{