Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Redirect to Mobile theme in Magento using add exception


If you look at the System > Configuration > General > Design -> Package and Theme sections, you’ll see that Magento provides “Add Exception” buttons most of the configuration parameters available. There is also a cryptic caption saying: “Match expressions in the same order as displayed in the configuration.”

But what does it mean? And what can we do with this?


Well, if you’re adventurous and hike into the code behind the exception options you will realize that Magento takes a regular expression string in “Matched Expression” and will compare it with the browser user agent, applying the “Value” set as the one to use instead of what is set for the default if it finds a match.

In other words, if the regular expression matches with the browser user agent apply the design exception set.

In yet more words, you can use this to check what browser customers are using to access your store and set a different package / template / skin / layout / theme accordingly. So, if you want to serve up a different theme for mobile browsers, this is where the exceptions come in handy.

Let’s look at how to set this up so Magento serves the iPhone theme for mobile device customers:

Magento add exception


Here is the full contents of the “Matched Expression”:

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini


So what the example in the screenshot is saying is: “If the user agent is one of the listed ones, serve up the iphone design that ships with Magento, otherwise just use the default”.

Depending on where you add your exception, you can create a different layout or skin or complete theme for your audience who use different devices to get to your site.

For example, you could have a cutting edge design as your default theme but offer an alternative, cut-down version for the odd IE6 user.

For the most part, however, you will use this feature to serve a mobile optimized version of your design.

Finally, what does that cryptic caption then mean? Well, it just means that if you have several exception rules, they will be matched and applied in the order they are listed.

Update: If it is not working properly you can redirect using another way check here.


Generate xml file of all products fields in Magento programmatically


By using this module you can create xml file of all the products.
You are able to create xml file from your magento admin panel.
Follow the step for that.

XML file of all products fields in Magento

1) Download the zip file. Download zip

2) Copy and paste all the file from zip as its file structure.

3) Create one directory "productsxml" in your root.

4) Download option available in your magento admin.

Your xml looks like this.

XML file of all products fields in Magento


Hit like or leave comment if post help!

Change shipping address dropdown to list view at checkout page Magento


shipping address dropdown to list view

Once i need to change shipping address dropdown to div structure.
After a long research i found that this select box is comming form core php file and i do not want to make any change in core file. So at last i changed my shipping.phtml file as following.

Magento shipping address dropdown to list view


I have changed in file
/app/design/frontend/default/[My-Theme]/template/checkout/onepage/shipping.phtml

This code is used for getting the html for select box for presaved address.
I added my new code after this.
<?php echo $this->getAddressesHtmlSelect('shipping') ?>

Now, my code looks like this,


<label for="shipping-address-select"><?php echo $this->__('Select a shipping address from your address book or enter a new address.') ?></label>
<div class="input-box" style="display: none;">
<?php echo $this->getAddressesHtmlSelect('shipping') ?>
</div>
        /*New Code start*/   
<div id="custAddress">
<?php $customerId = Mage::getSingleton('customer/session')->getCustomer();?>    
<?php $customer = Mage::getModel('customer/customer')->load($customerId->getId()); ?>
<?php $data = array();?>
<?php $i=0; foreach ($customer->getAddresses() as $address):?>
<?php $data = $address->toArray();?>
<div id="addresseList">
       <a href="javaScript:void(0);" onclick="setAddress(this.id)" id="<?php echo $i;?>">
       <address> 
          <div id="selected_<?php echo $i;?>" class="selectedImage" style="float: right; margin: -6px; display: none;"><img src="<?php echo $this->getSkinURl()?>images/right.jpg" /></div>
         <?php echo $data['firstname'].' '.$data['lastname'].'<br />';?>
         <?php echo $data['street'].'<br />';?>
         <?php echo $data['city'].','.$data['region'].','.$data['postcode'].'<br />';?>
         <?php $country_name = Mage::app()->getLocale()->getCountryTranslation($data['country_id']);?>
         <?php echo $country_name.'<br />';?>
          <?php echo 'T: '.$data['telephone'];?>
       </address>
    </a>
 </div>
 <?php $i++; endforeach; ?>  
 </div>


<li id="addNewtext"><a href="javaScript:void(0);" onclick="setNewAddress()"><?php echo $this->__('Click to Add new address') ?></a></li>

/*End of New code start*/

I have added javascript and jQuery function in same file at the bottom of the page.

<script type="text/javascript">
function setAddress(obj)
{
    document.getElementById('shipping-address-select').selectedIndex = obj;
    jQuery(".selectedImage").hide();
    jQuery("#selected_"+obj).show();
    jQuery("#shipping-new-address-form").hide();
    jQuery("#addNewtext").show();
}
function setNewAddress()
{
    jQuery("#shipping-address-select").find("option:contains('New Address')").each(function()
    {
     if( jQuery(this).text() == 'New Address' )
     {
        jQuery(this).attr("selected","selected");
        jQuery("#shipping-new-address-form").show();
        jQuery("#addNewtext").hide();
        jQuery(".selectedImage").hide();
      }
    });
}
</script>  


Hit like or leave comment if post help!

Add New Custom Category Attributes to Magento via Module

Time and time again I need to create a custom category attribute for a site I’m working on, and each time I search for a good article covering the topic in depth I fall short, and half written and poorly explained versions of how to do exactly this. I’ve learnt how to do this over time, and now I’ll share exactly how to, and also how it works. First of all, I’ll show you the code for each file, and explain everything afterwards.

Add New Custom Category Attributes to Magento

To create a custom attribute we are going to create it as a module, the reason for this is so when we come to install our Magento site on another server, or if our extension we’re developing needs to be used on other Magento installs our custom category attribute will be installed if it doesn’t yet exist!

First of all let’s set up our basic module file structure we need for this:


app/code/local/Patelgroup/Customcatattrb
app/code/local/Patelgroup/Customcatattrb/etc
app/code/local/Patelgroup/Customcatattrb/sql/customcatattrb_setup

Now let’s create the files, first up is our config.xml, this is the main file within your module which tells Magento which controllers and models to load, plus plenty more.

Save this file to: app/code/local/Patelgroup/Customcatattrb/etc/config.xml


<?xml version="1.0"?>
<config>
    <modules>
        <Patelgroup_Customcatattrb>
            <version>0.1.0</version>
        </Patelgroup_Customcatattrb>
    </modules>
    <global>
        <resources>
            <customcatattrb_setup>
                <setup>
                    <module>Patelgroup_Customcatattrb</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>default_setup</use>
                </connection>
            </customcatattrb_setup>
        </resources>
    </global>
</config>


Next up, let’s create yet another XML file, this time it’s our file which lets magento know we have a module to be loaded in, and where the module is located.

Save this file to: app/etc/modules/Patelgroup_Customcatattrb.xml


<?xml version="1.0"?>
<config>
    <modules>
        <Patelgroup_Customcatattrb>
            <active>true</active>
            <codePool>local</codePool>
        </Patelgroup_Customcatattrb>
    </modules>
</config> 


Last but not least, is our install script. This is a tiny script which will install our attribute to the database, and we can start using our newly created attribute straight away after!

Save to: app/code/local/Patelgroup/Customcatattrb/sql/customcatattrb_setup/mysql4-install-0.0.1.php


<?php
$installer = $this;
$installer->startSetup();
$attribute  = array(
    'type' => 'text',
    'label'=> 'Customer Description',
    'input' => 'textarea',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'default' => "",
    'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'cust_description', $attribute);
$installer->endSetup();
?>

Hit like or leave comment if post help!


 

Copyright @ 2017 HKBlog.