Welcome to My Blog

Here you can fantastic Magento & Design posts.

Get Current Store Details like ID, Code, Name and Status

Get Current Store Details like ID, Code, Name and Status

// Gets the current store's details $store = Mage::app()->getStore(); // Gets the current store's id $storeId = Mage::app()->getStore()->getStoreId(); // Gets the current store's code $storeCode = Mage::app()->getStore()->getCode(); // Gets the current website's id $websiteId = Mage::app()->getStore()->getWebsiteId(); // Gets the current store's group id $storeGroupId = Mage::app()->getStore()->getGroupId(); // Gets the current store's name $storeName = Mage::app()->getStore()->getName(); // Gets the current store's sort order $storeSortOrder = Mage::app()->getStore()->getSortOrder(); // Gets the current store's status $storeIsActive = Mage::app()->getStore()->getIsActive(); // Gets the current store's locale $storeLocaleCode = Mage::app()->getStore()->getLocaleCode(); // Gets the current store's home url $storeHomeUrl =...
Create custom option for Product by MySql Query

Create custom option for Product by MySql Query

try { $productId=$product->getEntityId();//Your product id $write = Mage::getSingleton( 'core/resource' )->getConnection( 'core_write' ); $read = Mage::getSingleton( 'core/resource' )->getConnection( 'core_read' ); $query = "UPDATE catalog_product_entity set has_options=1 where entity_id=".$productId; $write->query($query); $optionType = 'field'; $query = 'INSERT INTO catalog_product_option (product_id,type) VALUES ('.$productId.',"'.$optionType.'")'; $write->query($query); $optionTitle = 'Comment'; $optionId = $read->fetchOne("SELECT MAX(`option_id`) as LastID FROM `catalog_product_option`"); $query = 'INSERT INTO catalog_product_option_title (option_id,title) VALUES ('.$optionId.',"'.$optionTitle.'")'; $write->query($query); $priceType = 'fixed'; $query = 'INSERT INTO catalog_product_option_price (option_id,price_type) VALUES ('.$optionId.',"'.$priceType.'")'; $write->query($query); } catch(Exception $e) { echo $e;...
Simple way Reindex all in magento

Simple way Reindex all in magento

Create a php script with the following below mention code. Provide proper path, In my case path is : /var/www/import/web/shell/indexer.php path is change according to server base directory location. <?php exec("php -f /var/www/import/web/shell/indexer.php reindexall");...
Enable Admin Template Hints Magento

Enable Admin Template Hints Magento

Enable Admin Template Hints Magento INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/debug/template_hints', 1),('default', 0,'dev/debug/template_hints_blocks',1); Disable Admin Template Hints Magento UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints'; Re-Enable Admin Template Hints Magento UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path...
UPLOAD SIMPLE PRODUCT IN MAGENTO FROM CSV PHP SCRIPT

UPLOAD SIMPLE PRODUCT IN MAGENTO FROM CSV PHP SCRIPT

#!/usr/local/bin/php.cli <?php //complete_notification require_once('app/Mage.php'); Mage::app('default'); set_time_limit(0); $handle = fopen("catalogproduct.csv","r"); $count=1; while(($data=fgetcsv($handle,","))!==FALSE) { $product = Mage::getModel('catalog/product'); $dataarr = array('sku'=>$data[0],'attribute_set'=>$data[2],'type_id'=>$data[3],'name'=>$data[8],'price'=>$data[9],'description'=>$data[7],'short_description'=>$data[10],'weight'=>$data[16],'status'=>$data[12],'visibility'=>$data[15],'qty'=>$data[17]); $product = Mage::getModel('catalog/product'); $sku = $product->getIdBySku($dataarr['sku']); //$storeid = Mage::app()->getWebsite()->getDefaultGroup()->getDefaultStoreId(); //echo '<pre>'; //print_r($data); //echo '</pre>'; if(!$sku) { if($count>1) { $productData=array( 'sku' => $dataarr['sku'], 'name' => $dataarr['name'], 'description' => $dataarr['description'], 'short_description' => $dataarr['short_description'], 'weight' => $dataarr['weight'], // whatever your product weighs 'status' => $dataarr['status'], // 1 => enabled, 0 => disabled some time 2=> disable 'visibility' => '4', // 1 => Not Visible Individually, 2 => Catalog, 3 => Search, 4 => Catalog, Search 'attribute_set_id' => 4, // default 'type_id' => $dataarr['type_id'], 'price' => $dataarr['price'], //'special_price' => 1599, // optional 'tax_class_id' => 0, // None //'page_layout' => 'one_column', ); foreach($productData as $key => $value) { $product->setData($key,$value); } $product->setWebsiteIds(array(1)); //$product->setStoreId($storeId);//Setting default store id $product->setStockData(array( //'manage_stock' => 1, 'is_in_stock' => 1, 'qty' => 10, //'use_config_manage_stock' => 0 )); $categoryIds = array(3); // Use category ids according to your store $product->setCategoryIds($categoryIds); //$mode = array("image"); $img = 'db_file_img_229_160xauto.jpg'; //$product->addImageToMediaGallery($img, $mode, true, true); $mode = array("small_image","thumbnail","image"); try { $product->addImageToMediaGallery($img,$mode,false,false); } catch(Exception $e) { echo 'Image failed'; echo $e->getMessage(); } foreach($product->getStoreIds() as $storeId) { $product->setStoreId($storeId)->setImage(false)->setSmallImage(false)->setThumbnail(false); } try { $product->save(); echo $product->getId(); } catch (Exception $ex) { echo 'Error'; } break; } } $count++; }// end of while loop...
Column type in Magento Admin Grid

Column type in Magento Admin Grid

In Magento Admin Grid In Magento Admin Grid we can change type of of the columns as per the datatype of the data and some other type of column type also available in Magento. $this->addColumn('name', array( 'header' => Mage::helper('yourmodule')->__('Name'), 'align' =>'right', 'width' => '50px', 'type' => 'date', 'index' => 'name', )); You can change column type of your admin grid by opening Grid.php path : namespace\modulename\Block\Adminhtml\modulename\Grid.php In this file just find function _prepareColumns() and there you define your column like $this->addColumn('name',array('header'=>'Mage::helper('yourmodule')->__('Name'),'type'=> 'date','index' => 'name')); You can just change you column type by changing array element “type”. If you want to change date just change in array ‘type’=>’date’ if you want to change datetime just change in array ‘type’=>’datetime’ There are various column type are available in Magento Admin Grid That are as Follows. date datetime number currency price country concat action options checkbox massaction radio input select text store wrapline...
Default Email Variables In Magento

Default Email Variables In Magento

Default Email Variables In Magento {{var customer}} Will print out all customer information {{var customer.ID}} {{var customer.email}} {{var customer.firstname}} {{var customer.lastname}} {{var customer.name}} {{var customer.password}} {{var customer.created_in}} Store Name {{var customer.dob}} Date of Birth {{var customer.password_hash}} {{var customer.prefix}} {{var customer.middlename}} Initial {{var customer.suffix}} {{var customer.group_id}} {{var customer.taxvat}} {{var customer.store.name}} Name of Store in English {{var customer.store.group.name}} The actual Store’s name (not the Store View’s) //- To subscribe/unsubscribe newsletter: {{var subscriber.getConfirmationLink()}} {{var subscriber.getUnsubscriptionLink()}} {{var subscriber.email}} //- Send to a friend {{var product_image}} {{var name}} Recipient’s Name {{var email}} Recipient’s Email {{var product_name}} Product Name {{var product_url}} Product Url {{var message}} Message Text {{var sender_name}} Sender’s Name {{var sender_email}} Sender’s Email {{var product_image}} Product Image //- Block {{block type='core/template' area='frontend' template='email/order/shipment/track.phtml' shipment=$shipment order=$order}} //- Depend Condition {{depend order.getIsNotVirtual()}} {{/depend}} {{depend salable}} {{/depend}} //- If Condition {{if order.getIsNotVirtual()}} {{else}} {{/if}} For Order Mail {{var order.getShippingAddress().format('html')}} //Items of the shipping address : {{var order.getShippingAddress().getName()}} Get the first and last name {{var order.getShippingAddress().getPrefix()}} {{var order.getShippingAddress().getFirstName()}} {{var order.getShippingAddress().getMiddleName()}} {{var order.getShippingAddress().getLastName()}} {{var order.getShippingAddress().getSuffix()}} {{var order.getShippingAddress().getStreet1()}} {{var order.getShippingAddress().getStreet2()}} {{var order.getShippingAddress().getCity()}} {{var order.getShippingAddress().getRegion()}} {{var order.getShippingAddress().getPostcode()}} {{var order.getShippingAddress().getCountry()}} Get the country’s ID {{var order.getShippingAddress().getCountryModel().getName()}} Get the country’s full name {{var order.getShippingAddress().getRegion()}} {{var order.getShippingAddress().getTelephone()}} //- Other {{var addAllLink}} {{var alertGrid}} {{var billingAddress.format('html')}} {{var checkoutType}} {{var comment}} {{var creditmemo.id}} {{var creditmemo.increment_id}} {{var data.comment}} {{var data.email}} {{var data.name}} {{var data.telephone}} {{var dateAndTime}} {{var invoice.id}} {{var invoice.increment_id}} {{var invoice.created_at}} {{var items}} {{var items_html}} {{var message}} {{var name}} {{var order.customer_email}} {{var order.getBillingAddress().format('html')}} {{var order.getBillingAddress().getName()}} {{var order.getCreatedAtFormated('long')}} {{var order.getCustomerName()}} {{var order.getCustomerFirstname()}} {{var order.getCustomerLastname()}} {{var order.getEmailCustomerNote()}} Currently unknwon how to test this variable for being set/empty {{var order.getShippingDescription()}} {{var order.getStatusLabel()}} {{var order.getStoreGroupName()}} {{var order.id}} {{var order.increment_id}}...
Set, Get and Delete cookies in Magento Client Side – Javascript.

Set, Get and Delete cookies in Magento Client Side – Javascript.

Before setting Magento Cookie you have to set Path, Domain And Expiry Time Setting Path path of the server on which cookie is available if set ‘/’ the cookie is availble entire domain ‘/directoryname/’ this means cookie available directory and all sub directory. Mage.Cookies.path = '/'; Setting Domain The domain the cookie is available ‘www.example.com’. Mage.Cookies.domain = '.example.com'; Setting Expiry Time expiry time of the cookie. var today = new Date(); today.setTime(today.getTime()); /*This time is for One Day Means 24 hour 1=day 1000=1sec 60*60=1hour 24=no of hour.*/ var expiress = 1 * 1000 * 60 * 60 * 24; var expires_date = new Date(today.getTime()+(expiress)); Mage.Cookies.expires = expires_date; Setting Cookie Value. var name = 'Aman'; Mage.Cookies.set('name',name); Getting Cookie Value. var name = Mage.Cookies.get('name'); alert(name); Delete Cookie Value....
Add Multiple Field Filter (addFieldToFilter) and Multiple Attribute Filter (addAttributeToSelect) in Magento.

Add Multiple Field Filter (addFieldToFilter) and Multiple Attribute Filter (addAttributeToSelect) in Magento.

There are the following difference between addAttributeToSelect() : As you know that the magento prducts are having many attributes, so the addAttributeToSelect() method is used to select the attributes that we want to use. Its retrive only attributes its not filter the collection, however when we use addAttributeToSelect(‘*’) its select all attriutes of the products. addAttributeToFilter() : This method is used to filter the attributes, its used to filter the collection based on the specific conditional parametters. addFieldToFilter() : This method is used to filter collection but non-EAV models. Example : In below mentioned code we have used product collection and selected name and price attribute with addAttributeToSelect() method and filter the collection with greater than equal to 5 with addAttributeToFilter() method. $collections = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect(array('name', 'price')) ->addAttributeToFilter('price',array('eq' => 5.00)) ->load(); Below is the list of conditions that you use to filter the collection: Attribute Code SQL Equivalent Example eq = $collections->addAttributeToFilter('price', array('eq' => 5.00)); neq != $collections->addAttributeToFilter('price', array('neq' => 5.00)); like LIKE $collections->addAttributeToFilter('name', array('like' => '%Pattern%')); nlike NOT LIKE $collections->addAttributeToFilter('name', array('nlike' => '%Pattern%')); in IN () $collections->addAttributeToFilter('id', array('in' => array(1,2,3,4,5))); nin NOT IN () $collections->addAttributeToFilter('id', array('nin' => array(1,2,3,4,5))); is IS notnull IS NOT NULL $collections->addAttributeToFilter('description', 'notnull'); null IS NULL $collections->addAttributeToFilter('description', 'null'); moreq >= $collections->addAttributeToFilter('price', array('moreq' => 5.00)); gt > $collections->addAttributeToFilter('price', array('gt' => 5.00)); lt = $collections->addAttributeToFilter('price', array('gteq' => 5.00)); lteq = $collection->addAttributeToFilter('created_at', array( 'from' => '10 December 2014', 'to' => '15 December 2014', 'date' => true ));...