Skip to content

Instantly share code, notes, and snippets.

@drewgillson
drewgillson / redis-cli-delete
Created December 25, 2011 00:00
Example Redis delete key
DEL "zc:d:www.liveoutthere.com/"
@drewgillson
drewgillson / loadConfiguration
Created December 25, 2011 00:12
Redis for Tinybrick Lightspeed
case 'redis':
try {
require_once('lib/Credis/Client.php');
require_once('lib/Zend/Cache/Backend.php');
require_once('lib/Zend/Cache/Backend/Interface.php');
require_once('lib/Zend/Cache/Backend/ExtendedInterface.php');
require_once('app/code/core/Zend/Cache/Backend/Redis.php');
self::$cacheEngine = 'redis';
$options = array();
foreach($child2->backend_options as $el){
@drewgillson
drewgillson / get
Created December 25, 2011 00:20
Redis for Tinybrick Lightspeed - get
case 'redis':
return unserialize(self::$cacheData['server']->load($key));
break;
@drewgillson
drewgillson / cache-server-model
Created December 25, 2011 00:25
Redis for TinyBrick Lightspeed - cache server model
<?php
class TinyBrick_LightSpeed_Model_Server_Redis {
protected $_server;
protected $_enabled = false;
public function getServer() {
if (!$this->_server) {
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/Credis/Client.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/Zend/Cache/Backend.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/Zend/Cache/Backend/Interface.php');
@drewgillson
drewgillson / get-server
Created December 25, 2011 00:27
Redis for TinyBrick Lightspeed - getserver
public function getServer()
{
if(!$this->_server){
$type = strtolower(Mage::getConfig()->getNode('lightspeed/cache/type'));
if ($type == "memcached"){
$this->_server = Mage::getModel("lightspeed/server_memcache");
}elseif ($type == "redis"){
$this->_server = Mage::getModel("lightspeed/server_redis");
}else{
$this->_server = Mage::getModel("lightspeed/server_files");
@drewgillson
drewgillson / local.xml
Created December 25, 2011 00:34
Redis for TinyBrick LightSpeed - local.xml
<lightspeed>
<global>
REDACTED
</global>
<session>
REDACTED
</session>
@drewgillson
drewgillson / applyCouponCodeAction.php
Created December 31, 2011 03:18
Magento - apply coupon code automatically
public function indexAction() {
$coupon_code = $this->getRequest()->getParam('coupon_code');
if ($coupon_code != '') {
Mage::getSingleton("checkout/session")->setData("coupon_code",$coupon_code);
Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode($coupon_code)->save();
Mage::getSingleton('core/session')->addSuccess($this->__('Coupon was automatically applied'));
}
else {
Mage::getSingleton("checkout/session")->setData("coupon_code","");
@drewgillson
drewgillson / applyCouponEvent.php
Created December 31, 2011 04:12
Magento - applyCouponEvent
public function applyCouponEvent($observer){
$coupon_code = trim(Mage::getSingleton("checkout/session")->getData("coupon_code"));
if ($coupon_code != ''){
Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode($coupon_code)->save();
}
}
@drewgillson
drewgillson / config.xml
Created December 31, 2011 04:24
Magento - apply coupon code automatically config.xml
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<ApplyCoupon_apply>
<type>singleton</type>
<class>ApplyCoupon/Observer</class>
<method>applyCouponEvent</method>
</ApplyCoupon_apply>
</observers>
@drewgillson
drewgillson / product.phtml
Created December 31, 2011 04:35
Magento - apply coupon codes automatically
$productPrice = $_product->getPrice();
$coupon_code = trim(Mage::getSingleton("checkout/session")->getData("coupon_code"));
if ($coupon_code != '') {
/*** Warning - if you choose to use this code, you should probably not
* use the direct SQL query below, and instead use the SalesRule/Rule
* resource collection, which you can access by calling
* Mage::getModel('salesrule/rule')->getResourceCollection()
*
* This example was written a long time ago and the direct SQL query was