Thursday, December 8, 2011

IE9 Issue with Magento Checkout-Disabled Credit Card Fields-Fix

In some builds of Magento (Community and Enterprise), there is an issue with IE9 and all of the credit card fields being disabled. This is on step 4 of the one page checkout, and users will not be able to enter any information, or even use the dropdown select box to choose which type of credit card they are going to be using.



The fix:
Browse to your /skin/frontend/..template folder (if you’ve got one, if not, browse to the /skin/frontend/default/default/js/ folder). Open up the opcheckout.js file Around lines 641 AND 647, (inside the switchMethod function), replace :
1
var elements = form.select('input', 'select', 'textarea');
with
1
var elements = form.select('input').concat(form.select('select'), form.select('textarea'));
These 2 lines should fix your IE9 issues, as well as be compatible and work with Chrome/Firefox, earlier builds of IE, and others.

For other to solve the IE9 issue use the metatag in head of page

<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />

Tuesday, December 6, 2011

Extarct Fedex Shipping Response


 $xmltxt = $client->__getLastResponse(); 
       $xmltxt = preg_replace('#(</?)ns[\d]:#','$1',$xmltxt);     
     //remove all the namespaces that appear in the soap response.
        $xmltxt = preg_replace('#(</?)v[\d]:#','$1',$xmltxt);
         $xmltxt = preg_replace('#(</?)soapenv:#','$1',$xmltxt);
         echo $xmltxt;  
     //debuggig to make sure the SOAP is proper XML and 
         namespaces removed
        $doc = new DOMDocument();  
        $doc->loadXML($xmltxt);        
       $trackingNumber = $doc->getElementsByTagName("TrackingNumber");
        print_r($trackingNumber); //debugging to make sure this exists.
        
        if($trackingNumber = $trackingNumber->item(0)) { 
       //retrieve the first trackingnumber in the elements list.  
                $trackingNumber = $trackingNumber->nodeValue; 
        }  
        
        echo "Tracking Number :::::: ".$trackingNumber;

Saturday, November 19, 2011

How to change Magento search from LIKE ‘keyword’ to LIKE ‘keyword%’ but not LIKE ’%keyword% ?


The Like search is the most basic routine available in a SQL database engine that can be called a search function. It has to be applied against the data_index field in catalogsearch_fulltext and due to the fact that it is searching the whole field, has to be a sliding window search, or simulated simple regex if you’re used to those terms.
Here’s the code snippet that creates it:

foreach ($words as $word{
                    $like[] 
'`s`.`data_index` LIKE :likew' $likeI;
                    
$bind[':likew' $likeI] '%' $word '%';
                    
$likeI ++;
                
}
The reason for using %$word%; for the match string is pretty obvious and simple. It has to match against the whole field and find something bounded by spaces (definition of a word) to get a return match.
So a search on relation will return a match on: 
relation
correlation
correlations
   relations
   relationship
ad nauseum

If you remove the % from the beginning of the match string, then it has to match everything up to $word in the data_index field in order to return a match, so no solution there.
The next step is to decide that your customer might be smart enough to start a word with the right spelling, but trail off on the right hand side to unfindability. If Magento’s like search is modified to look for words starting with a space, looking for relation should no longer also return correlation, correlations, etc.
Where this modification falls down on the job is that it will never match the beginning of the data_index field, starting words in a parenthesis block or words that have been separated that are really one word or hyphenated.
For example, searches for black and stone will no longer return blackstone.
Modification to experiment with this this can be done in app/code/local/Mage/CatalogSearch/Model/Mysql4/Fulltext.php as follows: 
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
                
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE{
                $words 
$stringHelper->splitWords($queryTexttrue$query->getMaxQueryWords());
                
$likeI 0;
                foreach (
$words as $word{
                    $like[] 
'`s`.`data_index` LIKE :likew' $likeI;
                    
$bind[':likew' $likeI] '% ' $word '%';
                    
$likeI ++;
                
}
                
if ($like{
                    $likeCond 
'(' join(' AND '$like) . ')';
                
}
            }

From
'%' $word '%'; to
'% ' $word '%';

Tuesday, July 19, 2011

to find url in text and make them hyperlink


$text = preg_replace("
  #((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie",
  "'<a href=\"$1\" target=\"_blank\">$3</a>$4'",
  $text);

Thursday, June 30, 2011

How to get sold quantity of product in magento


If you want to have it so that it only shows quantity sold on the product page on items that are currently on sale.. use the following., There will also be an alert for customers when there is only 1 remaining in stock.Then use the following code.
<?php 
$_finalPrice 
$this->helper('tax')->getPrice($_product$_product->getFinalPrice());$_regularPrice $this->helper('tax')->getPrice($_product$_product->getPrice());
if (
$_regularPrice != $_finalPrice):$sku nl2br($_product->getSku());$to $_product->getResource()->formatDate(time());$from $_product->getResource()->formatDate(time() - 60 60 24 1);$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty($from$totrue)
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Already Bought Today '.(int)$product->ordered_qty
endif;
?>
<?php 
if ((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()==1): ?><p style="color:#990000; padding:5px 0; text-align:right;"><strong>ONLY 1 LEFT IN STOCK!</strong></p><?php endif; ?>

Or if you want to show stock sold on the product page for the entire duration the product has been active, use the following
<?php 

$sku 
nl2br($_product->getSku());$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty()
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Already Bought '.(int)$product->ordered_qty?>

and finally if you want to just just on the page how many have been sold of the product for today, use the following

<?php 
$sku 
nl2br($_product->getSku());$to $_product->getResource()->formatDate(time());$from $_product->getResource()->formatDate(time() - 60 60 24 1);$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty($from$totrue)
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Quantity Ordered Today '.(int)$product->ordered_qty
endif;
?>

Just copy and paste into your view.phtml file, into a suitable place :)

How to resize Image in magento



Here is the custom image resize function. This function will resize image proportionally.




/**
* Resize Image proportionally and return the resized image url
*
* @param string $imageName name of the image file
* @param integer|null $width resize width
* @param integer|null $height resize height
* @param string|null $imagePath directory path of the image present inside media directory
* @return string full url path of the image
*/
public function resizeImage($imageName, $width=NULL, $height=NULL, $imagePath=NULL)
{
$imagePath = str_replace("/", DS, $imagePath);
$imagePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $imageName;

if($width == NULL && $height == NULL) {
$width = 100;
$height = 100;
}
$resizePath = $width . 'x' . $height;
$resizePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $resizePath . DS . $imageName;

if (file_exists($imagePathFull) && !file_exists($resizePathFull)) {
$imageObj = new Varien_Image($imagePathFull);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->resize($width,$height);
$imageObj->save($resizePathFull);
}

$imagePath=str_replace(DS, "/", $imagePath);
return Mage::getBaseUrl("media") . $imagePath . "/" . $resizePath . "/" . $imageName;
}



You can write the following code in template (.phtml) file to display the resized image:


<img src="<?php echo Mage::helper('moduleName')->resizeImage('abc.jpg', 400, 300, 'xyz/image'); ?>" alt="resized image" />