Wednesday, September 9, 2015

Magetno - Get add to cart url for any product

$_productId = '1222';
$_product = Mage::getModel('catalog/product')->load($_productId);
$_carturl = Mage::helper('checkout/cart')->getAddUrl($_product);

Log of mysql query in magento

Go to lib/Varien/Db/Adapter/Pdo/Mysql.php

And do as following:
$_debug               = true;
$_logAllQueries       = true;
$_debugFile           = 'var/debug/pdo_mysql.log';

Tuesday, September 8, 2015

Magento Delete Orders

require 'app/Mage.php';

Mage::app('admin')->setUseSessionInUrl(false);                                                                                      
$orderIds=Array = array('100000001','100000002','100000004','200000002');

for($cnt=0;$cnt<count($orderIdsArray);$cnt++)
{
    try
{
$OrderId=$orderIdsArray[$cnt];
        Mage::getModel('sales/order')->loadByIncrementId($OrderId)->delete();  
echo "Order #".$OrderId ." is removed"."<br />";
    }
catch(Exception $e)

        echo 'Error: '.$e->getMessage().'<br />';
}
}

Magento - Getting shipments of the order

$order = Mage::getModel('sales/order')->load($orderID);

foreach($order->getShipmentsCollection() as $shipment)
{
        echo "<pre>";
print_r($shipment->getData());
echo "</pre>";

}

Magento : call block function in another phtml file

$className = Mage::getConfig()->getBlockClassName('Companyname_Modulename_Block_Filename');

$blockObject = new $className();  

$blockData = $blockObject->functionName();

Magento showing wrong product count in category in admin

After importing or updrading database, you may face this problem.

To fix this, you need to run following sql query:

Kindly, take database backup before running query to prevent accident deletes.

DELETE FROM catalog_category_product where product_id NOT IN (SELECT entity_id FROM (catalog_product_entity)) 

Fix the issue of magento importing more rows than found


To fix this issue, you need to empty the table "dataflow_batch_import" in mysql magento database.

Remove 'Add New' button from Admin Grid

 Go to Namespace > Module > Block > Adminhtml > BlockFile.php


  • Add the following code in the constructor of this file.
  • It will be after the call to parent constructor.


parent::__construct(); 
$this->_removeButton('add');

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method... magento 2

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method and must therefore be declared abstract or implement the remaining met...