Friday 26 June 2015

CodeIgniter Remove index.php from URL

change in .htaccess file and try it

RewriteEngine OnRewriteBase /project/RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Pagination in CodeIgniter

Controller:
------------------------
public function index() {
        $count = $this->dcategory->Count_drugcategories();
        $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
        $this->load->library('pagination');
        $config['base_url'] = base_url('drug_categories');
        $config['use_page_numbers'] = TRUE;
        $config['total_rows'] = $count;
        $config['per_page'] = 10;
        $config["uri_segment"] = 2;
        $this->pagination->initialize($config);
        $limit = $config['per_page'];
        $start = ($page  == 0) ? 0 : ($page * $config['per_page']) - $config['per_page'];
        $data['query'] = $this->dcategory->Getlist_drugcategories($start,$limit);      
        $seo['title'] = 'Drug Categories List | ekimed';
        $data['links'] = $this->pagination->create_links();
        $this->load->view('layout/header',$seo);
        $this->load->view('drug_categories/listdrugcategories',$data);
        $this->load->view('layout/footer');
    }

Model:
----------------------
function Getlist_drugcategories($limit=0,$start=0){
        $this->db->select('*');
        if($limit>0 && $start>=0) {
            $this->db->limit($limit,$start);
        } else {
            $this->db->limit(10);
        }
        $query = $this->db->get($this->drugs_category);
        if($query->num_rows() > 0){
            return $query->result();
        } 
        return FALSE;
    }

Views:
-----------
<?php echo $links; ?>

Inserting multiple rows mysql in codeigniter

if your php version>=5.4 it should work.
You may try this

if ($_POST) { $row_ids=$this->input->post('id'); $desc=$this->input->post('desc'); $spaces=$this->input->post('space'); $prices=$this->input->post('price'); $totals=$this->input->post('total'); $data = array(); for ($i = 0; $i < count($this->input->post('id')); $i++) { $data[$i] = array( 'row_id' => $row_ids[$i], 'desc' => $desc[$i], 'space' => $spaces[$i], 'price' => $prices[$i], 'total' => $totals[$i], 'code' => time() ); } $this->Home_model->create($data); }

Only variable references should be returned by reference - Codeigniter

Edit filename: core/Common.php, line number: 257

Before

return $_config[0] =& $config; 
 
After
 
$_config[0] =& $config;return $_config[0];  

How to called codeigniter helper function using JQuery AJAX?

You need to make a request via controller, then call that function through that controller, something like:
 
 
$("#id").change(function()
{       
 $.ajax({
     type: "POST",
     url: base_url + "controller_name/your_function", 
     data: {val: $("#your_val").val(),currency_id: $("#your_cur").val()},
     dataType: "JSON",  
     cache:false,
     success: 
          function(data){
            $("#your_elem").val(data.price);
      }
});
 
 
Then on your controller:

public function yourfunction()
{
   $data = $this->input->post();
   $price = format_price($data['val'],$data['currency_id']);
   echo json_encode(array('price' => $price));
}

PHP - CodeIgniter - Invalid argument supplied for foreach()

<?php if(is_array($result)): ?>
<?php foreach($result as $row):?>  
<h3><? echo $row->title; ?></h3>  
<p><? echo $row->text; ?></p>  
<?php endforeach;?>  
<?php endif; ?>

How to assign category on multiple products in Magento

  • In your backend, go to Catalog -> Categories -> Manage Categories.
  • Select the category you want to add products to.
  • Click "Category Products" Tab
  • Reset the Filter, select your products, Save Category

Monday 8 June 2015

How to make custom page in opencart

1) Create a new file in admin/controller/custom/helloworld.php

helloworld.php
load->model(‘custom/hello’);
$this->template = ”.$template.”;
$this->children = array(
‘common/header’,
‘common/footer’
);
$this->response->setOutput($this->render());
}
}
?>

2) Create a new file in admin/view/template/custom/hello.tpl

Hello.tpl

HelloWorld

3) Create a new file in admin/model/custom/hello.php

hello.php

db->query($sql);
return $query->row[‘total’];
}
}
?>

4) You then need to enable the plugin to avoid permission denied errors:

Opencart > Admin > Users > User Groups > Admin > Edit

http://www.example.com/opencart/admin/index.php?route=custom/helloworld


Import “Not Logged In” Pricing in Magento

<?php
/**
 * Class Tier price processor
 * @author dweeves
 *
 * This imports tier prices for columns names called "group_price:"
 */
class GrouppriceProcessor extends Magmi_ItemProcessor
{
    protected $_tpcol=array();
    protected $_singlestore=0;
    protected $__pricescope=2;

    public function getPluginInfo()
    {
        return array(
            "name" => "Group price importer",
            "author" => "Dweeves,bepixeld,Jason",
            "version" => "0.0.1",
            );
    }

    

    public function processItemAfterId(&$item,$params=null)
    {

        $pid=$params["product_id"];

        $tpn=$this->tablename("catalog_product_entity_group_price");
        $tpcol=array_intersect(array_keys($this->_tpcol),array_keys($item));
        //do nothing if item has no group price info or has not change
        if(count($tpcol)==0  )
        {
            return true;
        }
        else
        {

         //it seems that magento does not handle "per website" tier price
// on single store deployments , so force it to "default"
          //so we test wether we have single store deployment
// or not.
          //bepixeld patch : check pricescope from general config
          if($this->_singlestore==0 && $this->_pricescope!=0)
          {
            $wsids=$this->getItemWebsites($item);
          }
          else
          {
            $wsids=array(0);
          }
          $wsstr=$this->arr2values($wsids);
            //clear all existing tier price info for existing customer groups in csv
           $cgids=array();
            foreach($tpcol as $k)
            {
                $tpinf=$this->_tpcol[$k];
                if($tpinf["id"]!=null)
                {
                    $cgids[]=$tpinf["id"];
                }
                else
                {
                    $cgids=array();
                    break;
                }

            }

            //if we have specific customer groups
            if(count($cgids)>0)
            {
                //delete only for thos customer groups
                $instr=$this->arr2values($cgids);

                //clear tier prices for 
//selected tier price columns
                $sql="DELETE FROM $tpn WHERE entity_id=? AND customer_group_id IN ($instr) AND website_id IN ($wsstr)";
                $this->delete($sql,array_merge(array($pid),$cgids,$wsids));
            }
            else
            {
                //delete for all customer groups
                $sql="DELETE FROM $tpn WHERE entity_id=? AND website_id IN ($wsstr)";
                $this->delete($sql,array_merge(array($pid),$wsids));
            }
        }

        foreach($tpcol as $k)
        {

        //get tier price column info
          $tpinf=$this->_tpcol[$k];
          //now we've got a customer group id
          $cgid=$tpinf["id"];
          //add tier price
          $sql="INSERT INTO $tpn
            (entity_id,all_groups,customer_group_id,value,website_id) VALUES ";
          $inserts=array();
          $data=array();

          if($item[$k]=="")
          {
            continue;
          }
          $tpvals=explode(";",$item[$k]);

          foreach($wsids as $wsid)
          {
                //for each tier price value definition
                foreach($tpvals as $tpval)
                {
                    $tpprice=str_replace(",",".",$tpval);
                    if($tpprice=="")
                    {
                        continue;
                    }
                    if(substr($tpprice,-1)=="%")
                    {
                        //if no reference price,skip % tier price
                        if(!isset($item["price"]))
                        {
                            $this->warning("No price define, cannot apply % on group price");
                            continue;
                        }
                        $fp=(float)(str_replace(",",".",$item["price"]));
                        $pc=(float)(substr($tpprice,0,-1));
                        $m=($pc<0?(100+$pc):$pc);
                        $tpprice=strval(($fp*($m))/100.0);
                    }
                    $inserts[]="(?,?,?,?,?)";
                    $data[]=$pid;
                    //if all , set all_groups flag
                    $data[]=(isset($cgid)?0:1);
                    $data[]=(isset($cgid)?$cgid:0);
                    $data[]=$tpprice;
                    $data[]=$wsid;
                }
          }
          if(count($inserts)>0)
          {
            $sql.=implode(",",$inserts);
            $sql.=" ON DUPLICATE KEY UPDATE `value`=VALUES(`value`)";
            $this->insert($sql,$data);
          }
         }
        return true;
    }

    public function processColumnList(&$cols,$params=null)
    {
       //inspect column list for getting tier price columns info
        foreach($cols as $col)
        {
            if(preg_match("|group_price:(.*)|",$col,$matches))
            {
                $tpinf=array("name"=>$matches[1],"id"=>null);

                //if specific tier price 
                 if($tpinf["name"]!=="_all_")
                 {
                    //get tier price customer group id
                    $sql="SELECT customer_group_id from ".$this->tablename("customer_group")." WHERE customer_group_code=?";
                    $cgid=$this->selectone($sql,$tpinf["name"],"customer_group_id");
                    $tpinf["id"]=$cgid;
                }
                else
                {
                    $tpinf["id"]=null;
                }
                $this->_tpcol[$col]=$tpinf;
            }
        }
        return true;
    }

    public function initialize($params)
    {
     $sql="SELECT COUNT(store_id) as cnt FROM ".$this->tablename("core_store")." WHERE store_id!=0";
     $ns=$this->selectOne($sql,array(),"cnt");
     if($ns==1)
     {
      $this->_singlestore=1;
     }
     //bepixeld patch : check pricescope from general config
     $sql = "SELECT value FROM ". $this->tablename('core_config_data') ." WHERE path=?";
     $this->_pricescope = intval($this->selectone($sql, array('catalog/price/scope'), 'value')); //0=global, 1=website    

    }
}

Tuesday 2 June 2015

How to replace word in database in mysql PHP


UPDATE student SET firstname = replace(firstname, 'jaydip', 'Kansagra');




 How to create multilingual static block in controller

$deliveryBlock = Mage::getModel('cms/block')->load('delivery_returns'); echo $deliveryBlock->getTitle(); echo $deliveryBlock->getContent(); 

Search does not return results in magento


Open your file Mage_CatalogSearch_Model_Layer and in method

public function prepareProductCollection($collection)
 
before return $this;

Add following rows:

Mage::log($collection->getSelectSQL(1), false, 'search.log', true);
Mage::log((array)Mage::getConfig()->getNode()->global->models->catalogsearch, false, 'search.log', true)

 OR

Goto -> admin->attributs->manage attribute-> search sku - open it -> Frontend Properties-> Use in Quick Search (YES )