Archive for June 2017

Redirecting in Magento

Redirect to the list Action in the same Controller $this->getResponse()->setRedirect(Mage::getUrl(’*/*/list’));

How to get a table name in Magento Resource Collection

Method 1:   <?php … $this->getResource()->getTable(’catalog/category_product’); Method 2:   … Mage::getSingleton(’core/resource’)->getTableName(’catalog/category_product’);

Another method of getting Customer Data

  <?php   … public function getCustomer() { $customerId = $this->_getCustomerId();   return Mage::getModel(’customer/customer’)->load($customerId); }   private function _getCustomerId() { return Mage::getSingleton(’customer/session’)->getCustomerId(); } …

Check if Customer Logged In and get the details from Session

  <?php   // require_once ‘/var/www/magento/app/Mage.php’; // Mage::init();   function getSession() { return Mage::getSingleton(’customer/session’); }   if (!getSession()->isLoggedIn()) { $this->_redirect(’customer/account/login’); return; }   if (getSession()->isLoggedIn()) { echo ‘loggedIn’;   $customerData = Mage::getSingleton(’customer/session’)->getCustomer();   printf("%s\n %s\n %s\n %s", $customerData->getId(), $customerData->getWebsiteId(), $customerData->getStoreId(), $customerData->getIsActive()); //Zend_Debug::dump($customerData); }

Magento Core Tables

1) eav_attribute whenever you create a attribute this table gets entry which stores all important data which helps to make a relation, like entity_type_id,attribute_code,backend_type and many more but this are the important fields. 2) eav_entity_type Magento has 8 types of entity, by which, type of attribute is decided. in your case it is catalog_product 1) […]

Comparing EAV to Relational Table

EAV makes a lot of sense for a generic e-commerce solution. A store that sells laptops (which have a CPU speed, color, ram amount, etc) is going to have a different set of needs than a store that sells yarn (yarn has a color, but no CPU speed, etc.). Even within our hypothetical yarn store, […]

Running Raw SQL Query

Place this function to Resource Model   public FUNCTION getMarkers($lat, $lng) { /** * Search radius in km */ $searchRadius = 10;   /** * Get the resource model */ $resource = Mage::getSingleton(’core/resource’);   /** * Retrieve the read connection */ $readConnection = $resource->getConnection(’core_read’);   /** * Retrieve our table name */ $table = $resource->getTableName(’storelocator/entity’); […]

How-to get SQL query string from Mage

  <?php   $collection = Mage::getResourceModel(’mybrands/orders’) ->addFieldToSelect(’name’) ->addFieldToSelect(’order_id’);   echo ‘<pre>’; print_r($collection->getSelect()->__toString());

How-to magento translate

1. in phtml file do: <?php echo $this->__(’Stores found’)?> 2. In Vendor/Module/etc/config.xml do: … <frontend> <translate> <modules> <VisionDirect_Globalcollect> <files> <default>VisionDirect_Globalcollect.csv</default> </files> </VisionDirect_Globalcollect> </modules> </translate> <routers> … </routers> </frontend> … 3. app/locale/de_DE/VisionDirect_StoreLocator.csv “My name is Imran”,”Maine name ist Imran” “That is a wall”,”Dast ist fenster” 4. Switch domain name of your webstie from english to German […]

How-to get current locale of the store

<?php echo Mage::getStoreConfig(’general/locale/code’) ?>