Just another WordPress.com weblog

Hello

Table rates shipping method is not working properly in magento 1.6 or after migration to magento v1.6.

To resolve this follow below points:

1)Open file Mage/Shipping/Model/Resources/Carrier/Tablerate.php and copy it in app/code/local folder
2)Find getRate() function and replace given code in that function:

public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$adapter = $this->_getReadAdapter();
$bind = array(
‘website_id’ => (int)$request->getWebsiteId(),
‘country_id’ => $request->getDestCountryId(),
‘region_id’ => (int)$request->getDestRegionId(),
‘postcode’ => $request->getDestPostcode()
);

$select = $adapter->select()
->from($this->getMainTable())
->where(‘website_id = ‘.$bind[‘website_id’])
->order(array(‘dest_country_id DESC’, ‘dest_region_id DESC’, ‘dest_zip DESC’,’condition_value DESC’))
->limit(1);

// render destination condition
$orWhere = ‘(‘ . implode(‘) OR (‘, array(
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = “.$bind[‘postcode’],
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ””,
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ‘0’”,
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ‘*'”,
//”dest_country_id = ‘0’ AND dest_region_id = 0 AND dest_zip = ‘*'”,
)) . ‘)’;
$select->where($orWhere);

// render condition by condition name
if (is_array($request->getConditionName())) {
$orWhere = array();
$i = 0;

foreach ($request->getConditionName() as $conditionName) {

$bindNameKey = sprintf(‘:condition_name_%d’, $i);
$bindValueKey = sprintf(‘:condition_value_%d’, $i);
$orWhere[] = “(condition_name = {$bindNameKey} AND condition_value getData($conditionName);
$i++;
}

if ($orWhere) {
$select->where(implode(‘ OR ‘, $orWhere));
}
} else {

$bind[‘condition_name’] = $request->getConditionName();
$bind[‘condition_value’] = $request->getData($request->getConditionName());

$select->where(‘condition_name = “‘.$bind[‘condition_name’].'”‘);
$select->where(‘condition_value fetchRow($select, $bind);
// normalize destination zip code
if ($result && $result[‘dest_zip’] == ‘*’) {
$result[‘dest_zip’] = ”;
}
return $result;
}

This works for me like a charm. Hope it works for you also.

If it helps you don’t forget to comment me.

Regards,
Meghna Vora

Hello

Getting to this point ultimately lead to the resolution. Below is the process we used to solve the reindexing issue for Product Flat Data:

1) Export all catalog_product_flat _* tables with data and structure with “Disable foreign key checks” enabled.
2) Drop all catalog_product_flat _* tables.
3) Once check in Frontend , that products are categories are visible
4) Login to Magento backend
5) Go to: System -> Index Management
6) Click “Reindex Data” next to “Product Flat Data” index

Below is the process we used to solve the reindexing issue for Category Products (Indexed category/products association):

1) Log into phpMyAdmin
2) Go to `catalog_category_product_index`
3) Click “Export”.
4) Export only structure with “Disable foreign key checks” enabled.
5) Drop the table `catalog_category_product_index`
6) With the SQL that was exported, remove the constraints at the bottom of the export. Be sure to keep the “SET FOREIGN_KEY_CHECKS” statements.
7) Click “SQL”, paste in modified SQL and click “Go”
8) Login to Magento backend
9) Go to: System -> Index Management
10) Click “Reindex Data” next to “Category Products” index

This worked for me ..Hope it will help you too.

If it helps dont forget to comment me ..

Meghna Vora

Hello All,

Below is the steps to change encoded path of image and display in listing page of magento

1) Add below funciton in Image.php project/app/Local/Mage/Catalog/Helper/Image.php
Copy the core file and place in local folder and than add the code in local file.

/*********Function added to encrypt image path**********/

public function base64_encode_image ($filename=string,$filetype=string) {
if ($filename) {

$changeFilePath = explode(‘cache’,$filename);
$changeFilePath = Mage::getBaseDir(). DS. ‘media’. DS. ‘catalog’.DS.’products’.DS.’cache’.$changeFilePath[1];

$imgbinary = fread(fopen($changeFilePath, “r”), filesize($changeFilePath));
return ‘data:image/’ . $filetype . ‘;base64,’ . base64_encode($imgbinary);
}
}

Now we will call above function in list.phtml file of project/app/design/catalog/product/list.phtml

Add below inside foreach loop

<?php
$this->helper('catalog/image')->init($_product, 'small_image')->resize(193,250);
$forFiletype = explode('.',$product_image);
$forFiletype = array_reverse($forFiletype);
$filetype = $forFiletype[0];
if(strtoupper($filetype) == 'JPG')
{
$filetype = 'jpeg';
}
$base64image = '';
$base64image = $this->helper('catalog/image')->base64_encode_image($product_image,$filetype);

?>

And change Image tag of product same as Below:


<img src="<?php echo $this->getSkinUrl('images/spacer.png'); ?>" width="193" height="250" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="background:url(<?php echo $base64image;?>) no-repeat;"/>

When user save image it will save spacer image and not the original image.

I hope this post is helpful to you. If you have any question leave the comment.

Thanks,
Bijal Bhavsar 🙂

Hello All,

I found the way to rename product image folder from ‘product’ to ‘products’ or any name you wants.

1) First of all you have to rename folder name to the physical path of your project (i.e ‘project/media/catalog/product’ to ‘project/media/catalog/products’)

2) You need to change in 5 files under PATH = project/app/Mage/Catalog/Model:
You need to change from all media path ‘product’ to ‘products’ to below listed files.


file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.$size.DS.$image)

TO

file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'products'.DS.$size.DS.$image)

REPLACE below code

'catalog/product/'

TO
'catalog/products/'

File1: PATH / Product/Attribute/Frontend/Image.php

File2: PATH / Product/Attribute/Media/Image.php

File3: PATH / Product/Image.php

File4: PATH / Product/Media/Config.php

File5: PATH / Entity/Product/Attribute/Frontend/Image.php

I hope you will find this post helpful.. If you have any question add your comment.

Thanks,
Bijal Bhavsar 🙂

To Add New Rupee symbol in magento currency follow below steps:

1. Add below css and js in header.phtml of your design theme.
link rel=”stylesheet” type=”text/css” href=”http://cdn.webrupee.com/font&#8221;
script src=http://cdn.webrupee.com/js type=”text/javascript”

2. add below code in root.xml
path of file: lib/Zend/Locale/Data/root.xml open file in wordpad

find:

currency type=”INR”

replace symbol Rs with: amp#x20B9; (use & for amp).

3. After this refersh cache from admin and manually delete cache from front var/cache folder.

Now in front end it will display new India rupee symbol.

Thanks
Krupal Lakhia

Magento Transactional emails not working

IF you installed wysiwyg editor ,, then try to disable from etc/modules/Namespace_Modulename.xml

Thanks
vishal surani

For example in our custom module we have to add order_id in grid, if we search by order id in grid than such type of error occurs.

SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘Order_id’
in where clause is ambiguous

to resolve such error we can add ‘filter_index’=>’main_table.order_id’ in $this->addColumn() function


$this->addColumn('order_id', array(
'header' => Mage::helper('couponcode')->__('Order Id'),
'align' =>'left',
'index' => 'order_id',
'filter_index'=>'main_table.order_id', // This parameter helps to resolve above error
));

Thanks,
Bijal Bhavsar 🙂

To generate pdf from html using tcpdf, follow the below steps:

Step1: Download tcpdf library from below link
http://sourceforge.net/projects/tcpdf/files/

Step2: Add tcpdf folder in your project at path :: Your_project/lib/tcpdf

Step3: Create html file at any place you wants.. Than create one function in model file.. to generate pdf like below:


public function generatePdf($couponIds)
{
$filename = " HERE PATH OF HTML FILE WILL COME" ; //EG: Mage::getBaseDir().'/app/locale/en_US/template/email/coupon.html' this will return file coupon.html
$logoImage = Mage::getBaseDir().'/skin/frontend/default/default/images/logo_pdf.jpg'; //logo image path
$ptemplate = file_get_contents($filename);
$couponFindReplace = array(
'##LOGO_IMAGE##' =>$logoImage ,
'##FOOTER_TEXT_IMAGE##' =>$footertextImage
}
//Above array is to change content dynamically.
$after_replace = strtr($ptemplate, $couponFindReplace);
$pdf_html = $after_replace;
require_once(Mage::getBaseDir().'/lib/tcpdf/config/lang/eng.php');
require_once(Mage::getBaseDir().'/lib/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('PDF Title');
$pdf->SetAuthor('Author');
$pdf->SetKeywords('PDF','tcpdf','html');
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'ltr';
$lg['a_meta_language'] = 'en';
$lg['w_page'] = 'page';
$pdf->SetFont('times','',20); //set font of pdf and default font size is 20
//set some language-dependent strings
$pdf->setLanguageArray($lg);

// add a page
$pdf->AddPage();
$pdf->writeHTML($coupon_pdf_html, true, 0, true, true);
//$pdf->Output('test.pdf','D'); //this will create pdf and download at a time..
/*START:: To create pdf at particular location in server*/
$file_name = 'test.pdf';
$file_name_path = Mage::getBaseDir().'/media/coupons/'.'test.pdf';
if(file_exists($file_name_path))
{
unlink($file_name_path);
}
$pdf->Output($file_name_path,'F');
@chmod($file_name_path, 0777);
/*END:: To create pdf at particular location in server*/
return $file_name;
}

above function will generate pdf

The above are the steps to create simple pdf..

If the above code is helpful to you than do reply….

Thanks,
Bijal Bhavsar:)

Hello,

We all know that Paypal is not working in Magento – Multishipping..

if we want to make it work just open
code/core/Mage/Paypal/Model/Standard.php
in this file the variable
protected $_canUseForMultishipping = flase;
is initialized make it
protected $_canUseForMultishipping = true;

now you can use Paypal with Multishipping in Magento

Thanks
vishal surani

Hello,

If you have problem with Catalog Price Rules…
When we apply catalog price rules then rules are reflect to product listing and product detail
but when we add product in cart its taking original product price …

I think its magento core problem.

Any-way , lets solve it ….

open Mage/Catalogrule/Model/Observer.php
around 101st line

you have this segment …

if ($observer->hasCustomerGroupId()) {
$gId = $observer->getEvent()->getCustomerGroupId();
} elseif ($product->hasCustomerGroupId()) {
$gId = $product->hasCustomerGroupId();
} else {
$gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
}

Now in 4th line we have code like
$gId = $product->hasCustomerGroupId();
… simply change this to
$gId = $product->getCustomerGroupId();

Thanks…

-Vishal Surani