Thursday, July 9, 2015

Magento direct SQL queries

Step 1: Initialize a resource object that will communicate with the database.

// To read from the database
$readObject = Mage::getSingleton( 'core/resource' )->getConnection( 'core_read' );

// To write to the database
$writeObject = Mage::getSingleton( 'core/resource' )->getConnection( 'core_write' );

Step 2: Set table name with it's prefix
$dbTable = Mage::getSingleton( 'core/resource' )->getTableName( 'custom_product' );

Step 3: Prepare query
$sql = "SELECT additional_description FROM " . $dbTable . " WHERE id:productId";
$filters = array(
'productId' => $productId
);

Step 4: Run your query.
$result = $readObject->query( $sql, $filters );
while ( $row = $result->fetch() ) {
echo 'Additional Description ' . $row['additional_description'] . '<br />';
}

Make admin form field read only in magento

     $fieldset->addField(
            'additional_description',
            'text',
            array(
                'label' => Mage::helper('custom_favourites')->__('Additional Description'),
                'name'  => 'additional_description',
            'required'  => false,
            'readonly' => true,
            'class' => 'required-entry',
           )
        );

Get MSRP of the product

<?php echo Mage::helper('core')->currency($_product->getMsrp(),true,false); ?>

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...