Posts Tagged ‘Magento’

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

Magento – create a static block in footer

Tuesday, July 26th, 2011
Static blocks are a Magento feature that makes adding content to your Magento site easy and convenient. Static blocks allow for your Magento site to be updated via the admin panel making it faster than having to “hard-code” every time you need to make a change to your website. Static blocks can be used anywhere on your Magento site to display text, images, & navigation.  Some Magento designs have static blocks already in place for your convenience; however, you might have to install them yourself. Below is a simple tutorial on how to install a static block in the footer of your Magento site

Step One: Create Static Block in Your Magento Admin

Magento Admin Panel—>Static Blocks—>Add New Block

1) Name your Static Block, in this case Custom footer Links

2) Label the Identifier (This is the link you will use to call the block later) in this case, custom-footer-links

3) Choose what store view you would like it to render in

4) Set Status to Enabled

2)Now for the fun part! Add your navigation links to the block.   Make sure to use <style> to make them match your sites color and theme.

Step Two: Inserting Code to Call the Static Block

This part is going to require you to FTP into your Magento site and modify footer.phtml
app—>design—>frontend—->default—>(your template)—>template—>page—>footer.phtml

Find where in the footer you want your navigation links to display and insert:
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘custom-footer-links’)->toHtml(); ?>

Now most of the time the Static block should display just fine but in some cases you are going to have do some extra steps to have the block display.

1) Instead of inserting:
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘custom-footer-links’)->toHtml(); ?>

Use:

<reference name=”left”>
<block type=”cms/block” name=”left.permanent.callout”>
<action method=”setBlockId”><block_id>custom-footer-links</block_id>
</action>
</block>
</reference>

2)Modify catalog.xml
app—>design—>frontend—>default—>f002—>layout—>catalog.xml

Add under <!– Mage_Catalog –>

<block type=”cms/block” name=”left.permanent.callout”>
<action method=”setBlockId”><block_id>custom-footer-links</block_id>
</action>
</block>

Magento – How to tell if you are on the home page or not

Tuesday, July 26th, 2011
How to tell if your on the home page in magento or not
if($this->getIsHomePage()) {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}

Or you can try this:

$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}