Monday 26 October 2015

Display associated posts on a Magento Product page

<?php echo $this->getLayout()
        ->createBlock('wordpress/post_associated')
            ->setTemplate("wordpress/post/associated.phtml")
            ->setTitle('Related Blog Posts')
            ->setEntity('product')
            ->setCount(5)
            ->toHtml() ?>
 Display associated products on a blog post page

                        <?php echo $this->getLayout()
    ->createBlock('wordpress/post_associated_products')
        ->setTemplate('wordpress/post/associated/products.phtml')
        ->setTitle('Related Products')
        ->toHtml() ?>

Monday 19 October 2015

How to remove white space around the product image in Magento

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize(270,396); ?>" width="270" height="396"  />

Thursday 15 October 2015

Magento Log file created custom page

                $customererror='';               
                try {
                            $address->save();
                            $customer->save();
                        }                           
                         catch (Exception $ex) {
                            $customererror=$ex->getMessage();
                           
                            Mage::log($customererror,null,'customer.log');   
                        }

Monday 12 October 2015

Reading a file line by line in php

<?php
$handle = fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>

Monday 5 October 2015

Facebook image sharing

<meta property="og:title" content="<?php echo $Brand?>"/>
<meta property="og:image" content="<?php echo $imgurl.'?ts='.time();?>"/>
<meta property="og:image:secure_url" content="<?php echo $imgurl.'?ts='.time();?>"/>
<meta property="og:url" content="<?php echo $curUrl?>" />
<meta property="og:description" content="<?php echo $ProName?>"/>

================OR========================
<?php $product = Mage::registry('current_product');
if ($product): ?>
<meta property="og:title" content="<?php echo $product->getName(); ?>" />
<meta property="og:type" content="product" />
<meta property="og:url" content="<?php echo $this->helper('catalog/product')->getProductUrl($product); ?>" />
<meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(300, 300); ?>" />
<meta property="og:description" content="<?php echo strip_tags($product->getShortDescription()); ?>" />
<meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName() ?>" />
<?php endif; ?>
================OR=========================
<?php /* Open Graph Protocol for Facebook and SEO START */ ?>
<?php if(Mage::registry('current_product')): ?>
 <?php $product = Mage::registry('current_product'); ?>
 <meta property="og:title" content="<?php echo ($product->getName()); ?>" />
 <meta property="og:type" content="product" />
 <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(200,200);?>" />
 <meta property="og:url" content="<?php echo Mage::registry('product')->getProductUrl(); ?>" />
 <meta property="og:description" content="<?php echo strip_tags(($product->getShortDescription())); ?>" />
 <meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName(); ?>" />
<?php elseif(Mage::registry('current_category')): ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="product.group" />
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
 <meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName(); ?>" />
<?php elseif((Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&
 Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')) : ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="website" />
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
 <meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName(); ?>" />
<?php else: ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="article" />
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
 <meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName(); ?>" />
<?php endif; ?>
<?php /* Open Graph Protocol for Facebook and SEO END */ ?>