Tuesday 15 November 2016

Magento : Add Order Status to Last 5 Orders on Magento Admin Dashboard

It’s happened to us all folks, you log onto the admin dashboard you see an new order in the last 5 orders list and automatically think to yourself, “Nice, I have a new order!”. Well hold on a minute, this is not always the case, the order could have be abandoned or pending payment. This has happened to me a few too many times this week so I decided, I NEED to have the order status along with the Customer Name, Items & Grand Total.

If you follow the instructions below, I will show you how to add Status to the Last 5 Orders grid.


Modified Grid

First of all, and this is a must when modifying any core files, create a local copy of the following file:

Copy app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php

To app/code/local/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php

Open your local copy of Grid.php and around line 114 add the following:

$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type'  => 'options',
'width' => '70px',
'sortable'  => false,
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));


Save and upload the local copy and you should now have a column called Status in your Last 5 Orders.

Done! :)


Monday 26 September 2016

Magento : Enable Address Fields on Customer Registration Forms


In order to enable address fields in Magento customer registration forms you only need to enable the attribute setShowAddressField.

To do so either add the following in your template or in the base local.xml (/app/design/frontend/base/default/layout/local.xml):

<customer_account_create> 
  <reference name="customer_form_register"> 
    <action method="setShowAddressFields">
      <param>true</param>
    </action> 
  </reference>
</customer_account_create>

As always, make sure to reload your cache afterwards. This setting will enable to execution of

<?php if($this->getShowAddressFields()): ?>

in register.phtml (/app/design/frontend/base/default/template/customer/form/register.phtml).

Done! :)

Monday 19 September 2016

Magento : How to remove index.php from URLs

To remove index.php from urls follow the below steps :
1) Log-in Magento Admin
2) Go to System -> Configuration -> Web.
3) from ‘Search Engine Optimisation’ tab “Use Web Server Rewrites” select ‘YES’.
4) Make sure your “Secure” and “Unsecure” base urls should end with “/”.
5) now edit your .htaccess ( will be in magento root folder ) and pate the below code and save:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

now your index.php issue will be solved.

Done! :)

Tuesday 6 September 2016

Magento : An Error Occurred While Saving The URL Rewrite

I found out that issue is because the system could not insert a duplicated record. So something was wrong with “core_url_rewrite” table.

I fixed the issue by logging into phpMyadmin, find that table and truncate all records (do not worry about this because all URL rewrites will be generated again when you reindexed).

After that, I logged in the backend, refresh Magento cache and reindex again. Everything is ok now.

Wednesday 31 August 2016

Magento : How to fix Email sending problem

Just do a small change in order.php /app/code/core/Mage/Sales/Model/Order.php

If you don't want to change core file so please create directory  /app/code/local/Mage/Sales/Model/ like this and put Order.php inside folder

Find code and replace it

$mailer->setQueue($emailQueue)->send();

To

$mailer->send();

Done! :)

Magento : How to fix Email sending problem in Magento ver. 1.9.2.0


In latest Magento versions, all emails are being sent via CRON job. Every email will be queued and sending will depend on the set interval, in general 5 minutes.


By default, Magento has already set CRON jobs at
System -> Configuration -> Advanced -> System -> Advanced -> Cron


If CRON job is not working properly, please follow below steps to send instant emails.


Copy Template.php file from
app -> code -> core -> Mage -> Core -> Model -> Email


Create folder structure like
app -> code -> local ->  Mage -> Core -> Model -> Email


Paste Template.php file in Email folder


Open Template.php file and go to line number 407 or search for the following code
if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {


Replace above code with following
if (!($this->hasQueue()) && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {


This trick works perfectly on Magento ver. 1.9.2.0

Tuesday 30 August 2016

Magento : How to remove decimal in price


First create currency class in path /app/code/local/Mage/Directory/Model/Currency.php

copy the content from file in core /app/code/core/Mage/Directory/Model/Currency.php and paste in your new file /app/code/local/Mage/Directory/Model/Currency.php

Go to line no. 222 and find code your file

return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);

and replaced it by this line :

return $this->formatPrecision($price, 0, $options, $includeContainer, $addBrackets);

Clear your caches and it’s done. :)

Magento : Delete all Customer Data by Sql

Go to in you phpmyadmin select database click on sql tab then run

SET FOREIGN_KEY_CHECKS=0;

-- Customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;

-- Search
TRUNCATE `catalogsearch_query`;
TRUNCATE `catalogsearch_fulltext`;
TRUNCATE `catalogsearch_result`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;
ALTER TABLE `catalogsearch_fulltext` AUTO_INCREMENT=1;
ALTER TABLE `catalogsearch_result` AUTO_INCREMENT=1;

-- Polls
TRUNCATE `poll`;
TRUNCATE `poll_answer`;
TRUNCATE `poll_store`;
TRUNCATE `poll_vote`;
ALTER TABLE `poll` AUTO_INCREMENT=1;
ALTER TABLE `poll_answer` AUTO_INCREMENT=1;
ALTER TABLE `poll_store` AUTO_INCREMENT=1;
ALTER TABLE `poll_vote` AUTO_INCREMENT=1;

-- Reports
TRUNCATE `report_viewed_product_index`;
ALTER TABLE `report_viewed_product_index` AUTO_INCREMENT=1;

-- Newsletter
TRUNCATE `newsletter_queue`;
TRUNCATE `newsletter_queue_link`;
TRUNCATE `newsletter_subscriber`;
TRUNCATE `newsletter_problem`;
TRUNCATE `newsletter_queue_store_link`;
ALTER TABLE `newsletter_queue` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_subscriber` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_problem` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_queue_store_link` AUTO_INCREMENT=1;

-- Wishlist
TRUNCATE `wishlist`;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Done! :)

Magento : Delete all Orders, Sales & Customer Data by Sql

Go to in you phpmyadmin select database click on sql tab then run

SET FOREIGN_KEY_CHECKS=0;

##############################
# SALES RELATED TABLES
##############################
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;            # ??
TRUNCATE `sales_invoiced_aggregated_order`;        # ??
TRUNCATE `log_quote`;

ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;

#########################################
# DOWNLOADABLE PURCHASED
#########################################
TRUNCATE `downloadable_link_purchased`;
TRUNCATE `downloadable_link_purchased_item`;

ALTER TABLE `downloadable_link_purchased` AUTO_INCREMENT=1;
ALTER TABLE `downloadable_link_purchased_item` AUTO_INCREMENT=1;

#########################################
# RESET ID COUNTERS
#########################################
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;


##############################
# CUSTOMER RELATED TABLES
##############################
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `tag_properties`;            ## CHECK ME
TRUNCATE `wishlist`;
TRUNCATE `log_customer`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `tag_properties` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;


##############################
# ADDITIONAL LOGS
##############################
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `report_event`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `sendfriend_log`;
### ??? TRUNCATE `log_summary`

ALTER TABLE `log_url` AUTO_INCREMENT=1;
ALTER TABLE `log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
ALTER TABLE `report_viewed_product_index` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
### ??? ALTER TABLE `log_summary` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;



Done! :)

Monday 29 August 2016

Magento : Add ‘Customer Group’ to Registration Form.

Step -1

app/desing/frontend/themepackage/yourtheme/template/customer/form/register.phtml

Add felow start form

<div>
<label for=”group_id”><?php echo $this->__(‘Group’) ?><span class=”required”>*</span></label><br/>
<select name=”group_id” id=”group_id” title=”<?php echo $this->__(‘Group’) ?>” class=”validate-group required-entry input-text” />
<?php $groups = Mage::helper(‘customer’)->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<option value=”<?php print $group[‘value’] ?>”><?php print $group[‘label’] ?></option>
<?php } ?>
</select>
</div>

Step-2

app/code/core/Mage/Customer/controllers/AccountController.php

Go to line no 294 or find $customer = $this->_getCustomer(); add code felow this line

$customer->setGroupId($this->getRequest()->getPost(‘group_id’));

OR

if ($this->getRequest()->getParam('group_id', false)) {      
    $customer->setGroupId($this->getRequest()->getParam('group_id', false)); 
}

This code for if user not select customer group so form send automatic select default value


Step-3

app/code/core/Mage/Customer/etc/config.xml

Find customer_account and Add customer_account node

<group_id><create>1</create><update>1</update></group_id>


Done! :)

Saturday 27 August 2016

Magento : Get Current Store Details (ID, Code, Name and Status)

// Gets the current store's details
$store = Mage::app()->getStore();

// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();

// Gets the current store's code
$storeCode = Mage::app()->getStore()->getCode();

// Gets the current website's id
$websiteId = Mage::app()->getStore()->getWebsiteId();

// Gets the current store's group id
$storeGroupId = Mage::app()->getStore()->getGroupId();

// Gets the current store's name
$storeName = Mage::app()->getStore()->getName();

// Gets the current store's sort order
$storeSortOrder = Mage::app()->getStore()->getSortOrder();

// Gets the current store's status
$storeIsActive = Mage::app()->getStore()->getIsActive();

// Gets the current store's locale
$storeLocaleCode = Mage::app()->getStore()->getLocaleCode();

// Gets the current store's home url
$storeHomeUrl = Mage::app()->getStore()->getHomeUrl();

MAGENTO : EXPORT CATEGORIES AND IDS TO CSV




<?php
require_once 'app/Mage.php';
Mage::app();
$allCategories = Mage::getModel ( 'catalog/category' );
$categoryTree = $allCategories->getTreeModel();
$categoryTree->load();
$categoryIds = $categoryTree->getCollection()->getAllIds();
if ($categoryIds) {
$outputFile = "var/export/categories-and-ids.csv";
$write = fopen($outputFile, 'w');
foreach ( $categoryIds as $categoryId ) {
$data = array($allCategories->load($categoryId)->getName(), $categoryId);
fputcsv($write, $data);
}
}
fclose($write);
?>

Tuesday 23 August 2016

Magento : Blank white screen frontend issue

Magento shows blank/empty page, I was scared when this happened on one of the live site but after some exercises with source code and using internet I come to find out the solution. Most probably it could have memory issue or the compilation tool.
In order to troubleshoot the issue,  your first step is to edit index.php, find out bellow line and uncomment
ini_set('display_errors', 1);
If its not available, insert this line somewhere at the top of the file and try out bellow solutions.
Try – 1 : Disable ComplierGo to System -> Tools -> Compilation and Disable you Complier and clear/flush magento cache data. In most of the cases this would solve the issue.
Try – 2 : Improve PHP Memory LimitIf you can access php.ini OR using .htaccess in the root OR edit index.php add bellow line right after ini_set(‘display_errors’, 1);
ini_set('memory_limit', '256M');
Try – 3 : Design changesIf you have recently installed new theme try to switch interface to a previously used one. Flush Magento cache after each operation. Magento will switch to default theme if it can not find a custom one.
I hope these would resolve  your problem.

Magento : Delete All Products Using PhpMyAdmin


Deleting all products on magento via the admin panel can be almost imposible when you have more than 10.000 products.

A quick way to do this would be thru phpmyadmin.

Before running this code please make sure you have a backup of the entire database.

This code worked fine on magento 1.7.0.2

Copy and paste this code @ phpmyadmin under SQL tab and run it.


SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_category_product_index`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `cataloginventory_stock`;
INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
TRUNCATE TABLE `catalog_product_entity`;
SET FOREIGN_KEY_CHECKS = 1;


Now you have Done! :)

Magento : Image upload error

Go to magneto root directory and find lib\Varien\File\Uploader.php

Edit file and go line no. 259


$params['object']->$params['method']($this->_file['tmp_name']);

should be

$params['object']->{$params['method']}($this->_file['tmp_name']);

Done! :)

Saturday 20 August 2016

Magento : Unknown cipher in list: TLSv1 [duplicate]

First going to Curl.php in downloader/lib/Mage/HTTP/Client/Curl.php,

Edit file going to line no 377 and try changing:

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

to

$this->curlOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

Done!

Magento : PHP extension "soap" must be loaded.

Going to php.ini file


I edited php.ini and removed the leading semicolon ( ; ) from extension=php_soap.dll.

like this

;extension=php_soap.dll
to
extension=php_soap.dll

After restarting Apache I was able to proceed with the installation without any other issues.

Done!

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.

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! :)

Saturday 23 April 2016

Magento : STOCK QUANTITY ON MAGENTO PRODUCT PAGE

Warning: This is a quick-n-dirty hack and will not work on all product types.

Instead of just showing the “in stock” and “out of stock” messages, we want to have an in-between message to show that stock levels are running low. This is easily done, by editing the following file:

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

We change the contents of the file to the following:

<?php
$_product = $this->getProduct();
$_quantity = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
?>

<?php if ($_product->isAvailable()): ?>
  <?php if ( intval($_quantity) < 10 ): ?>
    <p class="availability last-stock"><?php echo $this->__('Availability:') ?>
      <span><?php echo $this->__('Only '); echo $_quantity; echo $this->__(" left"); ?></span>
    </p>
  <?php else : ?>
    <p class="availability in-stock"><?php echo $this->__('Availability:') ?>
      <span><?php echo $this->__('In stock') ?></span>
    </p>
  <?php endif; ?>
<?php else: ?>
  <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?>
    <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

<?php echo $this->getChildHtml('product_type_data_extra') ?>
<?php echo $this->getPriceHtml($_product) ?>


That’s it!

We just created a warning-type level once stock drops to less than 10 items. Meanwhile, both the “in-stock” and “out-of-stock” messages are preserved. This can be easily styled using CSS. Note we added the class “last-stock” to our new p-tag

Magento : Disable/ Remove “Estimate Shipping and Tax”

We can solve this issue two way.
First way :
Create local.xml file with below code and upload your theme layout folder
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<layout>
<checkout_cart_index>
<reference name=”content”>
<block name=”checkout.cart”>
<remove name=”checkout.cart.shipping”/>
</block>
</reference>
</checkout_cart_index>
</layout>
Second way :
Remove the following code from /app/design/frontend/yourtheme/layout/checkout.xml
<block type=”checkout/cart_shipping” name=”checkout.cart.shipping” as=”shipping” template=”checkout/cart/shipping.phtml”/>
Done! :)

Sunday 20 March 2016

Magento : How to Rename the Attribute Code?

Connect to your Magento database using your favourite database GUI (PHPMyAdmin, HeidiSQL, MySQL Workbench, etc.).
Caution: backup your database
Go to the table eav_attribute and edit the column attribute_code. You can rename the attribute code here.
Once you have renamed the attribute code in the database, go to the Magento admin and re-index (System > Index Management) all indexes.

Magento : Get Logged In Customer’s Group ID

<?php
/* Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
    /* Get the logged in customer's group ID */
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    /* Check if the logged in customer's group ID matches with the ID you are after */
    /* Customer group IDs are listed against each group under Admin > Customers > Customer Groups */
    if($customerGroupId == 3) :
        echo 'Welcome Retailer';
    endif;
endif;
?>

You can also write static blocks or custom variables to contain group specific information. You can name the static block identifier based on the $customerGroupId and retrieve it on the front end.

Magento : Check if CMS Static Block is Enabled / Active

Static blocks in Magento are really useful. They offer an easy way to insert content into various parts of the template. You are only limited by your imagination. You can check if the static blocks are enabled, before printing them to screen.
<?php 
if(Mage::getModel('cms/block')->load('static-block-identifier')->getIsActive()) : 
    echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('static-block-identifier')->toHtml(); 
endif; 

?>

Magento : Get CMS Static Block Model Data (Title, Status, Content)

You can store template and HTML data in Magento’s static blocks. If you want to pull it into your PHTML templates, just call load up the model and use the data fields.

<?php
$staticBlock = Mage::getModel('cms/block')->load('static-block-identifier');
echo $staticBlock->getTitle();
echo $staticBlock->getIdentifier();
echo $staticBlock->getIsActive();
echo $staticBlock->getContent();

?>

Magento : Get Current Package Name and Theme Name

// To get the current package name of the Magento store / site
Mage::getSingleton('core/design_package')->getPackageName();

// To get the current theme of the Magento store / site
Mage::getSingleton('core/design_package')->getTheme('frontend');

// You can pass 'locale', 'layout', 'template', 'default', or 'skin' into the above function.

Magento : Disable Toolbar Sort / Order By Memory Cookie

<reference name="product_list_toolbar">
    <action method="disableParamsMemorizing"/>
</reference>