Thursday 25 April 2013

Magento - How to Access key values from Magento->getData() method?

 - If we want to get values from Magento->getData() method return array,


$_items = $order->getItemsCollection();

foreach ($_items as $one_item) {

            Zend_Debug::dump($one_item->getData()); 
}

for above we got respons like below,

array(82) {
  ["item_id"] => string(2) "58"
  ["order_id"] => string(2) "45"
  ["parent_item_id"] => NULL
  ["quote_item_id"] => string(2) "61"
  ["store_id"] => string(1) "1"
  ["created_at"] => string(19) "2012-11-21 07:14:43"
  ["updated_at"] => string(19) "2012-11-21 07:14:43"
  ["product_id"] => string(2) "52"
  ["product_type"] => string(6) "simple"
  ["product_options"] => string(179) "a:1:{s:15:"infost";a:3:{s:4:"uc";s:88:"aHR,,";s:7:"product";s:2:"52";s:3:"qty";i:1;}}"
  ["weight"] => string(7) "50.0000"
  ["is_virtual"] => string(1) "0"
  ["sku"] => string(4) "1112"
  ["name"] => string(5) "Chair"
  ["description"] => NULL
  ["applied_rule_ids"] => NULL
  ["additional_data"] => NULL
  ["free_shipping"] => string(1) "0"
  ["is_qty_decimal"] => string(1) "0"
  ["no_discount"] => string(1) "0"
  ["qty_backordered"] => NULL
  ["qty_canceled"] => string(6) "0.0000"
  ["qty_invoiced"] => string(6) "0.0000"
  ["qty_ordered"] => string(6) "1.0000"
  ["qty_refunded"] => string(6) "0.0000"
  ["qty_shipped"] => string(6) "0.0000"
  ["base_cost"] => string(7) "50.0000"
  ["price"] => string(8) "129.9900"
  ["base_price"] => string(8) "129.9900"
  ["original_price"] => string(8) "129.9900"
  ["base_original_price"] => string(8) "129.9900"
  ["tax_percent"] => string(6) "0.0000"
  ["tax_amount"] => string(6) "0.0000"
  ["base_tax_amount"] => string(6) "0.0000"
  ["tax_invoiced"] => string(6) "0.0000"
  ["base_tax_invoiced"] => string(6) "0.0000"
  ["discount_percent"] => string(6) "0.0000"
  ["discount_amount"] => string(6) "0.0000"
  ["base_discount_amount"] => string(6) "0.0000"
  ["discount_invoiced"] => string(6) "0.0000"
  ["base_discount_invoiced"] => string(6) "0.0000"
  ["amount_refunded"] => string(6) "0.0000"
  ["base_amount_refunded"] => string(6) "0.0000"
  ["row_total"] => string(8) "129.9900"
  ["base_row_total"] => string(8) "129.9900"
  ["row_invoiced"] => string(6) "0.0000"
  ["base_row_invoiced"] => string(6) "0.0000"
  ["row_weight"] => string(7) "50.0000"
  ["gift_message_id"] => NULL
  ["gift_message_available"] => NULL
  ["base_tax_before_discount"] => NULL
  ["tax_before_discount"] => NULL
  ["weee_tax_applied"] => string(6) "a:0:{}"
  ["weee_tax_applied_amount"] => string(6) "0.0000"
  ["weee_tax_applied_row_amount"] => string(6) "0.0000"
  ["base_weee_tax_applied_amount"] => string(6) "0.0000"
  ["base_weee_tax_applied_row_amnt"] => string(6) "0.0000"
  ["base_weee_tax_applied_row_amount"] => string(6) "0.0000"
  ["weee_tax_disposition"] => string(6) "0.0000"
  ["weee_tax_row_disposition"] => string(6) "0.0000"
  ["base_weee_tax_disposition"] => string(6) "0.0000"
  ["base_weee_tax_row_disposition"] => string(6) "0.0000"
  ["ext_order_item_id"] => NULL
  ["locked_do_invoice"] => NULL
  ["locked_do_ship"] => NULL
  ["price_incl_tax"] => string(8) "129.9900"
  ["base_price_incl_tax"] => string(8) "129.9900"
  ["row_total_incl_tax"] => string(8) "129.9900"
  ["base_row_total_incl_tax"] => string(8) "129.9900"
  ["hidden_tax_amount"] => NULL
  ["base_hidden_tax_amount"] => NULL
  ["hidden_tax_invoiced"] => NULL
  ["base_hidden_tax_invoiced"] => NULL
  ["hidden_tax_refunded"] => NULL
  ["base_hidden_tax_refunded"] => NULL
  ["is_nominal"] => string(1) "0"
  ["tax_canceled"] => NULL
  ["hidden_tax_canceled"] => NULL
  ["tax_refunded"] => NULL
  ["base_tax_refunded"] => NULL
  ["discount_refunded"] => NULL
  ["base_discount_refunded"] => NULL
}

- From the above we can access data like below, (ex. we need to get orderid)

 "
$one_item->getOrderId();

             (OR)

$one_item->getData('order_id')  "

- Likewise we can access the other datas from that array.

How to make PDF file downloadable in PHP

 - To Make PDF as downloadable in PHP,


 $filename = '/path/to/your/file/download.pdf';
  header("Pragma: public");
  header("Expires: 0"); 
  header("Pragma: no-cache"); 
  header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0,pre-check=0");  
  header("Content-Type: application/force-download"); 
  header("Content-Type: application/octet-stream");
  header("Content-Type: application/download");
  header('Content-disposition: attachment; filename=' . basename($filename));
  header("Content-Type: application/pdf");
  header("Content-Transfer-Encoding: binary");
  header('Content-Length: ' . filesize($filename));
  @readfile($filename);
  exit(0);

Wednesday 24 April 2013

Jquery - How to change button type using jquery


- If we need to change input field "type" change,



$('#password').get(0).type ='text';
$('#submit_btn').get(0).type ='button';


Yii Examples of Using CDbCriteria


Examples of Using CDbCriteria
Basic Usage
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Products = Product::model()->findAll($Criteria);
OR
//An example using the constructor to populate the properties.
$Criteria = new CDbCriteria(array('condition' => 'price > 30'));
$Products = Product::model()->findAll($Criteria);
Personally, I like to go with the first approach. I think it’s generally easier to read, but that’s just my personal preference.
Adding A Limit
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Products = Product::model()->findAll($Criteria);
Limit with Offset
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Products = Product::model()->findAll($Criteria);
Ordering Results
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Criteria->order = "name ASC";
$Products = Product::model()->findAll($Criteria);
Limiting Selected Fields
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Criteria->order = "name ASC";
$Criteria->select = "id, name";
$Products = Product::model()->findAll($Criteria);
Example relation with :
$criteria = new CDbCriteria;
$criteria->with = array('foreign_table1',
                        'foreign_table2', 
                        'foreign_table2.foreign_table3');
$criteria->together = true; // ADDED THIS
$criteria->select = array('id');
$criteria->condition = "foreign_table1.col1=:col_val AND 
                        foreign_table3.col3=:col_val2";
$criteria->params = array(':col_val' => some_val, ':col_val2' => other_val);
$criteria->order = 'foreign_table3.col5 DESC';
$criteria->limit = 10;