Tuesday, 31 January 2023

How to remove .html from URL?

 Use the following code in .htaccess file to remove .html from url. 

This code will work for static html files. 

example.com/page.html   to example.com/page

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteBase /

RewriteCond %{https://example.com} !(\.[^./]+)$

RewriteCond %{REQUEST_fileNAME} !-d

RewriteCond %{REQUEST_fileNAME} !-f

RewriteRule (.*) /$1.html [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP

RewriteRule ^([^.]+)\.html$ https://example.com/$1 [R=301,L]

</IfModule>

Monday, 18 January 2021

Amazon Great Republic Day Sale 20th – 23rd January

 

Amazon Great Republic Day Sale will start from 20 January and end 23 January. The sale will start early for Prime Members a day before on 19 January.

Great Republic Day Sale

prime Members

The Amazon Great Republic Day Sale have great features discounts and offers on Mobiles, Electronics, Fashion apparel and accessories, home appliances, daily essentials and many more products.

The Amazon Great Republic day sale will also release instant 10% discount on credit cardholders of SBI bank.

Check out the Best Features of The Amazon Great Republic day sale:

Customers can expect up to 40 percent off on Mobiles and accessories from popular brands.

Amazon will also offer exchange offers on most of the products.

Customers will see discounts on Xiaomi Redmi Note 9, Samsung Galaxy M21, iPhone 7, OnePlus 8 5G and Nokia 5.3. There will also up to 75 percent off on headphones, up to 30,000 off on laptops, and up to 45 percent discount on tablets during Amazon Great Republic Day Sale.

Mobile OffersElectronics

Kitchen productsDaily Essentials

FashionTV

Brands & MoreBooks

Amazon Great Republic Day Sale, Amazon Great Republic Day Sale 2021, Amazon Great Republic Day Sale deals, Amazon Great Republic Day Sale offers, IPhone 12 mini, smart tv, laptop, amazon sale, Amazon Great Republic Day Sale on January 2021

Thursday, 16 April 2020

How to get last executed query in Codeigniter?

Are you want to display last executed query in Codeigniter ?
You can use last_query() function of db class in Codeigniter.


You can use in controller and get output of last executed query:






Example : 


public function get_cities(){  

           $query = $this->db->get("cities"); 


           $str = $this->db->last_query(); 

           echo "<pre>";

           print_r($str);

           exit;

}



Output:


SELECT * FROM `items`







Friday, 3 April 2020

Why Codeigniter Shopping Cart doesn't allow any special character in the name?

Codeigniter Cart have some rules for product name in following format :

$product_name_rules = '\w \-\.\:';   (Codeigniter 3).

You can see this rule in Cart Library.

Here no any special character allow in product name. So, need some modification for allow special character. You can add same product name in cart with following modification in your cart class not in default Cart Library.

Add the following syntax before insert cart :


$this->cart->product_name_rules = '[:print:]';


After add this syntax your code looks like :


$this->cart->product_name_rules = '[:print:]';
$this->cart->insert(array());


'[:print:]' - allow to insert product name with special character.

Friday, 7 September 2018

Check if browser is Internet Explorer in jQuery

If you want to know that this browser is IE or not. You can check by following code:


<script>
function isIE() {
  ua = navigator.userAgent;

  /* MSIE used to detect old browsers and Trident used to newer ones*/

  var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
  
  return is_ie; 
}

/* Create an alert to show if the browser is IE or not */

if (isIE()){
alert('It is InternetExplorer');
}else{
alert('It is NOT InternetExplorer');
}
</script>






Friday, 17 August 2018

Codeigniter : How to get the selected option value in controller



Get the selected option value in controller


Put this code in view:

<select name="color" id="color" class="form_input">
    <option value="Red">Red </option>
    <option value="Green">Green</option>
   <option value="Blue">Blue</option>
   <option value="Yellow">Yellow</option>
   <option value="Pink">Pink</option>
</select>

Now, add following code in controller for get selected value : 

<?php $color= $this->input->post("color"); ?>



Now, get multiple selected option values in contorller


Put this following code in view:

<select  class="default " id="color" name="color[]">
   <option value="">Select color</option>
   <?php foreach ($colors as $color) {  ?>
   <option value="<?php echo $color->color_id;?>">
   <?php echo $color->color_name;?>
   </option>
   <?php } ?>
</select>


Now, add following code in controller or model for get selected values : 

<?php $colors = $this->input->post("color"); ?>










Thursday, 16 August 2018

Codeigniter : Check if id already exists in database

Check if any id already exists in database table and not exist id, insert in table.



$product_category = $this->input->post('product_category');    // product_category is multiple checkbox name


$dataCatBatch = array();
foreach($product_category as $_category){
$ros = $this->db->get_where('product_category',array('product_id'=>$productId,'category_id'=>$_category))->num_rows();
if($ros == 0){
$dataCatBatch[] = array('product_id'=>(int)$productId,'category_id'=>(int)$_category);
}
}

if(count($dataCatBatch) > 0){
$this->db->insert_batch('product_category',$dataCatBatch);
}

Description : product_category is table name. You can change column name according your table column name. 

Jquery : Sum of multiple input fields in one input

Sum of multiple input fields if all input fields have same class in one input field by Jquery

<input type="text" class="pro_qty" value="" />

<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="total_qty" value="" />
<script>
$(document).on("change", ".pro_qty", function() {
var sum = 0;

$(".pro_qty").each(function(){
sum += +$(this).val();
});

$(".total_qty").val(sum); });
</script>

Friday, 12 May 2017

How to check customer email id is exist or not before registration in Magento?


You can check customer email id is exist or not before registration in Magento by following code.


          $customer = Mage::getModel('customer/customer');
                $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                $customer->loadByEmail($customer_email);

                if($customer->getId())
                {
                  echo "Customer Exist";
                }




Thursday, 20 October 2016

How to add breadcrumbs on custom phtml page?

You can add breadcrumbs from your custom index controller action. Reference code is below.


<?php 

 
    public function IndexAction() {     
      $this->loadLayout();
      $this->getLayout()->getBlock("head")->setTitle($this->__("CB Magento Developer"));  /* add your page title */
            $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
      $breadcrumbs->addCrumb("home", array(
                "label" => $this->__("Home Page"),
                "title" => $this->__("Home Page"),
                "link"  => Mage::getBaseUrl()
           ));

      $breadcrumbs->addCrumb("magento_developer", array(       /* add css class */
                "label" => $this->__("Magento Developer"),
                "title" => $this->__("Magento Developer")
           ));

      $this->renderLayout();

    }


?>

How to call static block in CMS page in admin?

Call static block in CMS Page by following code:



{{block type="cms/block" block_id="your_block_id"}}

Wednesday, 19 October 2016

Display Magento Category on any page or custom module page

How you can get list of all categories of your Magento Store.


If you want to display all categories in homepage or any CMS page or any custom module page. There are different ways to get the category listing. Some method are below:-


Get all Categories:

The below code will fetch all categories (both active and inactive), which are added in your Magento Store.


$categories = Mage::getModel('catalog/category')                                         ->getCollection()                                          ->addAttributeToSelect('*');


Get all active categories


The below code will fetch all active categories, which are added in your Magento Store. Thus filtering the inactive categories.


$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter();



Get active categories of any particular level


The below code will fetch all active categories of  particular level. Here, I have selected level 2.


$categories = Mage::getModel('catalog/category')->getCollection()
->addIsActiveFilter()
->addAttributeToFilter('level','2')
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');


Now, You can display Name, URL, id etc. by following code:


foreach ($categories as $category)
{
        $entity_id = $category->getId();
        $name = $category->getName();
        $url_key = $category->getUrlKey();
        $url_path = $category->getUrl();
}


Monday, 17 October 2016

How to add breadcrumbs in Magento.

You have add bredcum by two ways:



1. Via code (Add in a controller):


              $crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');

           $crumbs->addCrumb('home', array(

'label' => 'Home',

'title' => 'Go to Home Page',

'link' => Mage::getUrl('')

));


2. Via Layout XML:


              <reference name="breadcrumbs">

                 <action method="addCrumb">

                     <crumbname>home</crumbname>  <!-- Class Name Which apply on li -->

                    <crumbinfo>

                         <label>Home</label>

                        <title>Go to Home Page</title>

                        <link>/</link>

                  </crumbinfo>

             </action>

            <action method="addCrumb">

 <crumbName>cb</crumbName>  <!-- Class Name Which apply on li -->

<crumbInfo>

<label>CB</label>

<title>CB</title>

</crumbInfo>

  </action>

</reference>


Thursday, 13 October 2016

How to import products with custom options by CSV file in Magento

If you want to import products with custom options by CSV file. So, you need some changes in "app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php" file. 

But it is core file of Magento, so we can not change directly in this file.  Because when you update Magento, then this file will be replace from new file and your customization will be removed.

So, you copy this file on same location in "app/code/local" folder.


app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php

 to 

app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php


Now, open ("app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php") file and add some following codes.


The below line numbers can change in different Magento versions. I used line numbers according to Magento ver. 1.9.2.4.


At about line 734 you will see:

foreach ($importData as $field => $value) {

Just above add following code:

$custom_options = array();


At about line 742 you will see:

$attribute = $this->getAttribute($field);
if (!$attribute) {
   continue;

}



Now need,  add some code above the continue statement.


/* CUSTOM OPTION CODE */
if(strpos($field,':')!==FALSE && strlen($value)) 
{
$values=explode('|',$value);
if(count($values)>0) 
{
@list($title,$type,$is_required,$sort_order) = explode(':',$field);
$title = ucfirst(str_replace('_',' ',$title));
$custom_options[] = array(
'is_delete'=>0,
'title'=>$title,
'previous_group'=>'',
'previous_type'=>'',
'type'=>$type,
'is_require'=>$is_required,
'sort_order'=>$sort_order,
'values'=>array()
);

foreach($values as $v) 
{
$parts = explode(':',$v);
$title = $parts[0];
if(count($parts)>1) {
$price = $parts[1];
} else {
$price =0;
}
if(count($parts)>2) {
$price_type = $parts[2];
} else {
$price_type = 'fixed';
}
if(count($parts)>3) {
$sku = $parts[3];
} else {
$sku='';
}
if(count($parts)>4) {
$sort_order = $parts[4];
} else {
$sort_order = 0;
}

switch($type) 
{
case 'file':

$custom_options[count($custom_options) - 1]['sku'] = $your_custom_sku;
$custom_options[count($custom_options) - 1]['file_extension'] = $your_custom_file_extension;
$custom_options[count($custom_options) - 1]['image_size_x'] = $your_custom_X_size;
$custom_options[count($custom_options) - 1]['image_size_y'] = $your_custom_Y_size;
$custom_options[count($custom_options) - 1]['price'] = $your_custom_price;
$custom_options[count($custom_options) - 1]['price_type'] = $your_custom_price_type;
break;

case 'field':
case 'area':
$custom_options[count($custom_options) - 1]['max_characters'] = $sort_order;

/* NO BREAK */

case 'date':
case 'date_time':
case 'time':
$custom_options[count($custom_options) - 1]['price_type'] = $price_type;
$custom_options[count($custom_options) - 1]['price'] = $price;
$custom_options[count($custom_options) - 1]['sku'] = $sku;
break;

case 'drop_down':
case 'radio':
case 'checkbox':
case 'multiple':
default:
$custom_options[count($custom_options) - 1]['values'][]=array(
'is_delete'=>0,
'title'=>$title,
'option_type_id'=>-1,
'price_type'=>$price_type,
'price'=>$price,
'sku'=>$sku,
'sort_order'=>$sort_order,
);
break;
}
}
}
}

/* END CUSTOM OPTION CODE */



Now, you'll see $product->save(); . Add following code just after.


/* Remove existing custom options attached to the product */
foreach ($product->getOptions() as $o) 
{
$o->getValueInstance()->deleteValue($o->getId());
$o->deletePrices($o->getId());
$o->deleteTitles($o->getId());
$o->delete();
}

/* Add the custom options specified in the CSV import file */

if(count($custom_options)) 
{
foreach($custom_options as $option) {
try {
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$opt->addOption($option);
$opt->saveOptions();
}
catch (Exception $e) {}
}

}




That's it. Now, you add all product custom options in CSV file.

For, import a custom option, you have need to add a new column to your CSV import file. The name of the column determines the name and type of the option. The format is: Name:Type:Is Required. 

For example, You want to add drop down option called "Size". So your column header should be Size:drop_down:1 (1 for required, 0 for optional). Here is a list of the Types, which is used for "Custom Options" in the Magento admin area.

* field: Field
* area: Area
* file: File
* drop_down: Drop-down
* radio: Radio Buttons
* checkbox: Checkbox
* multiple: Multiple Select
* date: Date
* date_time: Date & Time
* time: Time

If you want import multiple values for one type (drop_down, radio, checkbox, multiple), so you can specify using a | separator. For Example, you are using Small, Medium, Large Size, you would use "Small|Medium|Large" as the value for the "Size:drop_down:1" column in your csv file.

Here's example of the import product with custom option format:

sku,name,description,price,Size:drop_down:1

T-Shirt1,T-Shirt,A T-Shirt,5.00,Small|Medium|Large
T-Shirt2,T-Shirt2,B T-Shirt,6.00,XS|S|M|L|XL


Now, if you want to an additional price and SKU for each option value. So, the complete syntax with all option values is:

title:price:price_type[fixed or percent]:sku:sort_order

Small|Medium:5:fixed::1|Large:10:percent:L_10:0


Here's the first example with additional price/sku modifiers.

sku,name,description,price,Size:drop_down:1
T-Shirt1,T-Shirt1,A T-Shirt,5.00,Small:0:fixed:-SM:0|Medium:2:percent:-MED:1|Large:3:percent:-LRG:2

Tuesday, 12 April 2016

How to get attribute code in Magento filter.phtml file?

If you want to get attribute code in Magento "filter.phtml" file.



Then use below code in foreach loop: 



<?php echo $_item->getFilter()->getAttributeModel()->getAttributeCode() ?>






How to remove product count from layered navigation in Magento?

If we want to remove product count from layered navigation in Magento, then we can follow following different steps:


1. You can disable the product count in layered navigation from the Admin Panel, without modifying any templates.


               Open Admin Panel and change following setting.



System -> Configuration -> Catalog -> Layered Navigation -> Display Product Count   


Set Display Product Count "No" and save setting.






2. You can remove from phtml file.

      Open following file from following location:

      app/design/frontend/base/default/template/catalog/layer


      And Remove below code or comment code:

     (<?php echo $_item->getCount()  ?>)





Thursday, 7 April 2016

How to Remove/ Disable “Estimate Shipping and Tax” from cart page in Magento

If You want to Remove or Disable “Estimate Shipping and Tax” from cart page in Magento.


Then remove following code from: 



/app/design/frontend/your_package/yourtheme/layout/checkout.xml



Locate this piece of code on line 89:



<block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="checkout/cart/shipping.phtml"/>






Comment it out using <!–.....................…–> like:






Now, refresh the shopping cart page, you will no longer see the ‘Estimate Shipping and Tax’ block.






Tuesday, 5 April 2016

How to display “You Save” option on product detail page in Magento

You want to display "You Save: $ 0000" Price for "Special Price" on product detail page in Magento. Then you can follow the following steps:


Copy following file:

   
 app/design/frontend/base/default/template/catalog/product/price.phtml       
    

to your theme folder:


 app/design/frontend/default/yourtemplate/template/catalog/product/price.phtml


Then


Paste Following code, After 

   <?php   else: /* if ($_finalPrice == $_price): */  ?>




Paste Code:


 <?php   if( $cb_finalPrice  <  $cb_OrgPrice ) :     ?>


    <?php 

$_saveDiscountPercent = 100 - round(($cb_finalPrice / $cb_OrgPrice) * 100);  // if you want to display save                                                                           percentage 


  $_saveDiscountAmount = number_format(($cb_OrgPrice - $cb_finalPrice), 2);  


    ?>
        <p class="cbsave">


            <span class="price-label label">You Save :  </span>


            <span class="price">


                   <strong class="save-discont-amount">


 $<?php echo $_saveDiscountAmount ; ?> 


<?php echo '('.$_saveDiscountPercent .'%)'; 

                                   // if you want to display save percentage  ?>


                    </strong> 


            </span>


        </p>


    <?php endif;  ?>





Wednesday, 9 March 2016

How we can increase the Magento performance

We can increase the Magento Performance, follow by following steps:


  1. Disable the Magento log
  2. Disable un-used modules
  3. Enable Magento Caching
  4. Enable Gzip compression
  5. Optimize your image
  6. Optimize your Server
  7. Use a Content Delivery Network (CDN)
  8. USE Gzip Components
  9. Put Stylesheets at the Top (CSS Files in head tag)
  10. Put Scripts at the Bottom (Js files in footer)
  11. Avoid CSS Expressions (e.g 100/2)

What are the different features of Magento

  1. User Management
  2. Customer Management
  3. Product Management
  4. Order Management
  5. Payment Management
  6. Site Management
  7. Search engine optimization
  8. International Support