iFUEL INTERACTIVE

A NY Interactive Agency and a Division of Agency212

See you on Flickr See you on Twitter See you on FaceBook Subscribe

Archive for October, 2009

Finding Files in Vista by Date Range
October 18th, 2009  |  NO COMMENTS  |  Vista
Tags: ,

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
October 18th, 2009  |  4 COMMENTS  |  Development, Magento
Tags: , , ,

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;
 }

Read more

jQuery, Magento and Ajax Add to Cart Redux
October 15th, 2009  |  12 COMMENTS  |  Development, Magento
Tags: , , , ,

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;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;
}

Read more

Copyright iFuel Interactive © 2010. All Rights Reserved.
Going up? Click here.A NY INTERACTIVE AGENCY