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.

Monday 16 May 2016

Magento : Default to the first item for all required options

Stick the code into 

app/design/frontend/default/theme/template/catalog/product/view/options.phtml

near the end of the file look for this line: 


var opConfig = new Product.Options(<?php echo $this->getJsonConfig() ?>);


and replace with this:


var opConfig = new Product.Options(<?php echo $this->getJsonConfig() ?>);Event.observe(window'load', function() {$$('.product-options select').each(function(element{
element
.selectedIndex 1;opConfig.reloadPrice();});});


Refresh cache and load a product on the frontend which has custom options - after the page loads an option should automatically be selected.

Magento : How to remove Custom Options +Price($10.00)



Using the comment from user "R.S" above I was able to fix this issue for my website. Here is a screenshot from my website showing the fix works






Find the file
/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php
Go to lines 70 - 74
Remove this code from line 72
. ' ' . $priceStr . ''
OR comment out the code
$_value->getTitle() /*. ' ' . $priceStr . ''*/,
be sure to leave the "," at the end of the statement. My code now looks like this and works fine.
$select->addOption(
              $_value->getOptionTypeId(),
                $_value->getTitle() /*. ' ' . $priceStr . ''*/,
                array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false))
            );
I hope this helps you and other who are looking for the same fix!

Saturday 7 May 2016

Magento : Unknown cipher in list: TLSv1 [duplicate]




Go to downloader/lib/Mage/HTTP/Client/Curl.php,

            Edit Curl.php in notepad++ go line no. 377 or find

$this->curlOption(CURLOPT_SSL_CIPHER_LIST, 'TLSv1');

    to

$this->curlOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

Done! :)