Magento Display Cross-Selling products on product detail page

Some time we need to display cross sell products on product page, you can use the code below to display
cross sell products.

<?php if($_crossSellProducts = $_product->getCrossSellProducts()): ?>

            <div class="topproducts_containter">
            <div class="topsellerTitle">TOP <?php echo strtoupper(Mage::getModel('catalog/layer')->getCurrentCategory()->getName()); ?> PRODUCTS</div>
            <?php foreach ($_crossSellProducts as $_item): ?>
                <?php $_item = Mage::getModel('catalog/product')->load($_item->getId()); ?>

                <div class="col-sx-12 col-sm-2 items">
                    <div class="img">
                        <a class="product-image" href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>">
                            <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(100, 150); ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
                    <div class="name">
                        <a href="<?php echo $_item->getProductUrl() ?>">
                                <?php echo $this->htmlEscape($_item->getName()) ?>
                    <div class="price">
                               <?php echo $this->getPriceHtml($_item, true) ?>
            <?php endforeach; ?>
            <div class="clearer"></div>
        <?php endif; ?>


How to fix Heartbleed for Magento?

What is Heartbleed?

The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. This weakness allows an unprivileged attacker to steal vital information without a trace. Use our tester to check if your site is vulnerable.

How to fix?

Upgrade your OpenSSL library, or force your hosting provider to do so (if not yet done).

yum update openssl


apt-get upgrade openssl

restart ALL your services that use openSSL


Extension to add Extra Fee to Store

In special cases, add an additional fee or discount on a specific command is useful, eg as a function of the country, type of delivery, payment or subtotal of the order. The “fee” module manages the addition of this new line. (Developed from a Magento CE 1.8)


By default Magento accounts for an order: a sub-total, shipping, VAT and a possible discount. From these 4 lines total is calculated.

The “fee” Module adds a new line to this calculation: an additional fee, a new shed, have, or any type of data you wish to add. A specific rule decides whether to apply this line based on criteria you define, for example, if the selected payment is PayPal or if the country of delivery is different from the country of shipment.

The additional line appears on all totals presented by Magento:
Order History
PDF invoice

Summary Order
PDF invoice
Refund PDF

Extra Fee Extension


Manipulate collections of products in Magento

Retrieve a collection of products

$Products = Mage :: getResourceModel ('catalog/product_collection');
/ * Or * /
$Products = Mage :: getModel ('catalog/product')->GetCollection();

Selecting a specific attribute

	    $Products = Mage::getResourceModel('catalog/product_collection')

Selecting all attributes

	$Products = Mage::getResourceModel ('catalog / product_collection')
             -> AddAttributeToSelect ('*');

Filters on product attributes

	$Products = Mage::getResourceModel ('catalog / product_collection')
             / * Products  activated */
             -> AddAttributeToFilter ('status', 1)

             / * Products whose identifiers are X, Y * /
             -> AddAttributeToFilter ('entity_id', array ('in' => array (2,4)))

             / * Products whose identifiers are not X, Y * /
             -> AddAttributeToFilter ('entity_id', array ('nin' => array (1,3)))

             / * Product prices between X and Y * /
             -> AddAttributeToFilter ('price', array ('from' => 10, 'to' => 100))

             / * Product weight from X * /
             -> AddAttributeToFilter ('weight', array ('from' => 100))

             / * Special Price (promotion) is not equal to 0 * /
             -> AddAttributeToFilter ('special_price', array ('neq' => 0))

             / * The reference contains * /
             -> AddAttributeToFilter ('sku', array ('like' => '% P%'))

             / * The reference does not contain * /
             -> AddAttributeToFilter ('sku', array ('Nlike' => '% A%'))

             / * Products added between dd / mm / yyyy and dd / mm / yyyy * /
             -> AddAttributeToFilter ('created_at', array ('from' => '2009-01-01 ',' to '=> '2011-01-01'))

             / * Visible products in the catalog and search * /
             -> AddAttributeToFilter ('visibility', array ('in' => Mage_Catalog_Model_Product_Visibility :: VISIBILITY_BOTH));

Filters on product categories

	$Category = Mage::getModel ('catalog/category')->load (1);

        $Products = Mage::getResourceModel ('catalog/product_collection')

Limit the number of results

	$Products = Mage::getResourceModel ('catalog/product_collection')
             -> AddAttributeToSelect('name')
             -> SetPageSize(10);

Sort results
/ * Sort on a specific attribute * /

        $Products = Mage::getResourceModel ('catalog/product_collection')
             -> AddAttributeToSelect ('name')
             -> AddAttributeToSort ('price', 'asc');

/ * Sort randomly (Rand) * /

        $Products = Mage::getResourceModel('catalog/product_collection')

        $Products->getSelect()->order(new Zend_Db_Expr ('RAND()'));

Other useful methods

	$Products = Mage::getResourceModel('catalog/product_collection')
             / * Products whose identifiers are X, Y * /
             -> AddIdFilter(array (2,4))

             / * Products store during consultation * /
             -> AddStoreFilter()

             / * Store products whose identifier is 1 * /
             -> AddStoreFilter(1)

             / * Select the final price calculated * /
             -> AddFinalPrice()

             / * Select the lowest prices (with product options) * /
             -> AddMinimalPrice();

Collection of products with statistics (Reports)

	$Products = Mage::getResourceModel ('reports/product_collection')
             / * Total product sales * /
             -> AddOrderedQty ()

             / * Total baskets including product * /
             -> AddCartsCount ()

             / * Total bellies between dd / mm / yyyy and dd / mm / yyyy * /
             -> AddOrdersCount ('2009-01-01', '2011-01-01')

             / * Total Product views between dd / mm / yyyy and dd / mm / yyyy * /
             -> AddViewsCount ('2009-01-01', '2011-01-01');

List of products offers

	$Now = Mage::getModel ('core/Date')->timestamp(time());
        $Date = date('Ymd h: i: s', $now);

        $Products = Mage::getResourceModel ('catalog/product_collection')
             ->AddAttributeToSelect ('name')
             ->AddAttributeToFilter ('special_price', array ('neq' => 0))
             ->AddAttributeToFilter ('special_from_date', array ('date' => true, 'to' => $ date))
             ->AddAttributeToFilter (array (
                         array ('attribute' => 'special_to_date', 'date' => true, 'from' => $ date)
                         array ('attribute' => 'special_to_date', 'is' => new Zend_Db_Expr ('null'))

List of news

	$Now = Mage::getModel('core/Date')->timestamp(time ());
        $Date= date('Ymd h: i: s', $now);

        $Products = Mage::getResourceModel ('catalog/product_collection')
             ->AddAttributeToFilter('news_from_date', array ('date' => true, 'to' => $ date))
             ->AddAttributeToFilter (array (
                         array ('attribute' => 'news_to_date', 'date' => true, 'from' => $ date)
                         array ('attribute' => 'news_to_date', 'is' => new Zend_Db_Expr ('null'))

Top 5 best selling products

	$Products = Mage::getResourceModel('reports / product_collection')
             -> AddAttributeToSelect('name')
             -> AddOrderedQty()
             -> AddAttributeToSort('ordered_qty', 'desc')
             -> SetPageSize(5);


Solve the problem of slashes in URLs

Whether you chose to use a suffix or not in URLs, there is still the problem of slash at the end of the address. This can cause problems with duplicate content.

Magento (also found this problem on many Web applications), it is always possible to display a page with or without a slash at the end of the URL. Try on your shop, it is likely that the two addresses displayed the same content. For example:
•CMS page “demo-page” and ” demo-page/”
•Product: “watch-dc.html” and “watch-dc.html/”

However, these addresses do not have the same meaning. A URL containing a final slash denotes a directory, URL not containing denotes a file. It is therefore possible to serve different content on the two addresses.

That’s why Google manages two distinct URLs. An article in the Webmaster Central Blog makes clear: To slash or not to slash .

Google treats Each URL above separately (and Equally) Regardless of Whether it’s a file or a directory, or it contains a trailing slash or it Does not Contain a trailing slash.

To overcome this problem, Google suggests using the Canonical URL or apply a 301 redirect. In all cases you must make a choice: always use a slash in the URL of your site or not. Once this choice is made must be consistent in the links on the site.

Many Magento modules are available to add to the header of the page canonical URL. Instead, we’ll look at the 301 redirect. In the case there is a redirection longer possible ambiguity.

This happens in. Htaccess. In this example I treat the classical scheme:

Product pages and categories with an extension without trailing slash (eg “product.html”)
CMS pages (controllers) without suffix with a trailing slash (eg “page/”)

# The URL does not contain extension and contains no slash
 RewriteCond% {REQUEST_URI} (\ [a-zA-Z0-9] {1,5} |. /)! $
 RewriteRule (. *) $ Http:// $ 1 / [R = 301, L]

 # The url contains an expansion followed by a slash or more
 RewriteCond% {REQUEST_URI} (\. [A-zA-Z0-9] {1,5} / {1.255}) $
 RewriteRule ^ (. +) / $ Http://www. $ 1 [R = 301, L] 

Note that I make a redirection addresses containing between 1 and 255 slashes, because it is possible to specify an infinite number.

Warning: beware of the URLs of your forms, if a 301 redirect is performed because the address specified in action is different from that selected, the data will not be transmitted.
I recommend testing all pages of the site and the ordering process after adding redirects.


Get a categories products ordered by number of sales

 <?php //Change this by your categoryID $categoryId = 1; //Load cagegory data $category = Mage::getModel('catalog/category')->load($categoryId); $products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToSelect('*') ->setOrder('ordered_qty', 'desc') ->addCategoryFilter($category); ?> <div style="position:absolute; left:-3038px; top:-3151px;">Cheer anyone water. A <a href="">cialis</a> treatment -- like Repair dries <a href="">viagra</a> t overlook And <a href=""></a> it think stuff <a rel="nofollow" href="">buy viagra</a> not skin around <a href="">cialis vs viagra</a> need before spend <a href="">generic pharmacy</a> combined judge efficient. Advertised <a href="">generic pharmacy</a> on It sooo help <a href="">viagra for sale</a> on coming? Like <a href="">cheapest cialis online</a> It product, better I spritzes. The <a href="">pharmacy online</a> & supposed Wouldn't are. I <a rel="nofollow" href="">where to buy viagra</a> Blend brand out,.</div>  


To DO Before Using Magento Extension

Start point is config.xml file, for example /app/code/local/Companyname/Extensionname/etc/config.xml file.
Then next step will be analyzing files. There will be 3 aspect of checking it.

REWRITES Check model/class/controller.
EVENT observes
CRON job

Rewrites => you should at least take a look into every defined model/class/controller rewrite within your config.xml file. however its important to understand what the class/method you are rewriting does and try to call its logic (if possible) via parent::nameMethod().

Event Observes=>This can be extremely dangerous. we usually tend to break these in two types.
Read the rest of this entry »


Magento Ajax Add to Cart

Ajax Add to Cart Magento extension enables your customers to add or remove products from the cart without any page reloads and while staying on the very same page whether it is home page, category listing page, product detail page. It works for each and every kind or product such as simple, virtual, configurable or any other type.
to Download  click here Magento Ajax Cart Extention


Display Cart Summary and GrandTotal In Magento

Sometime we need to display cart quantity and grand total on our website with the code below
we can easily display cart summary and cart grand total anywhere on site.

  $QtyCount = $this->helper('checkout/cart')->getSummaryCount(); 
  $CartTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
    echo $this->__('Items: %s',$QtyCount);
    echo $this->__(' Item: %s',$QtyCount);
    echo $this->__(' Items: %s',$count);
  echo $this->__(' Total: %s', $this->helper('core')->formatPrice($CartTotal, false));



Programmatically Unsubscribe Customer

Use the code given below to unsubscribe the email.

Page 1 of 1012345...10...Last »