Saturday, 20 August 2016

Magento : Fatal error: Uncaught Error: Function name must be a string in C:\xampp\htdocs\em0126\app\code\core\Mage\Core\Model\Layout.php:555 Stack trace: #0

Fatal error: Uncaught Error: Function name must be a string in ... app\code\core\Mage\Core\Model\Layout.php:555 ...

This error was easy to fix because the problem was in the following line:

$out .= $this->getBlock($callback[0])->$callback[1]();

Instead it should be:

$out .= $this->getBlock($callback[0])->{$callback[1]}();

Now refresh the page

Done! :)

Tuesday, 21 June 2016

Magento : Add Terms and Conditions Checkbox during Checkout

To enable the terms and conditions check box at checkout, follow the below steps:
1. In the admin panel, go to System > Configuration > Sales > Checkout > Checkout Options and set Enable Terms and Conditions to Yes.  Then Save Config.
2. Now (from the top menu), go to Sales > Terms and Conditions.
3. Click Add New Condition and fill in the required fields.
Condition Name is only shown to the admin and can be whatever you’d like.
Status should be Enabled.
Show content as sets whether html can be displayed in the terms and conditions content box.  Set this to yes if you want to style the content or add links.
Checkbox text is shown next to the check-box, for example “I agree to the terms and conditions of this website.”
Content is the content that will be shown under the checkbox.  You can place the entire text of your terms and conditions here or include a link to it.
4. Click Save Condition and you are all set.  Remember to test your checkout to see how everything looks and make sure it is working correctly.

Done!

Monday, 20 June 2016

Magento : Remove recently added items

You simply use following xml layout update in local.xml:

   <remove name="cart_sidebar" />
OR

<action method="unsetChild"><name>cart_sidebar</name></action>


Done! 

Thursday, 26 May 2016

Magento : Add Back To Top Button

Step-1 Add this Div in Footer.phtml


<div id="back_top" style="display: block;"></div>

Step-2 Add this Java script in footer.phtml


<script type="text/javascript">
    jQuery(function() {
        jQuery(window).scroll(function() {
        if(jQuery(this).scrollTop() > 300) {
            jQuery('#back_top').fadeIn();    
        } else {
            jQuery('#back_top').fadeOut();
        }
    });
       jQuery('#back_top').click(function() {
        jQuery('body,html').animate({scrollTop:0},500);
    });    
    });
 </script>

Step-3 Add this CSS in styles.css


<style type="text/css">
    #back_top {
    background-color: red;
    bottom: 22px;
    cursor: pointer;
    display: none;
    height: 44px;
    position: fixed;
    right: 200px;
    width: 54px;
}
</style>

Done! :)

Wednesday, 25 May 2016

Magento : Adding website/store filter to category product grid in Magento

It appears the Magento developers didn’t think this one through enitrely as this to me is something that should be there by standard. Not everyone has a multi-website set up and products that span two stores, yet that’s the very reason this kind of thing can be a pain to add on not just here but also in the main catalog view and in other views like reports.

I am detailing this by editing core files, this is not the correct way and should be added via a module or local override, which in this case would be very little extra work,  but in essence the steps you need to take are modifying/overriding
Mage_Adminhtml_Block_Catalog_Category_Tab_Product
First find the function
_addColumnFilterToCollection
Add the following if statement at the top, this is checking for our column which we later add and looking up the website ID’s
 if ($column->getId() == 'website_id') {
            $this->getCollection()->joinField('websites',
                'catalog/product_website',
                'website_id',
                'product_id=entity_id',
                null,
                'left');
            return parent::_addColumnFilterToCollection($column);
        }
At the bottom of the function you need to modify the lines like so, to bring in the website names.
parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
Next add a new function directly underneath the above, this is a custom column callback for our new column which we add next, which is simply a way of adding more criteria onto our $collection, in this case we add the store filter.
   protected function _websiteFilter($collection, $column)
    {

        if (!$value = $column->getFilter()->getValue()) {
            return $this;
        }

        $store = Mage::app()->getWebsite($value);
        $collection->addStoreFilter($value);

        return $this;
    }
Finally add the website column, with our custom filter callback
  if (!Mage::app()->isSingleStoreMode()) {
                         $this->addColumn('websites',
                                 array(
                                     'header'=> Mage::helper('catalog')->__('Websites'),
                     'width' => '100px',
                     'sortable'  => false,
                     'index'     => 'websites',
                     'type'      => 'options',
                     'options'   => Mage::getModel('core/website')->getCollection()->toOptionHash(),
                                     'filter_condition_callback' => array($this, '_websiteFilter'),
             ));
         }
And you’re done.

Magento : Upgrading to Magento 2

Having had the opportunity to work on a new build using Magento 2 the architecture of the application has changed significantly, to me it has definitely increased the difficulty of getting a Magento project up and running but in return offers a more granular and organised application to work with.
With this view I think it’s unlikely that you would upgrade your site to v2. Magento have not given an upgrade path to 2.0 and I doubt they will, so it’s probably worth waiting for the opportunity to re-design the site before moving over to the new platform.
Magento have committed to 3 years from general release of 2.0 so that gives you till around 2019 to move over. In the meantime that means they will continue to provide security patches and support for the 1.x platform.

Tuesday, 17 May 2016

Magento : 404 page not found when trying to access CMS -> Pages in admin panel


Some leftover CMS-Page database entries were referencing a store_id of a store that no longer existed after I deleted it.

So here's what solved it for me:

Find out the ids of your stores: Under System > Manage Stores in the column Store View Name look for the Store's id that pop up when hovering the link and also in the link url
(e.g. ...admin/system_store/editStore/store_id/3/key/...)

To be safe, make a database backup under System > Tools > Backups

Go to your database and find the table cms_page_store. Delete all entries with a store id in the field store_id that points to a store, that does no longer exist.

Refresh CMS > Pages, 404 should be gone.