1. Home
  2. Prices
  3. Guided Tour
  4. New Shop
  5. Shop Review
  6. Ecommerce Marketing
  7. Ecommerce TV
  8. Magento Developers
  9. Portfolio
  10. Blog
  11. Contact

Magento Tutorials

Archive for the ‘Magento Tutorials’ Category

Create a Magento Holding Page

Posted on: 3rd Sep 2010 By: Adam Moss No Comments

If you’re working on a new website, it’s perfectly understandable that either your or the client will want to prevent people from seeing it until it is completely finished. This applies even more to ecommerce websites where people may try to buy something from a store which isn’t ready. The answer is to make yourself a holding page, something which is easier said than done in Magento as any modifications to the index.php file will cause the entire site to not work.

So how do you create a holding page while still being able to work on the entire shop? Easy…

1. Create a new file on your root layer to act as the holding page. Design it however you like, I’m going to keep it simple and call it ‘hold.php‘ with the following appearance. You may think of something more exciting such as “OMG New Website Coming Soon!”

Website Under Construction

2. With that file uploaded, it’s now a simple case of updating the .htaccess file. Open Magento’s long and lucrative .htaccess and find the line which defines the directory index:

DirectoryIndex index.php

…and simply change to:

DirectoryIndex hold.php

Now when you visit your website at it’s root address (www.domain.com) you will see the holding page rather than the Magento. To see your developing site simply go to www.domain.com/home

One thing I should mention: Using this method breaks Magento Connect – disable to use this service

Thanks for reading the Magento Blog at Ecommerce Web Design.

Categories: Magento Tutorials Tags:

Magento URL Rewrites on a Windows Server

Posted on: 25th Aug 2010 By: Luci Smethurst No Comments

For the record, I don’t recommend running Magento on a Windows server – I have nothing against IIS, but Magento was really built for Linux servers. Things like URL rewrites become needlessly difficult when they could be as simple as changing a dropdown box in the backend to “Yes”…

However, if you or a client is running Magento on a Windows server – and there is no option to transfer to Linux – and you would like to get your URL rewrites working, would like to set the default page to index.php, remove index.php from URLs and get the site redirecting from non-www to www and from index.php to the root then todays post on the Magento blog is for you!

First – and this is required – you must get in contact with whoever is looking after of your server. You need to have a URL Rewrite Module like Helicon installed.

Next is your web.config file – it works similar to a .htaccess, except that a Magento website on a Windows server will definitly listen to it.

  1. Create a new file in your favourite text/html editor. Anything from Notepad to Dreamweaver will do.
  2. Save your file as web.config.
  3. Enter the code below:
<configuration>

<system.webServer>

<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>

<rewrite>
<rules>
<rule name="Redirect domain.co.uk to www.domain.co.uk" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.co.uk" />
</conditions>
<action type="Redirect" url="http://www.domain.co.uk/{R:0}" />
</rule>

<rule name="redirect to root">
<match url="^index\.php$" ignoreCase="false" />
<conditions>
<add input="{QUERY_STRING}" pattern="^$" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.domain.co.uk/" />
</rule>

<rule name="Remove index.php from URLs" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions>
<add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>

</system.webServer>

</configuration>

Now, I’ll try and explain everything you can see here – it looks a feels a lot like XML. To begin with you open up configuration and system.webServer tag’s, which tells a Windows server that you’re editing the configuration, and the the latter applies specifically to IIS7.

<defaultDocument>

The defaultDocument specifies the default page to load should no page be specified. In this case index.php will load.

<rewrite>, <rules>

The rewrite and rules elements are quite self explanatory – all child single rules within this are related to rewriting URLs.

Non-www to www

You can name each of your rules to make the code more user friendly by using the name=”" area, and then again patternSyntax and stopProcessing are self explanatory. Having an asterisk withing the <match url=”"> catches all the URLs and then <conditions> specifies the conditions of the rule – ie the domain you want it to apply to.

<action> then specifies what you want to happen next – in this case “Redirect” under type=”" and your domain (with www.) in url=”". You can also specify a redirectType – I’ve chosen Permanent here.

Redirect to Root (remove index.php)

<match> URL here should be set to the default file name that you would like removing – in Magento’s case this would be index.php. For example if users navigate to www.domain.co.uk/index.php, with this rule in place they would automatically redirect to www.domain.co.uk. Again you set <conditions> and then an <action> – again a Permanent Redirect and the destination URL.

Remove index.php from URLs

A common problem when you turn on URL rewrites in Magento that’s running on a Windows server is that your URL rewrites happen – but the links are broken. A little annoying. This rule fixes this issue!

<match> should be set to all URLs after “.” and then <conditions> sets what you want it to apply to. <action type=”"> is this time set to Rewrite (rather than redirect – that’s already happening) and the url should be set to index.php.

Then hey presto! A working Magento site (hopefully) – URL writes and all, which is a must really if you are interested in magento seo. Thanks for visiting our blog at ecommerce web design!

Create a Customised Magento Search Form

Posted on: 24th Aug 2010 By: Adam Moss No Comments

The Magento software is okay for searches… It has the main basic search form, which can be used to search for keywords in pretty much every attribute that a product has attached to it. Then you have the advanced search form, allowing you to pick and choose which attribute values should be searched for. Attributes in this search form again can be user defined completely. So then I hear you cry, why would I want to create my own search form?

The situation arose when a client I was working for required a search form which did a calculation based on the numeral values entered, then compared this data against attributes in the product catalog to bring back the correct results. Although writing your own code into the Magento framework can sometimes be as painful as trying free yourself from the jaws of a crocodile, the solution came to me quite quickly and easily. As the code I used was quite long and complicated, here’s the simple version.

1. I made a file called ‘quote-results.phtml’, which is then echoes on a CMS page to show the results – I called mine ‘quote-results’…. I know, creative stuff right?

2. I created a search form which would sit on the homepage, I called this file ‘quote-form.phtml’. This echoed out on the homepage CMS page. Simple.

OK, this is what it’s gonna do – told you it was simplified. The client enters a width & a height into the search form.The products hypothetically have an attribute called ‘Max Length’. Which ever is bigger, it will use this figure and bring back only the products with a greater max length than what was calculated by the search form. Practically, this would probably never be useful code, but once you have the groundwork in place you can construct entire buildings! Before I drown everyone in a succession of David Brent-style metaphors, here’s my search form code:

<form action="/quote-results" method="post">
<label for="height"> <span>Height (cm): </span>
<input name="height" type="text" />
<label for="width"> <span>Width (cm): </span>
<input name="width" type="text" />
</label>
<button type="submit" name="quotesubmit">Submit</button>

Now that we can post the data to the quote results page where, the results will be generated by this bit of code (obviously this has no style to it):

<h1>Your Details</h1>

if (isset($_POST['width'])) { $width = $_POST['width']; }
if (isset($_POST['height'])) { $height = $_POST['height']; }
if (isset($_POST['quotesubmit'])) { $quotesubmit = $_POST['quotesubmit']; }

$postlength = 0;
if ($height > $width) { $postlength = $height; } else { $postlength = $width; }

if (isset($quotesubmit)) {

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$readresult = $write->query("SELECT DISTINCT product_id FROM catalog_category_product ORDER BY product_id");
while ($row = $readresult->fetch() ) {
$prodid = explode(" ", $row['product_id']);
foreach ($prodid as $id) {
$_product = new Mage_Catalog_Model_Product();
$_product->load($id);
$maxlength = $_product->getAttributeText('maxlength');

if ($postlength >= $maxlength) { ?>

<p><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_product->getName(); ?>"><?php echo $_product->getName(); ?></a> - <span>&pound;<?php echo number_format(round($_product->getPrice(), 2), 2) ?><span></p>
<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('/checkout/cart/add/product/<?php echo $_product->getId(); ?>/')">Add to Cart</button></p>
<?php else: ?>
<p><span><?php echo $this->__('Not Available') ?></span></p>
<?php endif; ?>
<?php } } ?>

That’s all there is to it. By using the Mage_Catalog_Model_Product(); script, we can load the product catalog from anywhere and have access to this data anywhere. Thanks for reading the Magento Blog at Ecommerce Web Design – look out for our new design in the next few weeks!

Categories: Magento Tutorials Tags:

Get Lowest Tier Price

Posted on: 18th Aug 2010 By: Robert Kent 6 Comments

A few weeks ago we were scratching our heads in confusion on how to get the lowest tier-price from magento. If you take a look at your catalog>product>view>tierprices.phtml you will see why – why does such a complicated section of code even exist?

Anyway after a few failed attempts we were contacted this morning by Christiaan who asked us this question a few weeks ago on the magento forums. We took this as a challenge and set to work this very morning sorting it out.

After a few black coffees we finally figured it out…or at least got rid of the rubbish that was concealing it. We now have a little method to bring back the lowest tier price on a magento product view page!

Here is how you do it:
1. Create a file in your product>view folder called getlowest.phtml
Copy & paste the following into it:

<?php
/**
* @E-Commercewebdesign.co.uk
*/
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

$_weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($_product);
if (Mage::helper('weee')->typeOfDisplay($_product, array(1,2,4))) {
$_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product);
}

?>
<?php if (count($_tierPrices) > 0): ?>
<?php if ($this->getInGrouped()): ?>
<?php $_tierPrices = $this->getTierPrices($_product); ?>
<?php endif; ?>
<?php Mage::helper('weee')->processTierPrices($_product, $_tierPrices); ?>
<?php $i = 0; ?>
<?php $_tierPrices = array_reverse($_tierPrices); ?>
<?php foreach ($_tierPrices as $_price): ?>
<?php if($i==0){ ?>
<p style="font-weight:bold; font-size: 1em;">After tier pricing the lowest price you can have a Cowboy Hat is...
<span style="font-size:150%; text-decoration:underline;">
<?php echo $_price['formated_price']; ?>
</span>
<p>
<?php $i++; ?>
<?php } ?>
<?php endforeach ?>
<?php endif;?>

As you can see you can edit some words above to output whatever you like around this lowest price – could be on top of an image or simply surrounded by text like above.

2. Open your themes catalog.xml and paste in the following code:

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

3. Call this function on your product>view.phtml

<?php echo $this->getChildHtml('getlowest') ?>

There you have it! This code will output the lowest price of your tier prices dynamically – and will also not show anything if tier-prices are not activated for the product.

Thanks for visiting our magento blog at ecommerce website design – home of the (newly styled!) magneto fox. Take Care.

Product Images Not Showing After Import

Posted on: 17th Aug 2010 By: Luci Smethurst No Comments

If you’ve tried to import images into magento at the same time as your products using the ‘Import Products’ profile, you may have come across a few errors. Whilst trying to import multiple products sing Magento’s ‘Import Products’ profile, I recently ran into one problem after another – though the products imported just fine, my images were either mysteriously absent, or mysteriously broken.

One of the initial problems is that the export profile puts a path in front of the image names, which is incorrect for new products. So if you’re importing products from another store, you’ll need to edit the image paths first. Exported products with images, when exported, with have image paths like this:

/i/m/imagefile01.gif

However, when importing multiple products with images, the csv needs to be directed to the media/import folder – this can be done with a simple, single forward slash:

/imagefile01.gif

Now, make sure all the product images you want to import are uploaded to: media/import and that the file permissions are set to 757 for the media directory & all files/subdirectories.

The next issue I had was that, even when the filepaths were correct, all of the image links were broken and set to ‘Exclude’. To fix this and get your image import working, simply do the following:

Create a local copy of:

app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php

Find

foreach ($imageData as $file => $fields) {
try {
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields);
}
catch (Exception $e) {}

and replace with

foreach ($imageData as $file => $fields) {
try {
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields,
true,         /* defaults to false - tells Magento whether to move the file or not */
false);         /* defaults to true - tells Magento whether to exlclude the file or not */
}
catch (Exception $e) {}

I hope this helps you with your importing product images issues – thanks for reading our Magento blog at Ecommerce web design!