Tag Archives: Magento tutorials online

Magento get current customer id

Magento get current customer id

Use the following code to get current logged in customer’s Id :

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
     $customerData = Mage::getSingleton('customer/session')->getCustomer();
     $customerId = $customerData->getId();
 }

can’t retrieve entity config magento

can’t retrieve entity config magento

This Error occurs basically due to config.php file’s Model setup
First of all check that table name and model name is correct in config.xml

Example :

  
                Demo_Model_Resource
                                    
                    
                        table_name

In the above example :

table_name


The model name and the table name should be correct .

Magento Custom Collection Sorting | Magento sort collection Item

Magento Custom Collection Sorting | Magento sort collection Item

function sortMagentoCollection(Varien_Data_Collection $collection, callable $sorter) {

$collectionReflectionMirror = new ReflectionObject($collection);
$itemsPropertyReflection = $collectionReflectionMirror->getProperty(‘_items’);
$itemsPropertyReflection->setAccessible(true);
$collectionItems = $itemsPropertyReflection->getValue($collection);
usort($collectionItems, $this->sorterCmp($sorter));
$itemsPropertyReflection->setValue($collection, $collectionItems);

$itemsPropertyReflection->setAccessible(false);

return $collection;
}

function sorterCmp($key) {
return function ($a, $b) use ($key) {
return strnatcmp($a[$key], $b[$key]);
};
}

example :

just call the method : sortMagentoCollection($collection,$sorter);

where $collection which you want to sort
$sorter : key name to sort , it may me column name on the basis of which you want to sort.

Magento get current controller ,current module , current action and route name

Magento get current controller ,current module , current action and route name :

Sometimes we need to get current Controller, Module , action & route name in magento :

its very easy to get the current name :
1 . controller name
Mage::app()->getRequest()->getControllerName();
// will return controller name
2. action name
Mage::app()->getRequest()->getActionName();
//will return action name
2. module name
Mage::app()->getRequest()->getModuleName();
// will return module name
2. routes name
Mage::app()->getRequest()->getRouteName();
//will return routes name

Increase Decrease Quantity Button

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>Increase Decrease Button </title>
		
		<script type="text/javascript">
		  function incre(){
      
                            document.getElementById("qty").value++;
                         }
                  function decre(){
                         var ckVal = document.getElementById("qty").value;
                   if(ckVal > '0') {
                       document.getElementById("qty").value--;
                      }
                   }
		</script>
	</head>
	<body>
		   <form name="DemoForm">
                               
                                    <input type='button' class="pull-left" name='incre' onclick='incre();' value='+'/>
                                    <input type='text' name='qty' value="1" id='qty' style="width:65px;" size="3"  class="pull-left" />
                                    <input type='button' class="pull-left" name='decre' onclick='decre();' value='-'/>
                  </form>
	</body>
</html>

Magento core_email_template setup | Base table or view not found: 1146 Table ‘core_email_template’ doesn’t exist

Run the following Query to create magento core email template
DROP TABLE IF EXISTS `core_email_template`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `core_email_template` (
`template_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘Template Id’,
`template_code` varchar(150) NOT NULL COMMENT ‘Template Name’,
`template_text` text NOT NULL COMMENT ‘Template Content’,
`template_styles` text COMMENT ‘Templste Styles’,
`template_type` int(10) unsigned DEFAULT NULL COMMENT ‘Template Type’,
`template_subject` varchar(200) NOT NULL COMMENT ‘Template Subject’,
`template_sender_name` varchar(200) DEFAULT NULL COMMENT ‘Template Sender Name’,
`template_sender_email` varchar(200) DEFAULT NULL COMMENT ‘Template Sender Email’,
`added_at` timestamp NULL DEFAULT NULL COMMENT ‘Date of Template Creation’,
`modified_at` timestamp NULL DEFAULT NULL COMMENT ‘Date of Template Modification’,
`orig_template_code` varchar(200) DEFAULT NULL COMMENT ‘Original Template Code’,
`orig_template_variables` text COMMENT ‘Original Template Variables’,
PRIMARY KEY (`template_id`),
UNIQUE KEY `UNQ_CORE_EMAIL_TEMPLATE_TEMPLATE_CODE` (`template_code`),
KEY `IDX_CORE_EMAIL_TEMPLATE_ADDED_AT` (`added_at`),
KEY `IDX_CORE_EMAIL_TEMPLATE_MODIFIED_AT` (`modified_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=’Email Templates’;
/*!40101 SET character_set_client = @saved_cs_client */;

Could not resolve host: magento-community

Problem with using Beta Magento versions

use this in front of the extension key name:

http://connect20.magentocommerce.com/community/

instead of

http://connect20.magentocommerce.com/ magento-community/EM_Quickshop

example:

http://connect20.magentocommerce.com/community/EM_Quickshop

Base table or view already exists: 1050 Table ‘core_email_queue’ already exists, query was: CREATE TABLE `core_email_queue` in magento 1.9

Magento install error base table or view already exists or
if you get error” Base table or view already exists: 1050 Table ‘core_email_queue’ already exists, query was: CREATE TABLE `core_email_queue` ”

Solution is very simple go to database

select the table core_resource

search for the code core_resource

update the values in column version & data_version from 1.6.05 to  1.6.06

Magento database error when delete cache

Magento Error when flushing or deleting cache in magento 1.9 | magento error after flushing cache

magento error after flushing cache

if you get following error in magento –

a:5:{i:0;s:1145:”Error in file: “app\code\core\Mage\Core\sql\core_setup\upgrade-1.6.0.5-1.6.0.6.php” – SQLSTATE[23000]: Integrity constraint violation: 1022 Can’t write; duplicate key in table ‘core_email_queue_recipients’, query was: CREATE TABLE `core_email_queue_recipients` (
`recipient_id` int UNSIGNED NOT NULL auto_increment COMMENT ‘Recipient Id’ ,
`message_id` int UNSIGNED NOT NULL COMMENT ‘Message ID’ ,
`recipient_email` varchar(128) NOT NULL COMMENT ‘Recipient Email’ ,
`recipient_name` varchar(255) NOT NULL COMMENT ‘Recipient Name’ ,
`email_type` smallint NOT NULL default ‘0’ COMMENT ‘Email Type’ ,
PRIMARY KEY (`recipient_id`),
INDEX `IDX_CORE_EMAIL_QUEUE_RECIPIENTS_RECIPIENT_EMAIL` (`recipient_email`),
INDEX `IDX_CORE_EMAIL_QUEUE_RECIPIENTS_EMAIL_TYPE` (`email_type`),
UNIQUE `19BDB9C5FE4BD685FCF992A71E976CD0` (`message_id`, `recipient_email`, `email_type`),
CONSTRAINT `FK_6F4948F3ABF97DE12127EF14B140802A` FOREIGN KEY (`message_id`) REFERENCES `core_email_queue` (`message_id`) ON DELETE CASCADE ON UPDATE CASCADE
) COMMENT=’Email Queue’ ENGINE=INNODB charset=utf8 COLLATE=utf8_general_ci”;i:1;s:1018:”#0

Solution is very simple go to database

select the table core_resource

search for the code core_resource

 

Magento database error when delete cache

 

update the values in column version & data_version from 1.6.05 to  1.6.06