MySql Find Replace String Function

I was looking to be able to find and replace references to a clients IP that were hard coded into product pages and such. Just a quick reference for myself and others whom may want to find and replace something from within a their database.

In order to use the following code I had to search for tables that contained what I wanted to replace. Then I could click on the table and find the specific row within the table that had the IP I wanted to replace. Type in the Table Name, then Row Name as well as what you are looking to find and replace with accordingly based on the following short code. The bolded items below have to be updated to match what you are trying to accomplish. Replace [] brackets text with appropriate info.

update [table_name] set [field_name] = replace([field_name],’[string_to_find]‘,’[string_to_replace]‘);

You may be able to find another database string function but I found this one safe and easy to use. It also allowed me to backup individual tables in case anything happened.

Remove Sidebar Callouts in Magento Layout

Here are a coupe of quick references for removing sidebar callouts in either a template/layout .xml file or custom page Layout per page. I used the following to remove some unwanted blocks from the homepage sidebar by updating the XML Layout for the homepage under the Design tab, such as the cart which is unnecessary on a website homepage.

<reference name=”right”>
<action method=”unsetChild”><name>cart_sidebar</name></action>
<action method=”unsetChild”><name>catalog.compare.sidebar</name></action>
<action method=”unsetChild”><name>right.reports.product.viewed</name></action>
<action method=”unsetChild”><name>right.permanent.callout</name></action>
</reference>

Magento 1.4.1.0 Upgrade Error

Fatal error:  Call to a member function toHtml() on a non-object in /public_html/app/code/core/Mage/Core/Model/Layout.php on line 529

The line in page.xml that seems to cause the problem is

<block type=”core/profiler” output=”toHtml”/>

Magento now uses an updated call:

<block type=”core/profiler” output=”toHtml” name=”core_profiler”/>

This should be one of the initial changes that can get your site live and updated when upgrading to Magento 1.4.1.0

Custom SEF Sidebar Navigation For Magento

I wanted to share a quick snippet of code that I created for adding a custom navigation section to your Magento left column area. I currently created this navigation area for a client to replace the layered navigation. The layered navigation has a lot of great features and organization but probably better severs as a multi -select drop down. Also in the previous versions of Magento the layered navigation was not search engine friendly.

This is not currently the case but I still find that there is not enough control over the category / subcategory display within the layered navigation. This custom navigation block could be used above some of the other build in features such as price, manufacturer etc. that is simple to accomplish with the layered navigation.

Also of note, I have found including other SEO centralized developers, that the layered navigation simply refreshs that page, so should you have content on the main category page, the layered navigation link creates confusion becuase the page content continues to display. [Read more...]

Make ‘Ship to This Address’ Default Option During Magento Checkout

As you may uncover there are a number of obvious changes that need to be made to the Magento core code. The default shipping option being one of them, this may in fact be yet another change that you would want to record and check during any upgrades as the code change is made to the core code of Magento.

Navigate to – app/code/core/Mage/Checkout/Block/Onepage/Billing.php

To update the default shipping option to ‘Ship to this Adress’ simply edit the core magento file located on your server:

Replace:

public function isUseBillingAddressForShipping()
{
if (($this->getQuote()->getIsVirtual()) || !$this->getQuote()->getShippingAddress()->getSameAsBilling())
{
return false;
}
return true;
}

With:

public function isUseBillingAddressForShipping()
{
if (($this->getQuote()->getIsVirtual()) || (!$this->getQuote()->getShippingAddress()->getSameAsBilling()))
{
return true;
} else {
return false;
}
}

Removing Extra Line Breaks Added To Magento Product Descriptions

In order to remove the extra line breaks that are added to Magento product descriptions. Simply update the following file:

/app/design/frontend/base/default/template/catalog/product/view/description.phtml

Edit the line nl2br($_description) to $_description, removing nl2br.

The added line breaks were causing issues in Firefox when creating unordered lists and such as the list code would have an added line break, <br>, or what appeared to be line spacing added to each item within the list.

Google Analytics Bug Fix for Magento 1.4.0.1

In installing Google Analytics you may notice that your account remains in a waiting to receive data state. Although Google Analytics has been recognized and installed correctly a small correction must be made to the source code of the Mage code.

You will want to edit the following file:
app/code/core/Mage/GoogleAnalytics/Block/Ga.php

…And add this simple line of code to line 179 in order to resolve the issue.

var _gaq = _gaq || [];

This issue has been reported and resolved already by the Magento Team through Issue #21456

How to Change an Existing Products Attribute Set in Magento

Unfortunately Magento does not have the function built into its setup to allow you the option to change a products attribute set once you have created a simple product. However, with the following coding updates, you can add the functionality to change a simple products attribute set directly on the Catalog > Manage Products page:

In app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php around line 253 ad:

$sets = Mage::getResourceModel(‘eav/entity_attribute_set_collection’)
->setEntityTypeFilter(Mage::getModel(‘catalog/product’)
->getResource()->getTypeId())->load()->toOptionHash();

array_unshift($statuses, array(‘label’=>”, ‘value’=>”));
$this->getMassactionBlock()->addItem(‘attribute_set’, array(
‘label’=> Mage::helper(‘catalog’)->__(‘Change attribute set’),
‘url’ => $this->getUrl(‘*/*/massAttributeSet’, array(‘_current’=>true)),
‘additional’ => array(
‘visibility’ => array(
‘name’ => ‘attribute_set’,
‘type’ => ‘select’,
‘class’ => ‘required-entry’,
‘label’ => Mage::helper(‘catalog’)->__(‘Attribute Set’),
‘values’ => $sets
)
)
));

And then in app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php (anywhere in the class) add a new function:

public function massAttributeSetAction(){

$productIds = $this->getRequest()->getParam(‘product’);
$storeId = (int)$this->getRequest()->getParam(‘store’, 0);
if(!is_array($productIds)) {
$this->_getSession()->addError($this->__(‘Please select product(s)’));
} else {
try {
foreach ($productIds as $productId) {
$product = Mage::getSingleton(‘catalog/product’)
->unsetData()
->setStoreId($storeId)
->load($productId)
->setAttributeSetId($this->getRequest()->getParam(‘attribute_set’))
->setIsMassupdate(true)
->save();
}
Mage::dispatchEvent(‘catalog_product_massupdate_after’, array(‘products’=>$productIds));
$this->_getSession()->addSuccess(
$this->__(‘Total of %d record(s) were successfully updated’, count($productIds)));
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}

$this->_redirect(‘*/*/’, array(‘store’=>(int)$this->getRequest()->getParam(‘store’, 0)));
}

Once you have added the two snippets of code you will now be able to select products from teh Manage Products list and update any products Attribute Set from the actions dropdown menu.

Simply Select ‘Change Attribute Set’ and select the appropriate attribute set from the new dropdown menu that appears to the right of Actions.

Pagination Update for Magento 1.4

With the update to Magento 1.4 comes a quick fix to the template file in order to allow your product listings to properly display the subpages or pagination for products.

In order to properly implement pagination into your product listings again, you must simply update your catalog.xml template file located in the layout directory of your template folder:

app/design/frontend/your-template/layout/catalog.xml

Add the follow code to properly call the pagination setup in the pager.phtml file:

<block type=”page/html_pager” name=”product_list_toolbar_pager”/>

Simply look for the toolbar.phtml block and paste in the pager block.

<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>

Adding Related Products to Magento

The step that I found most useful here was that you had to setup the drop down menu to ‘Any’ when searching for the product(s) you want to relate to a given product. Otherwise nothing shows when trying to search your product catalog.