Browsing articles tagged with "magento admin Archives - Kalpesh Mehta"
Oct 7, 2014
kalpesh

Magento fix for error “Code already exists.”

Fix for Magento error Code already exists. in Sales > Tax > Manage Tax Rules, when saving the rule.

When trying to save Tax rules in Magento, you may get “Code already exists.” error if there are lots of tax rates passing in POST. Magento error is not making sense here, as the issue is something different. Basically when you post the data in PHP, it limits maximum post variables which should pass to the server. For me, that limit was 1000 in max_input_vars, which by changing to 20000 solved this issue and Magento successfully accepted my changes without any error.

To change max_input_vars to higher value, you need to edit in PHP.ini file for max_input_vars like this:

1
max_input_vars 20000

But as editing PHP.ini requires restarting apache to reflect the changes, I did the change in .htaccess file just for Tax rule modification and later reverted it.

You can edit .htaccess to make this change by copy-pasting below line at the end of the file:

1
php_value max_input_vars 20000

Now you should be able to change Tax rules even if you have lots of tax rates posting through for that change! I prefered to revert .htaccess back to what it was as I didn’t need to change tax rules frequently.

Note: If the above does not solve the issue for you, make sure your Tax Rule name is not duplicating with another tax rule name.

Sep 23, 2014
kalpesh

Magento: Show gift card details in admin order page

Magento display gift card details (code and amount) in Order View page of admin panel. When customer uses gift card in their order Magento does not display gift card code and amount details in admin panel which makes it tough to know. Customer can pay partially through gift card which makes even tougher as Magento only shows payment information of other method and not gift card amount deductions.

Below code will show you an additional block in magento admin panel with Gift Card details. If gift card is not used in an order, the block will simply no shown.

Open the file app/design/adminhtml/default/default/template/sales/order/view/edit.phtml

Add the below lines of code anywhere you want the gift card block to appear. I have used it after Account Information block.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php $cards = unserialize($_order->getGiftCards());
        if($cards!='' && count($cards)>0) { ?>
<div class="box-left">
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4 class="icon-head head-account"><?php echo Mage::helper('sales')->__('Gift Cards') ?></h4>
        </div>
        <div class="fieldset">
            <div class="hor-scroll">
                <table cellspacing="0" class="form-list">
                <?php foreach ($cards as $card) { ?>
                <tr>
                    <td class="label"><label><?php echo Mage::helper('sales')->__('Giftcard Code') ?></label></td>
                    <td class="value">
                        <div style="font-weight:bold"><?php echo $card['c'];?></div>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label><?php echo Mage::helper('sales')->__('Giftcard Amount') ?></label></td>
                    <td class="value">
                        <div style="font-weight:bold"><?php echo $card['a'];?></div>
                    </td>
                </tr>
                <?php }?>
                </table>
            </div>
        </div>
    </div>
</div>
<?php }?>
Jan 8, 2012
kalpesh

Magento: Save shipment information of order programatically

After creating invoice and shipment, it is necessary to add tracking information to shipment. Here is how to write a observer which will invoke as shipment save method is called and save tracking information programatically.

config.xml – under global -> events node

1
2
3
4
5
6
7
8
9
<sales_order_shipment_save_before>
                <observers>
                    <namespace_modulename_ship_before>
                        <type>singleton</type>
                        <class>Namespace_Modulename_Model_Observer</class>
                        <method>salesOrderShipmentSaveBefore</method>
                    </namespace_modulename_ship_before>
                </observers>
            </sales_order_shipment_save_before>

Observer.php -> under Model directory of module

1
2
3
4
5
6
7
8
9
public function salesOrderShipmentSaveBefore($observer)
    {
            $shipment = $observer->getEvent()->getShipment();
            $track = Mage::getModel('sales/order_shipment_track')
                        ->setNumber('824343454454') //tracking number / awb number
                        ->setCarrierCode('aramex') //carrier code
                        ->setTitle('Aramex'); //carrier title
                    $shipment->addTrack($track);
       }
Jan 5, 2012
kalpesh

Magento: Wrong count in admin Grid when using GROUP BY clause, overriding lib module

If you have noticed or not, in version 1.5 of Magento when you use GROUP BY clause in any Grid.php file in admin, the count always display wrong. Many times it displays 1 even if there are hundreds of records. Due to this your pagination also doesn’t work. This is a bug in Magento. Your getSize() always returns wrong count whereas total records in grid are proper.

To fix this, you need to edit one of your core file. As it’s not a good practice to edit core file, we will here override the core file.
Overriding LIB module

Copy Db.php file from magento / lib / Varien / Data / Collection / Db.php
Paste it to your local directory so the resultant folder structure would look like this:
magento / app / code / local / Varien / Data / Collection / Db.php
Continue reading »

Dec 31, 2011
kalpesh

Magento: Joining/group by – order, invoice, shipment tables

Ever tried to join multiple tables in Magento? Joining and grouping tables is not that easy in Magento ORM than in simple MySql way we did for years.

Here is a piece of code where I was required to grab all the data from orders, invoices, shipments to generate reports for warehouse people to make their life easier.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$collection = Mage::getResourceModel('sales/order_shipment_item_collection');
$collection->addFieldToSelect('section_id');
$collection->addFieldToSelect('shelf_id');
$collection->addFieldToSelect('rack_id');
$collection->addFieldToSelect('box_id');
//$collection->addFieldToSelect('GROUP_CONCAT(DISTINCT main_table.product_id SEPARATOR ",")','product_ids');</p>
$collection->getSelect()->joinLeft('sales_flat_shipment_grid', 'main_table.parent_id = sales_flat_shipment_grid.entity_id', array('increment_id as shipment_increment_id', 'created_at as shipment_created_at', 'order_increment_id','total_qty'));
$collection->getSelect()->joinLeft('sales_flat_shipment_track', 'sales_flat_shipment_grid.entity_id = sales_flat_shipment_track.parent_id', array('number as track_id', 'carrier_code as carrier_name'));
$collection->getSelect()->joinLeft('sales_flat_order', 'sales_flat_shipment_track.order_id = sales_flat_order.entity_id', array('created_at as order_created_at','grand_total as ord_grand_total'));
$collection->getSelect()->joinLeft('sales_flat_order_item', 'main_table.order_item_id = sales_flat_order_item.item_id', array('product_type'));
$collection->getSelect()->joinLeft('sales_flat_order_payment', 'sales_flat_shipment_track.order_id = sales_flat_order_payment.parent_id', array('method as payment_method'));
$collection->getSelect()->joinLeft('sales_flat_order_address', 'sales_flat_shipment_track.order_id = sales_flat_order_address.parent_id', array('firstname','lastname','street','city','postcode','region','telephone'));
$collection->getSelect()->joinLeft('sales_flat_invoice', 'sales_flat_shipment_track.order_id = sales_flat_invoice.order_id', array('grand_total'));
//$collection->addAttributeToFilter('main_table.price', array('gt' => 0));
if($pickup_ids!='' &#038;&#038; is_array($pickup_ids))
    $collection->addAttributeToFilter('sales_flat_shipment_grid.entity_id', array('in' => $pickup_ids));
$collection->getSelect()->columns(
    array('product_ids' => new Zend_Db_Expr(
        "IFNULL(GROUP_CONCAT(DISTINCT main_table.product_id SEPARATOR ';'), '')"
)));
$collection->getSelect()->columns(
    array('weight' => new Zend_Db_Expr(
        "IFNULL(SUM(main_table.weight)/2, '')"
)));
$collection->getSelect()->group('shipment_increment_id');
//$collection->getSelect()->group('track_id');
//Mage::log($collection->getSelect()->__toString());
$this->setCollection($collection);
//$this->getCollection()->getSelect()->limit();

Although the query is so expensive, I have not yet tried to optimize it due to lack of time.

Pages:12»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications