October 25, 2020

cm-mini

Thinking Magento

Magento - Prevent Tier / Special Priced Products Discounted By Sales Rules

So, we've all been here and we've all come to the same conclusion so far.

Within the sales rules you need to specify the products that have a special price should be ignored. This is all well and good until the sale item is no longer on sale and the special price still exists on the product.

Specifying Special From and To Dates, would be the obvious answer, however these dates are fixed, rather than being able to specify todays date.

So, we've updated the SalesRule_Validator to compare the price of the product in the cart, to the original product price.

This will work for products including tax and products excl tax rates.

Download the file and upload it to your server. No more fiddling with Sales Rules.

Download Here

As per usual, always test this on a backup server. This particular Validator.php file is from 1.7x

Magento Paypal Error - Rounding & Discount Issue

Error: Transaction refused because of an invalid argument. See additional error messages for details. The totals of the cart item amounts do not match order amounts.

This error seems to affect most tax inclusive installations and if you start seeing it in your payment_paypal_express.log then hopefully we will be able to supply you with a solution.

The problem lies with rounding, especially if you are using percentage based discounts, but also if prices end in 9,7,3.

To combat this we have attached a new NVP.php file for Magento 1.7x. You can look into the file and search for the Hack lines to import them over into your Magento installation.

Download File

Let us know if it improved your situation or if you think that you can improve on it further.

Original source of code: http://stackoverflow.com/questions/11868985/magento-paypal-tax-rounding-issue

Magento - 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="" />

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.

$_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;

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());
 $product = Mage::getResourceModel('reports/product_collection')
 ->addOrderedQty()
 ->addAttributeToFilter('sku', $sku)
->setOrder('ordered_qty', 'desc')
->getFirstItem();

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);
$product = Mage::getResourceModel('reports/product_collection')
->addOrderedQty($from, $to, true)
->addAttributeToFilter('sku', $sku)
->setOrder('ordered_qty', 'desc')
->getFirstItem();
echo 'Quantity Ordered Today '.(int)$product->ordered_qty; ?>

Just copy and paste into your view.phtml file, into a suitable place :)