creative-mountains

The Creative Media Group Magento Blog

The MetaDescription

Many have claimed that they have the ultimate metadescription patch for Magento and as far as I'm concerned. Many have tried and many have failed.

For me the following is what made successful use of the metadescription.

<?php $content = htmlspecialchars($this->getDescription());
$content = str_replace("\n",'',$content);
$content = str_replace("\r",'',$content);
$content = preg_replace('/([\s]{2,})/',' ',$content);
$content = substr($content,0,250);
?>
<meta name="description" content="<?php echo $content ?>" />

Feel free to update your head.phtml file with it and see if it makes a difference for you.

   

Showing Percentage Saved On Product Page - Magento

So something that isn't included on the frontend of Magento. You Saved xx%. So, here's a little something you can copy and paste into your view.phtml

 

<?php
$_finalPrice
= $this->helper('tax')->getPrice($_product, $_product->getFinalPrice());
$_regularPrice = $this->helper('tax')->getPrice($_product, $_product->getPrice());
if (
$_regularPrice != $_finalPrice):
$getpercentage = number_format($_finalPrice / $_regularPrice * 100, 2);
$finalpercentage = 100 - $getpercentage;

echo
'<div class"savingbox">YOU SAVE '.number_format($finalpercentage, 0).'% </div>' ;

endif;
?>
   

Show Quantity Sold On Product Page - 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, $to, true)
->
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, $to, true)
->
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 :)
   

Magento - Multiple Domains Using a Single SSL

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';

and at the base of the index.php file place the following (replacing WEBSITE CODE, with the one you configured in the admin)

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. 

   

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="<?php echo $this->getSkinUrl('images/btn_paypal_checkout.gif') ?>" onclick="review.save();" value="<?php echo $this->__('Continue to Paypal') ?>" />
</
span>
<
span id="review-buttons-container" class="a-center" style="display:block;">
<
input type="image" src="<?php echo $this->getSkinUrl('images/btn_place_order.gif') ?>" onclick="review.save();" value="<?php echo $this->__('Place Order') ?>" />
</
span>

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";
}
}
</script>

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('<?php echo $_code ?>'); checkoutbuttons()"

Save both the files and you'll be set.
   

Page 1 of 4

creative-trees