Enabling Compression on a Magento Site on OpenSuse 0

January 26th, 2010

If you’re running Magento on OpenSuse (or any platform for that matter), you can really benefit from turning on http compression, especially to remote areas or from hosts that have limited bandwidth.

There are a lot of references out there on this, but you have to sort of pull it all together on your own for this particular combination.

Verify that mod_deflate has been installed in Apache:

1. Open /etc/sysconfig/apache2.

2. Find the line that starts:

APACHE_MODULES=…

3. Verify that “deflate” is one of the modules listed (may not be in alphabetical order).

Now, enable compression in the virtual host file for your site:

1. Open /etc/apache2/vhosts.d/.conf.

2. Add the following lines inside the tag:


    <IfModule mod_deflate.c>
	DeflateBufferSize 32768
	DeflateCompressionLevel 5

	<Location />
		SetOutputFilter DEFLATE
		BrowserMatch ^Mozilla/4 gzip-only-text/html
		BrowserMatch ^Mozilla/4\.0[678] no-gzip
		BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
		SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|tiff)$ no-gzip dont-vary
		# Header append Vary User-Agent env=!dont-vary
	</Location>
    </IfModule>

Now restart Apache using:

sudo /etc/init.d/apache2 restart

and you should be in business!

Validate that compression is working

A great, handy online site that you can use to validate that compression is working is http://www.gidnetwork.com/tools/gzip-test.php.

=============================
“e-commerce done right

http://www.ifuelinteractive.com

Agency212 on Facebook 0

January 15th, 2010

Agency212

Hey Everyone,

Be sure to check out our new Agency212 facebook page.

While you’re there, don’t forget to also visit the iFuel page.

Happy Holidays From iFuel 0

December 24th, 2009

We just wanted to take a minute and wish you all a happy and healthy holiday from everyone here at our interactive agency.

Clearing Test Data From Magento 0

November 2nd, 2009

On many occasions we’ve needed to clear out the test data from a Magento site in preparation for going live.  It’s not as trivial as you’d think, but I found a nice sql script thanks to Elias Interactive that was just what I needed.  I’ve removed a bit as I didn’t need to reset all the order numbers, etc.

-- Reset Magento TEST Data

SET FOREIGN_KEY_CHECKS=0;

-- reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;

-- reset sales order info
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

Just run this script against the Magento database (make a backup first!).

=============================
“e-commerce done right

http://www.ifuelinteractive.com

Finding Files in Vista by Date Range 0

October 18th, 2009

I had no idea you could find files in Vista by date range until I found this post:

http://www.howtogeek.com/howto/windows-vista/find-files-within-a-date-range-with-windows-vista-search/

Lots of options, but simply put:

modified: 10/1/2009 .. 10/10/2009

or

modified: > 10/1/2009

That goes into the vista search box.  Not crazy about Vista, but I have to admit, that’s definitely handy!

=============================
“e-commerce done right

http://www.ifuelinteractive.com

Logging all SQL in Magento 2

October 18th, 2009

I’ve been looking for a way to log all the sql that Magento is running for debugging purposes. There are a number of logging mechanisms built in to Magento, but none that would allow you to log all the sql that’s being run. Finally, I’ve found a simple change that can be made to a core file (I know, not ideal because it will get overwritten when you upgrade Magento – but it’s only a few lines in one file).

The Change

1. Open the file <magentoroot>/lib/Varien/Db/Adapter/Pdo/Mysql.php.

2. Add the following lines:

$code = 'SQL: ' . $sql . "\r\n";
if ($bind) {
     $code .= 'BIND: ' . print_r($bind, true) . "\r\n";
}
$this->_debugWriteToFile("[".date('Y-m-d H:i:s')."] ".$code);

Add it to the “query” function as shown below:

public function query($sql, $bind = array())
{
     $this->_debugTimer();

     try {
          $sql = (string)$sql;
          if (strpos($sql, ':') !== false || strpos($sql, '?') !== false) {
               $this->_bindParams = $bind;
               $sql = preg_replace_callback('#(([\'"])((\\2)|((.*?[^\\\\])\\2)))#', array($this, 'proccessBindCallback'), $sql);
               $bind = $this->_bindParams;
          }

          $code = 'SQL: ' . $sql . "\r\n";
          if ($bind) {
               $code .= 'BIND: ' . print_r($bind, true) . "\r\n";
          }
          $this->_debugWriteToFile("[".date('Y-m-d H:i:s')."] ".$code);

          $result = parent::query($sql, $bind);
     }
     catch (Exception $e) {
          $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
          $this->_debugException($e);
     }
     $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }

more

jQuery, Magento and Ajax Add to Cart Redux 8

October 15th, 2009

My previous post on adding to the cart with ajax in Magento has generated enough interest – and pointed out enough flaws in my overly complex code – that I’ve decided to put together a simplified version, so here goes:

ajaxAddToCart.zip

Step 1: Create the server side script.
My sample script is called “addToCartTest.php” and I put it in a /scripts folder in the root of my Magento installation.


< ?php
include_once '../app/Mage.php';
Mage::app();

try{
     // usage /scripts/addToCartTest.php?product_id=838&amp;amp;amp;qty=1
     $product_id = '';

     // get query string
     if (!isset($_GET['product_id'])) { $product_id = ''; } else { $product_id = $_GET['product_id']; }
     if (!isset($_GET['qty'])) { $qty = '1'; } else { $qty = $_GET['qty']; }

     $product = Mage::getModel('catalog/product')->load($product_id);

     $session = Mage::getSingleton('core/session', array('name'=>'frontend'));
     $cart = Mage::helper('checkout/cart')->getCart();

     $cart->addProduct($product, $qty);

     $session->setLastAddedProductId($product->getId());
     $session->setCartWasUpdated(true);

     $cart->save();

     $result = "{'result':'success'}";
     echo $result;

} catch (Exception $e) {
     $result = "{'result':'error'";
     $result .= ", 'message': '".$e->getMessage()."'}";
     echo $result;
}

more

Creating a new Product Attribute and then using it on a page in Magento 0

September 29th, 2009

Creating a new product attribute and using it when you’re displaying a product turns out to be fairly simple – but I know for us at iFuel – and I think for lots of others based on the posts you see around the net, it ends up not being as simple as it seems.

For this example, we’ll create a new attribute called “ingredients”.  We need this to be a text field (text area to be exact) that Magento admins can enter the product ingredients.  Then we’ll need to be able to access this text when we display the product.

Attributes

Attributes are single pieces of information that can be assigned to any of the entities (models) in the Magento system.  There is an extensive user interface for creating and maintaining attributes and attribute sets for products.  But you can actually create attributes for other entity types, like categories, too.  (Creating an attribute for a category has to be done right in the database – I’ll try to cover that in a future post).

To create an attribute:

more

IIS LogParser 0

September 22nd, 2009

I recently had to analyze how much static data the web server was sending out on a daily basis.  We wanted to try to get a sense of what it would cost to host all this static content on the new Amazon Cloudfront CDN (content delivery network).

I knew there had to be something out there, but I didn’t know there was something right in the IIS 6 resource kit called LogParser.

There are a bunch of options in log parser, but the one I thought was way cool was the ability to basically “query” the log.  For example:

LogParser “Select count(*), sum(sc-bytes) from d:\logs\w3svc1\ex090922.log where cs-uri-stem like ‘%.jpg’ or cs-uri-stem like ‘%.gif’ or cs-uri-stem like ‘%.swf’ or cs-uri-stem like ‘%.css’ or cs-uri-stem like ‘%.js’ or cs-uri-stem like ‘%.pdf’ or cs-uri-stem like ‘%.png’ or cs-uri-stem like ‘%.cur’”
returns:

more

Tools I can’t live without 0

September 17th, 2009

Updated: 10/14/2009

Over the years I’ve collected together a list of the tools I use all the time. I know there are lots of other lists like this out there, but, well, they’re not mine!!

I’m going to try to keep adding to this list on a regular basis as I find new tools, or decide to move on from others.

more