Get Image Path For Product Page in magento

Sunday, 30. October 2011

A nice simple script for getting an image path for product image in Magento’s product page

$_imageUrl = $this->helper('catalog/image')->init($_product, 'image');	
echo str_replace("http://".$_SERVER['SERVER_NAME']."/",$_SERVER{'DOCUMENT_ROOT'},$_imageUrl);

Add Review List and Review Form on Magento Product Page Tab

Sunday, 30. October 2011

If you want to add customer reviews on product page tab these steps may help you.

Locate and open your theme’s catalog.xml file

– On the file look/search for: catalog_product_view

– Look for the content enclosed within

<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">

– Add your review form and list as shown below.

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
  <block type="review/form" name="product.review.form" as="review_form"/>			                               
  <action method="addTab" translate="title" module="review">
	   <alias>product_additional_data</alias>
	   <title>Reviews</title>
	   <block>review/product_view_list</block>
	   <template>review/product/view/list.phtml</template>
  </action>	                 
</block>

– Your final result should look something like this.

<reference name="content">
  ...
  <block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
    <block type="review/form" name="product.review.form" as="review_form"/>			                               
    <action method="addTab" translate="title" module="review">
	   <alias>product_additional_data</alias>
	   <title>Reviews</title>
	   <block>review/product_view_list</block>
	   <template>review/product/view/list.phtml</template>
    </action>	                 
  </block>    
  ...
</reference>

– Finally you will need to make these changes to the review list template file.

Look for and open file review/product/view/list.phtml

On this file and near the bottom of it, look for and comment out this line

#echo $this->getChildHtml('review_form')

Then, add this line underneath

$layout = Mage::getSingleton('core/layout');
echo $layout->getBlock('content')->getChild('product.info')->getChild('info_tabs')->getChild('review_form')->toHtml();

Disable suhosin on the server using php.ini or .htaccess files

Sunday, 30. October 2011

If you ever wanted to disable certain Suhosin settings at a domain level, these 2 methods may be of help to you

Disable suhosin Using php.ini file

1) Login to the server as root and copy php.ini file to the root folder of the domain in question. Usually, this command should work for you.

[[email protected]]# cp /usr/local/lib/php.ini /home/<username>/public_html

2) Open the php.ini file and add the following code to the file:

[suhosin]
; Misc Options
suhosin.simulation = On
#On = Disabled, Off  = Enabled

3) Save and quit the file. Restart apache.

Disable suhosin Using .htaccess file

1) Locate and open the .htaccess file of the domain in question – possibly via FTP or CMD.

2) Now enter the following code in the file.

php_flag suhosin.simulation On

NOTE:
If suphp is in action on the server, you may also need to add this to your .htaccess.

<Files ".ht*">
deny from all
</Files>
suPHP_ConfigPath /home/username

4) Save and quit the file. Restart apache.

Can’t connect to local MySQL server through socket – Ubuntu xampp and MySql

Sunday, 30. October 2011

If you have come across this problem while connect to MySQL (possibly via command line tool) this solution may work for you. Th issue is mainly because the script is looking for a file – mysqld.sock – in order to be able to connect as localhost but in the wrong location.

MySQL Conenction Error

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Solution
On your terminal run the following two commands

sudo mkdir /var/run/mysqld/

Next run this

sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock

Now try again to connect to MySql using your configured MySQL username and password

mysql -u[username] -p[password]

Use Curl With Magento and Zend Framework

Tuesday, 25. October 2011

Just a little snippet of curl implementation inside Magento for anyone interested.

try {
 
  $http = new Varien_Http_Adapter_Curl();
  $config = array('timeout' => 30); # Or whatever you like!

  ## You attach proxy with your custom implementation like this::
  if ($this->getUseProxy()) {
    $config['proxy'] = $this->getProxyHost(). ':' . $this->getProxyPort();
  }
 
  ## You can add ssl certificate with your custom implementation like this::
  if ($this->getUseCertAuthentication()) {
    $config['ssl_cert'] = $this->getApiCertificate();
  }
  $http->setConfig($config);
 
  ## make a POST call
  $http->write(Zend_Http_Client::POST, $this->getApiUrl(), '1.1', array(), $requestQuery);
 
  ## Get Response
  $response = $http->read();
 
} catch (Exception $e) {
 
  $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
  $this->_debug($debugData);
  throw $e;
}
 
# Close Call
$http->close();

Run Raw SQL statement with Magento Core resource

Monday, 24. October 2011

There are times when you just want to run a simple SQL statement to quickly test things up on Magento without having to load up the entire collection.

On servers with limited resources this can be handy. Also, for someone like me sometimes I find life much easier working directly on the database (as LONG as you KNOW what you are doing! This approach in Magento can easily be your own UNDOING!)

Get the core resource

$_resource = Mage::getSingleton('core/resource');

Get the correct Database name

Because some installations may have table prefixes, this is the best way to make sure you get the correct table name with prefix (if one exists)

$_tableName = $_resource->getTableName('catalogsearch_query');

Start Magento Database Connection

Once everything is in place and you are ready to go, here is how you obtain DB connection

$_conn = $_resource->getConnection('core_write'); #you can also use 'core_read' for just reading data
# example
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');

Read Data From Magento Database

$sql = "SELECT * FROM directory_country_region WHERE country_id='UK'";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
foreach ($connection->fetchAll($sql) as $arr_row) {
	print $arr_row['default_name'];
}

Insert Data Into Magento Database Directly

// insert a new US State into the region table
$sql = "INSERT INTO `directory_country_region` (`region_id`,`country_id`,`code`,`default_name`) VALUES (NULL,'US','XX','New US State')";
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$connection->query($sql);

Enjoy!

PHP – Magento Jobs At Zone-Connect Leeds UK

Friday, 21. October 2011

– Are you excellent with PHP?

– Do you have any experience in E-Commerce and/or Magento platform?

– Do you enjoy working with PHP and other Web Development technologies, platforms or frameworks currently available?

– Are you looking for a job that will challenge you every day but also provide you with an opportunity to be creative?

– Can you work on your own, good at making decisions and quick at finding solutions when you hit the wall?

– Are you based in Leeds (or close range) area in UK?

– Are you looking for decent rewards for your hard work?

– Can you work for at least 3 days a week?

If you feel like you have the answers for these questions, please get in touch with us today.

Magento showing ‘special price’ even though no rule is active

Thursday, 20. October 2011

I have had a strange issue today on Magento 1.4.0.1 – all products were showing a Special Price even though all catalogprice rules were inactive and there was no special prices set for any of the products!

Even after deleting all the rules there completely, the special price never went away.

After a bit of digging I realized the table catalogrule_product_price on the database still had rows and rows of data even though there was no rules on the system.

So I did what you might have guessed – backed the table up and trancate all row!

Back to the site and WOOP WOOOP, special prices were all gone! Completely GONE!

Happy day at the office in the end and hope this may help you.

PS:
I don’t see to find this to be an issue on later versions but certainly on older ones prior to 1.5. However, I will not hesitate to do the same should I encounter the same problem on 1.6!

CONTINUE button Not working While PayPall Credit Card selected

Wednesday, 19. October 2011

If you are processing credit cards via paypal and for some reasons the continue button doesn’t seem to be working on the checkuot payment process, this may be the reason.

Open the page.xml file for your theme

Check to ensure this file exists and if not, add this line after the list of Javascript files added.

<action method="addJs"><script>lib/ccard.js</script></action>

why prices not showing on product page for simple products magento?

Thursday, 13. October 2011

Why is my prices not showing up on product pages for Magento simple products??

If you have asked yourself that question preciously this maybe a solution for you. More than often this is a theme configuration related issue and especially if you are using a custom theme based on the default theme or default theme itself (which is BAD!)

To fix this, you will need to look for the Layout folder on your custom theme and locate the catalog.xml file.

– Look for a line similar to this one (I would search for product.info.simple)

<block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/simple.phtml">

– Replace it with this line:

<block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml">

– Refresh your cache and jobs a gooder again!