Sunday, September 2, 2012

Magento Installation Linux/Ubuntu : Enable curl


Magento Installation Linux/Ubuntu : Enable curl

If you get error "curl cannot be loaded"  just run the below command in your linux terminal and the error will disappear.



sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

Monday, August 27, 2012

Magento : Get all options of a dropdown or multiselect attribute

Magento : Get all options of a dropdown or multiselect attribute

$arg_attribute = "manufacturer";//this may be any attribute code

//Object of attribute model

$attribute_model = Mage::getModel('eav/entity_attribute');

//Object of attribute options model

$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;

//

$attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);

$attribute = $attribute_model->load($attribute_code);

$attribute_table =$attribute_options_model->setAttribute($attribute);

//Getting all options

$options = $attribute_options_model->getAllOptions(false);

//Printing all options of particular attribute

echo "<pre />";

print_r($options);

Tuesday, August 21, 2012

Magento : Product list page wrong sorting by price

Magento : Product list page wrong sorting by price

When we install webtex_customergroupprice it has a bug when it sorts products

on product list page it is not correct. For this we need to change collections orderby.

We add

$collection->getSelect()->reset(Zend_Db_Select::ORDER)->order('(min_price)'.$orderDir);

at the end of the function public function sortByPrice() in file "app/code/local/Webtex/Customer

GroupsPrice/Model/Observer.php".

Refresh Cache and the sorting is perfect.

Enjoy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thursday, August 9, 2012

Magento : Ecommerce Tracking google analytics

Ecommerce Tracking google analytics magento

Code for sales conversion tracking in magento.

Add below code to the end of the success.phtml file in Magento

<?php
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$subtotal = $order->getSubtotal();
$order_id = $order->getId(); //the id of the order
//$order->getIncrementId();//the increment id of the order
$gtotal = $order->getGrandTotal();//grand total of the order
$address = $order->getBillingAddress()->getData();
$city = $address['city'];
$state = $address['region'];
$country = $address['country_id'];
?>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17916440-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '<?php echo $order_id; ?>',           // order ID - required
    'steigerhoutstunter.nl',  // affiliation or store name
    '<?php echo $gtotal;?>',          // total - required
    '0',           // tax
    '0',              // shipping
    '<?php echo $city;?>',       // city
    '<?php echo $state;?>',     // state or province
    '<?php echo $country;?>'             // country
  ]);

<?php
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{?>

 _gaq.push(['_addItem',
    '<?php echo $order_id; ?>',                // order ID - required
    '<?php echo $item->getSku(); ?>',          // SKU/code - required
    '<?php echo $item->getName(); ?>',         // product name
    'category name',                           // category or variation
    '<?php echo $item->getPrice(); ?>',        // unit price - required
    '<?php echo $item->getQtyToInvoice(); ?>'  // quantity - required
  ]);
<?php
}
?>
  _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

Sunday, August 5, 2012

Magento : Show guest name in last 5 orders magento admin dashboard


Show guest name in last 5 orders magento admin dashboard

On the magento community admin dashboard, Under "Last 5 orders" if there is an order by guest it doesnot show the name of guest customer. There were many instances when my clients wanted to show the names of guest too.
For this i have some suggestions. We can show the name from billing address there instead of the customer name. If you think my suggestion is feasible, i request to add this modification to the coming release of magento.
I have coded for this
In Mage/Adminhtml/Block/Dashboard/Orders/Grid.php about line '51' replace "->joinCustomerName('customer')"  with ->joinCustomerBName('customer')
and  in Mage/Reports/Model/Resource/Order/Collection.php

 add a function
 public function joinCustomerBName($alias = 'name')
    {
        $fields      = array('t2.firstname', 't2.lastname');
        $fieldConcat = $this->getConnection()->getConcatSql($fields, ' ');
        $this->getSelect()
        ->join(array('t2' => 'sales_flat_order_address'),'main_table.billing_address_id = t2.entity_id')->columns(array($alias => $fieldConcat));
       

        return $this;
    }

Thursday, July 5, 2012

Magento 1.6.1.0 : Custom option values not displaying at Orders in the Admin Page

In Magento 1.6.1.0 , when a product with custom option is ordered, the custom option values which are selected by customer do not display in  Orders in the Admin Page.( Sales >> Orders ). Also it is not displayed in the Invoice too.
But the values are visible at the order mails . Also when we will try to edit the order at Admin Orders itself, we will be able to see the values which are chosen by custome.

A simple solution to fix this bug:

Comment this line
<?php //$_option = $this->getFormattedOption($_option['value']); ?>

at line 44
in file "/app/design/adminhtml/default/default/template/sales/items/column/name.phtml"


ENJOY!!!!!!!!!

Wednesday, July 4, 2012

Magento : Inject custom module block to other modules

Magento inject custom module block to any module code sample



<firecheckout_index_index>

       <reference name="checkout.onepage.review.info.items.after">

           <block type="sendfriend/send" after="media"  name="sendfriend.send" template="sendfriend/send.phtml" />

       </reference>

   </firecheckout_index_index>