Posts Tagged ‘Magento’

PHP Storm searching for a string

Friday, May 11th, 2012

If you use PHP Storm, then this will help you find something in the code such as short tags for PHP.
We had an issue that some of our server environments did not have php short tags enabled. We needed to get rid of them!
So, what you do is open up PHP Storm..then (mac version ) and hold down control, and hold down shift, then press F and in the Options check the Regular expression box. Then in the Text to Find enter:

<\?[^(php|xml)]

Kudos to Brian for this tip!

Magento – how to decode the referer part of a URL

Friday, April 27th, 2012

If you have ever wondered how to figure out what that long string of letters and numbers are in a magento URL, here is how to do it.

Lets say that our URL is:

$string = 'www.whatever.com/customer/account/login/referer/aHR0cDovL2xvY2FsLmJsb29tMi5jb20vc2hvcA,,/';
Mage::helper('core')->urlDecode($string);

From what I can tell, it does the same thing as

base64_decode($string);

That will be decoded as

www.whatever.com/shop

Pretty fancy work there Magento! But I got you figured out.

How to get a block in a controller

Monday, April 16th, 2012

If you are in a Magento Controller and you need to get a different block and its methods….here is how:

// This function would be in a controller called something like CustomerController.php

class Bloom_BeautyBio_CustomerController extends Mage_Core_Controller_Front_Action
{
public function viewAction()
    {

/******** This is the secret sauce that gives you access to the class and its methods   ******/
        $viewingOthers = $this->getLayout()->createBlock('beautybio/beautybio')->viewingOtherMember();

        if($viewingOthers)
        {
            $this->_redirect('beautybio/customer/view/#photos');
            exit();
        }

        $this->loadLayout(array('default'));
        $this->renderLayout();
    }
}

Magento: Get a rough total for all rows in all tables in mysql

Tuesday, February 14th, 2012

$query = “SELECT table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘database_name_goes_here’”;

$result = Mage::getSingleton(‘core/resource’) ->getConnection(‘core_read’)->fetchAll($query);
$total = 0;

for( $i = 0; $i {
$total += $result[$i]['table_rows'];

}
echo ‘Grand Total = ‘ . $total;

magento and ajax

Wednesday, January 25th, 2012

http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-3-magento-controller-dispatch

Good tutorial

Magento – get shipping amount for a quote

Sunday, January 22nd, 2012

If your on the checkout/cart page, you can get the shipping totals:
$shipping_total = $this->getQuote()->getShippingAddress()->getShippingAmount();

Magento – Load customer by email address

Tuesday, December 20th, 2011

$customer = Mage::getModel(‘customer/customer’);
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->loadByEmail($email);

Magento log not working

Monday, December 19th, 2011

To fix your Magneto log: Mage::log() that is not logging you need to change the update the permissions for the magento var folder.

$ cd magento/location/on/server ( hit enter )

$ chmod -R 777 var/ ( hit enter )

That will prevent Magento from trying to use a default setting: /var/tmp//magento/var

Took me 2 hours, but hopefully this saves someone else from the same pain I had.

 

Magento – get current url

Wednesday, September 21st, 2011

$currentUrl = $this->helper(‘core/url’)->getCurrentUrl();

// Gives the base url of your magento installation
$baseUrl = Mage::getBaseUrl();

// Gives the url of media directory inside your magento installation
$mediaUrl = Mage::getBaseUrl(‘media’);

Magento – write to a log file

Thursday, August 18th, 2011

Magento has a built in feature to write to a log file.

In your code, you can use Mage::log(”).  In the quotes, you can put in anything you want, in my example, i am adding some text and then the dynamic customer email address.

Mage::log(‘Email sent to ‘ . $customer_email);

This should end up in the /var/log/system.log

Viewing that file, via command line, you can use:

$ tail /var/log/system.log and that will show you the last 10 results.

Make sure you remove this at some point or that log file will continue to grow and grow