Magento Get most popular products in a category or outside

Tags

Image representing Magento as depicted in Crun...

Image via CrunchBase

I have just added new function to my tgeneral extension which lets you get most popular products based on:

  • most viewed products
  • most ordered products by qty
  • most ordered products by number of orders

You can also set filter on top of them as:

  • current category
  • any defined category
  • filter by any attribute

And, bonus, you can get products from certain time range as well.

e.g. for last 7 days from current time.

$today = time();
$last = $today - (60*60*24*7);
$from = date("Y-m-d", $last);
$to = date("Y-m-d", $today);

This is how you will use this:

$_tcatalog = Mage::helper('tgeneral/catalog');
$_tcatalog->setFrom($from);
$_tcatalog->setFrom($to);

use:

$_tcatalog->getPopularProducts();

or

$_tcatalog->getPopularProducts('order.qty');

or

$_tcatalog->getPopularProducts('order.count');

To download or fork free magento extension/module head over to tgeneral extension on github.

Display full breadcrumb path in magento

Tags

,

Magento doesn’t always include category path in it’s breadcrumb. It shows only home/magento-store-product-name.html but we need full breadcrumb path in magento like this: home/magento-category-path/magento-store-product-name.html

To achieve this we need to override magento breadcrumbs block like this: http://t.co/j5q0aZtrbH

Read other magento tips on technooze.com or magentoanswers.

Magento update order status programmatically

Tags

,

Today I needed to update magento’s order (status,comment) programattically. So this is what rescued me.

$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$state = 'new';
$status = 'order_status';
$comment = 'Please find the shipping tracking code below:';
$isCustomerNotified = true;
$order->setState($state, $status, $comment, $isCustomerNotified);
$order->save();
$order->sendOrderUpdateEmail(true, $comment);

some helpful codes:

NOTE:: Magento doesn’t allow setState for complete and closed, so we are bypassing that check


/**
* change order status to 'Complete'
*/
$state = Mage_Sales_Model_Order::STATE_COMPLETE;
$order->setData('state', $state);

/**
* change order status to 'Closed'
*/
$state = Mage_Sales_Model_Order::STATE_CLOSED;
$order->setData('state', $state);

Don’t forget to save your order


$order->setStatus($order->getConfig()->getStateDefaultStatus($state));

$history = $order->addStatusHistoryComment($comment, false); // no sense to set $status again
$history->setIsCustomerNotified(true); // for backwards compatibility

$order->sendOrderUpdateEmail(true, $comment);

$order->save();

Other states:


/**
* change order status to 'Pending'
*/
$order->setState(Mage_Sales_Model_Order::STATE_NEW, true)->save();

/**
* change order status to 'Pending Paypal'
*/
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();

/**
* change order status to 'Processing'
*/
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();

/**
* change order status to 'Completed'
*/
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();

/**
* change order status to 'Canceled'
*/
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();

/**
* change order status to 'Holded'
*/
$order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();

/*
 * Cancel an order
 */
if($order->canCancel()) {
$order->cancel()->save();
}

/*
 * Hold an order
 */
if($order->canHold()) {
$order->hold()->save();
}

/*
 * Unhold an order
 */
if($order->canUnhold()) {
$order->unhold()->save();
}

Magento – get current path in magento

Tags

,

It is absolutely easy to get current url in magento which you can achieve with this just one line:

<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
?>

But if you are looking for more option about the current page or url or current url path then read more here: Magento - Get Current Url path in Magento http://learntipsandtricks.com/blog/magento/52/How-to-get-current-URL-in-Magento

Cheers from Magento Answers!!!

Magento – get current url key in magento

Tags

, ,

It’s quite easy to get current url in magento. You can use this one line:

<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
?>

But if you are looking for more option about the current page or url then read more here: Magento - Get Current Url key in Magento http://learntipsandtricks.com/blog/magento/52/How-to-get-current-URL-in-Magento

Happy Magento!!!

Follow

Get every new post delivered to your Inbox.