September 21, 2020

cm-mini

Thinking Magento

Cannot send headers; headers already sent

Have you started up your magento development site or live site to discover Cannot send headers; headers already sent. 

More often than not, this error is caused by the local.xml file not validating correctly after being edited for a server transfer.

Look at the following carefully, I've highlighted in bold where the mistake is normally made in the closing tags.

<username><![CDATA[]]></username>
<password><![CDATA[]]></password>
<dbname><![CDATA[]]></dbname>

If you use web development software, you can paste it in to an xml file and validate it or download the file and validate it.

Not the error you were looking for?

Next thing to look at is if your index.php file has been edit. If any additional code has been added before <?php in the index.php file, it will start to throw up this error.

It will not show in your logs that the error is coming from the index.php file, so I've suggested looking at this file before enabling debugging logs.

Last but not least you can enable logging to find the file that is causing the error.

Open app/code/local/Mage/Core/Controller/Response/Http.php

FIND

Mage::log('HEADERS ALREADY SENT: '.mageDebugBacktrace(true, true, true));

WITH

Mage::Log(print_r(get_included_files(),true));

This will start saving to /var/log/system.log, look for the last entry and the error will be in that file.

Found the error and fixed it? Undo the changes you made to Http.php, otherwise that log will grow very quickly and bring your website to a standstill before long.

Exclude Tier Prices From Catalog Price Rules

It maybe necessary for you to exclude products that already have tier prices from catalog price rule promotions. An example would be that you want to have a global sales rule for all products, but on some items you have to purchase a certain quantity in order to qualify for the discount. This work around has been applied to a multi-store magento website.

The following adjustments to Mage_CatalogRule_Model_Resource_Rule will be beneficial for you. 

Copy Mage_CatalogRule_Model_Resource_Rule to local directory structure

Find function _getRuleProductsStmt

FIND THE FOLLOWING

$select->joinInner(
array('product_website' => $this->getTable('catalog/product_website')),
'product_website.product_id=rp.product_id ' .
'AND rp.website_id=product_website.website_id ' .
'AND product_website.website_id='.$websiteId,
array()
);

ADD THE FOLLOWING BELOW IT

$select->joinInner(
array('pt' => 'catalog_product_index_price'),
'pt.entity_id=rp.product_id AND pt.customer_group_id IN(rp.customer_group_id) AND pt.tier_price IS NULL AND pt.website_id='.$websiteId,
array()
);

It's not the cleanest way of doing it and requires that you have Flat Catalog Products enabled in your System > Configuration. It will however get you to where you want to be and you can process your Catalog Price Rules without worrying about removing tier price discounts.

If this saved you hours of work or saved you from a headache, feel free to buy us a beer.

Manage Categories > Limited to 1000 Products Per Category

Did you recently move server or try to add more products in Magento through Catalog > Manage Categories and it reduced the number of products in the category to 1000 and no matter what you do it will not add another product.

This issue is down to your php.ini setting max_input_vars which is set to 1000 by default.

The recommended solution for this error would be to open you httpd.conf file or to create a virtualhost_global.conf

<LocationMatch "magentoshop/(index\.php/)?admin/">
<IfModule mod_php5.c>
php_value max_input_vars 8000
</IfModule>

The location match for the admin will help prevent the increased max_input_var from being exploited by Denial of Service (DDOS) attacks.

Not proficient with servers and just want to get out of this bind in a hurry, you can deploy a module fix on your server. Maksold is the original developer behind the event based module, I've just compiled it into a module for easy download and installation.

Download Module

Install on the server via ftp/sftp and flush your magento cache.

If this saved you hours of work or saved you from a headache, feel free to buy us a beer.

Configurable Product Is Creating A Simple Associated Product, But Ajax Loader Remains Spinning

As the title suggests for this one, this is an error you might have been receiving when you try and add associated products to a configurable product, however all that happens on the configurable screen is the spinning ajax wheel telling you it's loading.

The simple product is created correctly, however the screen for the configurable product does not update, your only option being to refresh the page.

I found this error was down to an update I made to combat against the Core_Url_Rewrite bug.

One solution had been to change the following code in 

app/code/core/Mage/Catalog/Model/Url.php 

Change:

if ($product->getUrlKey() == '' && !empty($requestPath) && strpos($existingRequestPath, $requestPath) === 0 ) 

To:

if (!empty($requestPath) && strpos($existingRequestPath, $requestPath) === 0 ) 

This change caused the issue with configurable products no longer being able to have the ajax loader update the associated products grid, requiring a refresh of the page to generate a new associated product and on top of that to save the association to the configurable.

So if you exhibit the symptons on your configurable ajax loader spinning indefinately and you made the above change. Then it's time to undo the change.

Note: In trying to debug this error, no error was being produced.

If this saved you hours of work or saved you from a headache, feel free to buy us a beer.

Create A Magento On Sale Category - The RIGHT Way

In a previous blog entry a few years back I wrote out a way to get sale products to show only. It's cumbsersome and not very elegant and work at a time when Magento was still fairly new.

In this entry I'm going to show you a revised way of doing this, which could be applied to filtering collections of any type such as price ranges, new products, custom attributes, date added etc, it's a fairly extensive list, which can be mapped in the .php file that you can find lower in the article.

So lets start with your category. Navigate in your admin to the category that you wish to show sale products only.

Catalog > Manage Categories or in EE Catalog > Categories > Manage Categories

Click on the category and go to the custom design tab and paste into the custom design layout box the following

<reference name="content">
<remove name="product_list"/>
<block type="catalog/product_sale" name="product_sale" alias="sale" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setLimit"><limit>32</limit></action>
<action method="setColumnCount"><columns>3</columns></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
<action method="addPriceBlockType">
<type>bundle</type>
<block>bundle/catalog_product_price</block>
<template>bundle/catalog/product/price.phtml</template>
</action>
</block>
</reference>
<reference name="product_list_toolbar">
<action method="setDefaultGridPerPage">
<limit>32</limit>
</action>
</reference>

One you've added that and saved, going to the category is going to produce an error because it's looking for the file Mage_Catalog_Block_Product_Sale.

Click here for file

Log in via ftp or sftp and place the file into app/code/local/Mage/Catalog/Block/Product/Sale

Going to the category will now show you only on sale products that are in stock.

Open up the Sale.php file if you wish to addAttributeToFilter. 

This tutorial is designed for those who just want to get the job done and out of the way and everyone needs a sale category the easy way.

If this saved you hours of work or saved you from a headache, feel free to buy us a beer.