Magento Themes and Magento Extensions

Magento Product Pages with Different Sized Images

Share
Posted on April 17th, 2013 | Posted by admin

Magento Product Pages with Different Sized Images

Occasionally you run into something that makes you scratch your head. Client has different product image sizes, think art prints. They can be divided into six groups. Some of them are 700×700, some are 700×400, you get the idea.

Client of course wants them to be full sized on the product page. That’s what they are selling.  So how do I get them all to display the proper size?  Custom Design, of course.

Magento allows you to select a different template, in Catalog>Manage Products. When you have the product page open, under Design Tab, there is an option called Custom Design, where you can select the template to use on this page.

Magento: More Flexibility For Your Layout Updates

Share
Posted on April 16th, 2013 | Posted by admin

Magento: More Flexibility For Your Layout Updates
I’ve been working on a project with a lot of requirements for certain templates or javascript to be added based on a lot of different conditionals and situations that the standard layout xml files do not really allow for. Fortunately, there are events and methods that you can use to add in xml on the fly without the need for layout xml files, allowing the ability to add in logic as to what and if something should be added or not.

First thing you are going to want to do is create an event observer to observe the ‘controller_action_layout_generate_xml_before’ event. That event will provide you with the layout object. By accessing the Update object from the layout, we can easily add in our own update:

$layout = $observer->getLayout();

$layout->getUpdate()->addUpdate('
    <reference name="content">
        <block type="module/block" name="the.name" template="your/template.phtml" />
    </reference>
');

If you wanted that block only to be added if the customer is not logged in, you could wrap the code in a conditional. You could get quite creative with this in implementing all sorts of cool functionality as we have done on our project. I hope this provides the tool to get you started!

Direct SQL queries in Magento

Share
Posted on April 15th, 2013 | Posted by admin

Magento and the Zend Framework that it is built upon offer a complete abstraction of data access, which allows you to get on with the creation of higher-level logic without worrying about database access. However, sometimes you just want to be able to run a few key SQL queries directly and bypass the abstraction. This post details the most direct method of doing so in Magento.

$conn = Mage::getSingleton('core/resource')->getConnection('core_read');

This will return a Varien_Db_Adapter_Pdo_Mysql object, a subclass of Zend_Db_Adapter_Abstract, which will allow you to run the Zend adapter methods directly. For example:

// Prints a list of all website names
$results = $conn->fetchAll("SELECT * FROM core_website;");
foreach($results as $row) {
    echo $row['name'] . "\n";
}

Create the checkout_cart_product_add_before observer in Magento

Share
Posted on April 14th, 2013 | Posted by admin

For some reason no one can explain, it appears that the event observer checkout_cart_product_add_before never existed in Magento (even though checkout_cart_product_add_after does). Say what?!??

Anyways, it’s fairly easy to go ahead and dispatch this event. Just add this to your module’s config.xml to rewrite the checkout/cart model:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0"?>
<config>
...
<global>
...
<models>
<checkout>
<rewrite>
<cart>Foo_Bar_Model_Checkout_Cart</cart>
</rewrite>
</checkout>
</models>
...
</global>
...
</config>

Then create your model that adds in the dispatch event to trigger the observers:

Image path in phtml files – Magento

Share
Posted on April 13th, 2013 | Posted by admin

Image path in phtml files – Magento
<?php  echo $this->getSkinUrl(‘images/your_image_name.jpg’) ?>

The function will return the full path of the image given as parameter .

Page 3 of 6«12345»...Last »