Posts

Magento Website / Store Groups / Store Views

Magento Website / Store Groups / Store Views Magento is much flexible and provide us a gteat flexibility for multistore setup.But there is a common confusion between Website,Store & Store View. If you login to your Magento backend and go to System > Manage Store There you'll find the terms "Website", "Store" and "Store view". This is really confusing as soon as you start digging into the code because there those terms are mapped to "Website", "Store Group" and "Store View": Backend  Label  Website Store Store View Model Class Mage_Core_Model_Website Mage_Core_Model_Store_Group Mage_Core_Model_Store Database Table core_website core_store_group core_store To always be clear I'll stick to the terms "Website", "Store Group" and "St...

Magento 2 Adding custom .less & css

How to Import   custom less css 1- add new file this location   (app\design\frontend\Vendor\Themename\web\css\source\_custom.less) 2-and import  _custom.less file  in _sources.less (app\design\frontend\Vendor\Themename\web\css\source\_sources.less)      @import '_custom.less'; 3- Run static content deploy> Go to Root of M2 setup php bin/magento setup:static-content: deploy How to Override default less file 1-Copy file form vendor/magento/theme-frontend-blank/web/css/styles-l.less 2- Paste  file here (app\design\frontend\Vendor\Themename\web\css\) In styles-l.less file import   _styles.less and   in _styles.less  import   _sources.less 3- Run static content deploy> Go to Root of M2 setup php bin/magento setup:static-content: deploy How to Import custom css file 1- add new file this location   (app\design\frontend\Vendor\Themename\web\css\_custom1.less) ...

Magento Checkout redirects to “Shopping cart is empty”

This is because of cookies. In Magento, by default cookie’s lifetime is set to 3600 (1 hour). But if the end users computer time runs ahead of server’s time, cookies will not get set for magento frontend as well as backend. To solve this, set cookie’s lifetime to 86400 (1 day) instead of 1 hour and everything will work as expected. You can also set cookie lifetime to 0, so that cookie will only expire when the user’s browser is closed. Go to: Magento backend -> Sytem -> Configuration -> Web -> Session and Cookie Management

Validate Date PHP

For date validation in PHP Try this and enjoy :) <?php function isValid($date) { $date_format = ' d F Y '; $input =$date;   //say ' 11 February 2013'; $input = trim ($input); $time = strtotime ($input); $is_valid = date ($date_format, $time) == $input; return $is_valid ? 'yes' : 'no'; }

Enable/Disable dates in jQuery Datepicker

// //Block certain days in jQuery Datepicker // // // Holiday List var unavailableDates = [ "9-3-2012" , "14-3-2012" , "15-3-2012" ]; // Exeptions if some Weekends are Working days var enableDay = [ "3-3-2012" , "10-3-2012" , "17-3-2012" ]; // Weekend Days Sunday = 0 ... Sat =6 var weekend = [ 0 , 6 ]; function nationalDays(date) { // get date dmy = date.getDate() + "-" + (date.getMonth() + 1 ) + "-" + date.getFullYear(); // if Holiday then block it if ($.inArray(dmy, unavailableDates) > - 1 ) { return [ false , "" , "Unavailable" ]; } // if Exception then Enable it if ($.inArray(dmy, enableDay) > - 1 ) { return [ true , "" ]; } //if Weekend then block it if ($.inArray(date.getDay(), weekend) > - 1 ) { return [ false , "" , "Unavailable" ];...

Add unit price to order email template

Image
In the email sent to customer for order confirmation, product unit price does not show by default. It requires a little knowledge of Magento to make the customization. In this article, I will try to show you an easy way to do it. Here is the result you will get after this customization: There are 3 files you have to change, you should copy these files to the folder of your using theme. 1) app/design/frontend/base/default/template/email/order/items.phtml Around line 32, find the following code: <tr> <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Item') ?></th> <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Sku') ?></th> <th align="center" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $t...

Latest product by creation date in magento

<?php $todayDate = Mage :: app () -> getLocale () -> date () -> toString (Varien_Date :: DATETIME_INTERNAL_FORMAT ); $collection = Mage :: getModel ( 'catalog/product' ) -> getCollection () -> addAttributeToFilter ( 'news_from_date' , array ( 'date' => true , 'to' => $todayDate )) -> addAttributeToFilter ( 'news_to_date' , array ( 'or' => array ( 0 => array ( 'date' => true , 'from' => $todayDate ), 1 => array ( 'is' => new Zend_Db_Expr( 'null' ))) ), 'left' ) -> addAttributeToSort ( 'news_from_date' , 'desc' ) -> addAttributeToSort ( 'created_at' , 'desc' );

Set limit on Magento Collections

<?php $limit = 5; $starting_from = 2; $product_collection = Mage::getModel( 'catalog/product' )->getCollection()->setOrder( 'name' , 'asc' ); //getting the product collection, results are ordered by product name $product_collection ->getSelect()->limit( $limit , $starting_from );   //where $limit will be the number of results we want, $starting_from will be the index of the result set to be considered as starting point (note 0 is the index of first row) //this will ouptput 5 records starting from 3rd record foreach ( $product_collection as $_product ) {      echo $_product ->getName(). '<br/>' ; } ?>

Category Name with Products in Cart Page Magento

Modify Your Cart.phtml <div class="cart">     <div class="page-title title-buttons">         <h1><?php echo $this->__('Shopping Cart') ?></h1>         <?php if(!$this->hasError()): ?>         <ul class="checkout-types">         <?php foreach ($this->getMethods('top_methods') as $method): ?>             <?php if ($methodHtml = $this->getMethodHtml($method)): ?>             <li><?php echo $methodHtml; ?></li>             <?php endif; ?>         <?php endforeach; ?>         </ul>         <?php endif; ?>     </div>     <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>   ...

Magento orders: states and statuses

Magento orders: states and statuses 08/11/2009 - 12:08 / Posted by Laurent Clouet Login to post comments Magento orders have different states for following their process (billed, shipped, refunded...) in the order Workflow . These states are not visible in Magento back office. In fact, it is orders statuses that are displayed in back office and not their states . Each state can have one or several statuses and a status can have only one state. By default, statuses and states have often the same name, that is why it is a little confusing. Here is the list of statuses and states available by default. State code State name Status code Status name new New pending Pending pending_payment Pending Payment pending_paypal pending_amazon_asp Pending PayPal Pending Amazon Simple Pay processing Processing processing Processing complete Complete complete ...

Open color box on Page load

This code working with all frameworks.             Required Latest versions of :-                     1-colorbox.js                     2-jquery.min.js                     2- Download                 < script type = "text/javascript" > var j = jQuery.noConflict(); j( document ).ready( function (){ j.fn.colorbox({width : "685px;" ,overlayClose : false , escKey : false , inline : true , href : "#inline_content" }); j( "#cboxClose" ).remove(); }); < /script>

Safe name of a file by php

 function filename_safe($filename) {     $temp = $filename;      // Lower case     $temp = strtolower($temp);         // Replace spaces with a "_"     $temp = str_replace(" ", "_", $temp);         // Loop through string     $result = "";     for ($i=0; $i<strlen($temp); $i++) {     if (preg_match("([0-9]|[a-z]|_)", $temp[$i])) {     $result = $result . $temp[$i];     }     }     // Return filename     return $result;     }         function safe_filename ($filename) {     $search = array(     // Definition of German Umlauts START     "/ß/",     "/ä/","/Ä/",     "/ö/","/Ö/",     "/ü/","/Ü/",     // Definition of German Umlauts ENDE     "([^[:alnum:]_])" // Disallow: Not alphanumeric...

Get related product on with same category,brand,gender

include('app/Mage.php'); Mage::app(); $product = Mage::getModel('catalog/product')->load(2122); $ids = $product->getCategoryIds(); //echo '<pre>'; //print_r($ids); $latest_cat_id = $ids[count($ids)-1]; $_category = Mage::getModel('catalog/category')->load($latest_cat_id); $_gender=Mage::getResourceModel('catalog/product')->getAttributeRawValue(2122, 'gender'); $_brand_name=Mage::getResourceModel('catalog/product')->getAttributeRawValue(2122, 'brand_name'); $catagory_model = Mage::getModel('catalog/category')->load($latest_cat_id);     $collection = Mage::getResourceModel('catalog/product_collection'); $collection->addCategoryFilter($catagory_model); $collection->addFieldToFilter('brand_name',$_brand_name ); $collection->addFieldToFilter('gender',$_gender );     $collection->addAttributeToFilter('status',1); $collection->ad...

Randomize Collection In magento

Randomize Collection In magento <?php $_model = Mage :: getModel ( 'catalog/category' ); // Using the "catalog/navigation" Block Classes, we can invoke the getStoreCategories() method to get all Store Cats. $storeId = Mage :: app () -> getStore () -> getId (); $_categories = Mage :: getModel ( 'catalog/category' ) -> getCollection () -> addAttributeToSelect ( '*' ) -> addIsActiveFilter () -> addLevelFilter ( 2 ) -> setStoreId ( $storeId ); $_categories -> getSelect () -> order ( new Zend_Db_Expr( 'RAND()' )); $new = "" ; $new2 = "" ; // We'll loop through the returned Category Object foreach ( $_categories as $_category ) { //this gives random order of products }
 Programming Mistakes Improper Input Validation Ensure that your input is valid. If you're expecting a number, it shouldn't contain letters. Nor should the price of a new car be allowed to be a dollar. Incorrect input validation can lead to vulnerabilities when attackers can modify their inputs in unexpected ways. Many of today's most common vulnerabilities can be eliminated, or at least reduced, with strict input validation. Improper Encoding or Escaping of Output Insufficient output encoding is at the root of most injection-based attacks. An attacker can modify the commands that you intend to send to other components, possibly leading to a complete compromise of your application - not to mention exposing the other components to exploits that the attacker would not be able to launch directly. When your program generates outputs to other components in the form of structured messages such as queries or requests, be sure to separate control information a...

Add template exceptions on the basis of parameter magento

copy  this file in magento local Mage before edit. /public_html/app/code/core/Mage/Core/Model/Design/package.php <?php /**  * Magento  *  * NOTICE OF LICENSE  *  * This source file is subject to the Open Software License (OSL 3.0)  * that is bundled with this package in the file LICENSE.txt.  * It is also available through the world-wide-web at this URL:  * http://opensource.org/licenses/osl-3.0.php  * If you did not receive a copy of the license and are unable to  * obtain it through the world-wide-web, please send an email  * to license@magentocommerce.com so we can send you a copy immediately.  *  * DISCLAIMER  *  * Do not edit or add to this file if you wish to upgrade Magento to newer  * versions in the future. If you wish to customize Magento for your  * needs please refer to http://www.magentocommerce.com for more information.  *  * @category ...