Ina Code Blog

bunch of code in one place
Jun
10

Magento: How to move cart block from sidebar to header?

Posted by admin in Magento

Open file: /app/design/frontend/your_theme/your_theme/template/page/html/header.phtml and add this line where you want the cart block to be displayed:

<?php echo $this->getChildHtml(’cart_sidebar_head’) ?>

Open file: /app/design/frontend/your_theme/your_theme/layout/page.xml and insert this in block type page/html_header:

<block type=”checkout/cart_sidebar” name=”cart_sidebar_head” template=”checkout/cart/sidebar.phtml” />

You probably don’t need cart block in you sidebar anymore so open file: /app/design/frontend/your_theme/your_theme/layout/checkout.xml and remove or comment these lines:

<block type=”checkout/cart_sidebar” name=”cart_sidebar” template=”checkout/cart/sidebar.phtml” before=”-”>
<action method=”addItemRender”><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method=”addItemRender”><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method=”addItemRender”><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
</block>

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Jun
3

Magento: how to display a certain attribute?

Posted by admin in Magento

Here is how you can display certain attribute on product page. In my case I needed to display cost price:

<?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getCost()), ‘cost’) ?>

Or use this for your custom attributes:

<?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getCustom()), ‘Custom’) ?>

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Apr
20

Magento: remove break (br) tag from textarea

Posted by admin in Magento

After installing WYSIWYG editor to my magento site the <br /> tags were still added after each row in textareas. My main problem was the product description so I opened file /app/design/frontend/my_theme/my_theme/template/catalog/product/view/description.phtml and found line:

<?php echo $this->helper(’catalog/output’)->productAttribute($this->getProduct(), nl2br($this->getProduct()->getDescription()), ‘description’) ?>

and replaced it with:

<?php echo $this->helper(’catalog/output’)->productAttribute($this->getProduct(), $this->getProduct()->getDescription(), ‘description’) ?>

Basically I removed the nl2br() function which inserts the <br /> tags to the description text. You can do the same where ever the breaks are messing up your design view…

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Apr
10

Magento: how to change image resolution?

Posted by admin in Magento

Magento resizes and sets image resolution to 75 by default. It was a big problem for me so I had to change that.

To reset image resize resolution open file /lib/Varien/Image/Adapter/Gd2.php and find (line 80):

call_user_func($this->_getCallback(’output’), $this->_imageHandler, $fileName);

and replace it with:

if (IMAGETYPE_JPEG === $this->_fileType)call_user_func($this->_getCallback(’output’), $this->_imageHandler, $fileName,100);
else
call_user_func($this->_getCallback(’output’), $this->_imageHandler, $fileName);

For this change to take the effect you need to reset your cache. In your administration go to System -> Cache Management and Clear Image Cache and Refresh All Cache!

Note: Currently I’m using Magento v.1.3.0.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Feb
27

Magetno problem: dbModel read resource does not implement Zend_Db_Adapter_Abstract

Posted by admin in Magento

I recived CSRF Attack Prevention message from Magento team saying that Magento admin has an vulnerability if attacker knows the admin path. Probably like most people I also used /admin/ to access the Magento administration. The message adviced to change it to something specific, so I did. And the page just crashed!?!

I got the error:

dbModel read resource does not implement Zend_Db_Adapter_Abstract
Trace:
#0 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php(68): Varien_Data_Collection_Db->setConnection(false)
#1 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/Config.php(789): Mage_Core_Model_Mysql4_Collection_Abstract->__construct(Object(Mage_Core_Model_Mysql4_Website))
#2 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/Config.php(831): Mage_Core_Model_Config->getModelInstance(’core_mysql4/web…’, Object(Mage_Core_Model_Mysql4_Website))
#3 /home/chasi/public_html/trgovina/app/Mage.php(345): Mage_Core_Model_Config->getResourceModelInstance(’core/website_co…’, Object(Mage_Core_Model_Mysql4_Website))
#4 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/Abstract.php(200): Mage::getResourceModel(’core/website_co…’, Object(Mage_Core_Model_Mysql4_Website))
#5 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/Abstract.php(205): Mage_Core_Model_Abstract->getResourceCollection()
#6 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/App.php(384): Mage_Core_Model_Abstract->getCollection()
#7 /home/chasi/public_html/trgovina/app/code/core/Mage/Core/Model/App.php(247): Mage_Core_Model_App->_initStores()
#8 /home/chasi/public_html/trgovina/app/Mage.php(432): Mage_Core_Model_App->init(”, ’store’, Array)
#9 /home/chasi/public_html/trgovina/app/Mage.php(453): Mage::app(”, ’store’, Array)
#10 /home/chasi/public_html/trgovina/index.php(52): Mage::run()
#11 {main}

I searched and searcher the forums and Magento pages and got some ideas on what may solve the problem. I had to contact my server provider and ask them to delete all cache (/var/cache/) and session (/var/session/) files. I couldn’t do it myself as my permission wasn’t sufficient. If that still doesn’t solve the problem ask them to restart the Apache aswell. That worked for me and the Magento shop is back and runing :)

The other solution would be to reinstall Magento. Hmmmm…

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Feb
24

Magento speed problem

Posted by admin in Magento

Modifying, I mean uncommenting few lines in your .htaccess file can speed up your magento site a looooot. Find these lines below and just remove # before them.

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary

# enable resulting html compression
php_flag zlib.output_compression on

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Jan
27

Magento: Add static block

Posted by admin in Magento

Go to Magento admin uder CMS -> Static Blocks and Add New Block. Insert Block Title, Identifier (for example: my-new-block), set Status to Enabled, insert block Content and Save Block.

If you want to put your static block in left column open file /app/design/frontend/your_theme/your_theme/template/callouts/left_col.phtml and insert code below where you want the static block to apear:

<?php echo $this->getLayout()->createBlock(’cms/block’)->setBlockId(’my-new-block’)->toHtml() ?>

You can put this code wherever you want the block to apear, for exapmle right_col.phtml, 3columns.phtml, … Sky is your limit …

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Jan
12

Magento: Change image background color

Posted by admin in Magento

If possible I always avoid modifing system core files, but in this case I couldn’t find any other solution. So to change your image background color open file /app/code/core/Mage/Catalog/Model/Product/Image.php and find:

protected $_backgroundColor  = array(255, 255, 255);

and replace it with:

protected $_backgroundColor  = array(0, 0, 0);

This will change the white background color to black. Change array(0, 0, 0) to whatever color you need.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]