October 25, 2020


Thinking Magento

Magento - Multiple Domains Using a Single SSL

The following is for version 1.3X - See below for changes to work in 1.4x - 1.7

This tutorial assumes you have already successfully setup a multi domain website.

Today we were confronted with a problem that quite literally left us all stumped. How on earth do we get several domains to use the same secure url. Being not so bright we forgot that sessions and cookies are going to be stored for the one url and that if you transfer directly over to the secure url, you're going to be left without a paddle and each time it redirects to an empty shopping cart.


So to combat this you'll need to create a directory in your root directory that has the same name as the url. http://www.store2.com

Example being

httpdocs is your main directory for your magento installation

httpdocs/store2 is going to be where you will place the following.

A copy of  your index.php file with two adjustments. The following needs to be adjusted to look like this;

$mageFilename = '../app/Mage.php';
Mage::run('WEBSITE CODE', 'website');

Also make a copy of your .htaccess file and place that in the folder.

Now go to your web configuration settings.
Switch to website 2.

After switching to website to, on the secure base_link_url and set it to {{secure_base_url}}store2/
(store2 being the directory you created)

Thats it, now everything will correctly go to the secure url.

1.4x - 1.7x

httpdocs is your main directory for your magento installation

httpdocs/store2 is going to be where you will place the following.

A copy of  your index.php AND also the .htaccess file in the root directory

The index.php file in

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'store2';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';

In the WEB configuration of store2 (Use the top left drop down to get there)

Set Use SID's to YES

Set secure base_link_url and set it to {{secure_base_url}}store2/
(store2 being the directory you created)


Now test out to see if adding an item to your cart and pressing checkout will take you to the correct SSL OnePageCheckout

Magento - Change Place Order Button for Paypal Button

It recently occurred to us that people seem to be very confused by the place order button on the one page checkout, when Paypal is selected as prefered payment method. Normally when checking out with paypal you expect a Proceed to Paypal button to avoid any confusion. Magento already sends an order notification email once you press the place order button so anyone in their right mind could think they have struck gold and that the order has already been accepted without paying. So, here is my new solution that will allow you to change the place order button for a proceed to paypal button, if paypal is selected.

For our example I'll be using the paypal standard method.

Firstly open up your template folder and go to Checkout/Onepage/review.phtml and replace your current checkout button with the following.

<span id="paypal-buttons" class="a-center" style="display:none;">
<input type="image" src="/" onclick="review.save();" value="" />
<span id="review-buttons-container" class="a-center" style="display:block;">
<input type="image" src="/" onclick="review.save();" value="" />
Once you've done this, you can then add this javascript to the base of the review.phtml file. This is the trigger for the change in button.
<script language="javascript">
function checkoutbuttons()
if (document.getElementById("p_method_paypal_standard").checked == true) {
document.getElementById("paypal-buttons").style.display = "block";
document.getElementById("review-buttons-container").style.display = "none";
if (document.getElementById("p_method_paypal_standard").checked == false) {
document.getElementById("paypal-buttons").style.display = "none";
document.getElementById("review-buttons-container").style.display = "block";
Finally, you'll need to open up methods.phtml, also in the checkout/onepage folder and replace the onlick function to the following.
 onclick="payment.switchMethod(''); checkoutbuttons()"
Save both the files and you'll be set.

Magento - Show Only Special Priced Products In A Category


So your tired of always having to go through your catalog to add and remove products that have a special price to a certain category called On Sale or something similar. A solution is on hand now that will allow you to filter out those Special Priced products that have a special from and special to date.

First of all this is the code were that we're going to be using to do this.

Mage::getSingleton('core/session', array('name' => 'frontend'));
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow); 
$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left'); 
echo '<div class="listing-type-grid catalog-listing">';
$_collectionSize = $_productCollection->count();
$i=0; foreach($_productCollection as $_product):
echo '<ol class="grid-row">';
echo '<li class="item">';
echo '<p class="product-image">';
echo '<a href="'.$_product->getProductUrl().'" title="'.$this->htmlEscape($this->getImageLabel($_product, 'small_image')).'">';
echo '<img src="'.$this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135);.'" width="135" height="135" alt=".$this->htmlEscape($this->getImageLabel($_product, 'small_image')).'" title="'.$this->htmlEscape($this->getImageLabel($_product, 'small_image')).'" />
echo '<h5><a href="'.$this->getProductUrl().'" title="'.$this->htmlEscape($_product->getName()).'">'.$this->htmlEscape($_product->getName()).'</h5>';
echo $this->getPriceHtml($_product, true) ?>
echo '</li>';
echo '</ol>';
echo '</div>';
You can then paste this into a file and name it specials.phtml and save it into your frontend template folder catalog/product.
Once you've done this you can then go into your admin and go to Manage Categories.
Create a category called On Sale Items or something else that you find fitting for your website. On the tabs click on Custom Design and in the Custom Layout box you can place the following.
<reference name="content">
<remove name="product_list"/>
<remove name="category.products"/>
<block before="-" type="catalog/product" name="home.new" alias="product" template="catalog/product/specials.phtml"> <action method="setProductsCount"><count>9</count></action>
This will remove the current content block and replace it with your specials.phtml content. Press save category and thats it. You will now have a category that will only have your current special priced products.

Magento - Editing phtml Files in Dreamweaver

Its only recently that we came across a post which has now brought me a lot of joy to our lives and made it a lot easier on the eyes. Natively dreamweaver does not recognise phtml files and so you end up living in a black and white world, which is ok except you feel like you've been living in a 1950's sid com for the last few years. However help is finally at hand and now you can finally see phtml files for what they really are and we're going to show you how to achieve the same.

First of all since we're all on PC's, the fix described is only for windows based computers. But if you do need a fix for windows you can find the fix here.

  • Step One

Documents and Settings > [user] > Application Data > Adobe Dreamweaver > Configuration > extensions.txt

Change the top line and add the PHTML


And then change the third line down to look like


  • Step Two

Program Files > Adobe > Dreamweaver [Your Version] > configuration > Extensions.txt

Change the top line and add the PHTML


And then change the third line down to look like


  • Step Three

Program Files > Adobe > Dreamweaver [Your Version] > configuration > DocumentTypes > MMDocumentTypes.xml

Go to line 75 and change it so it looks like below

<documenttype id="PHP_MySQL" servermodel="PHP MySQL" internaltype="Dynamic" winfileextension="php,php3,php4,php5,<strong>phtml</strong>"<br />macfileextension="php,php3,php4,php5,<strong>phtml</strong>" file="Default.php" writebyteordermark="false">; </documenttype><br /><br />Fin.<br /><br />Now you can live in the real world and see all your code in colour.</pre>"

Magento - Using Conditional Attributes For Display

In Magento you have all these great features in terms of adding attributes to your products, but utilising them in a far more constructive way than just "display on product page" is a little bit harder, but worth the learning curve. With some basic php know how you can turn those static stuffy attributes into extremely useful events on the product page. Today we are going to demonstrate a simple, yet effective use of this by showing you how to change an "add to cart" button into a "Pre Order Item" button.

To start with create your attribute in the backend. An example setup would be;

  • Attribute Code: pre-order
  • Scope: Shop View
  • Type: Dropdown
  • Unique Value: No
  • Required: No
  • Validation:None
  • Apply To: All Products
  • Frontend Attributes: All set to no

For the dropdown options

  • Pre Order Available For This Item


Go to Manage Attribute Sets and add pre-order to the various set names.

Now time for the code:

<?php if($_item->isSaleable()): ?>
<?php if ($_product->getData('pre-order')): ?>
getResource()->getAttribute('pre-order')->getFrontend()->getValue($_product); ?>
<?php if ($preorder=="Pre Order Available For This Item"): ?>
<button type="button" class="form-button" onclick="setLocation('getAddToCartUrl($_product) ?>')"><span>__('Pre Order Item') ?>

<button type="button" class="form-button" onclick="setLocation('getAddToCartUrl($_product) ?>')"><span>__('Add To Cart') ?>

<button type="button" class="form-button" onclick="setLocation('getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add To Cart') ?></span></button>
<?php endif; ?>
<?php endif; ?>

This code can now be used to replace the current add to cart button, from the if saleable statement on both the list.phtml and the view.phtml files in the frontend catalog template folder.