Pages

Tuesday, September 10, 2013

How to add categories to product by product sku programmatically in Magento

<?php

$rootDir = ""; //root path
include($rootDir."app/Mage.php");
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::app("default");
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

// $productsSkus is an array of the products you want to modify.
// Create it however you want, I did it like this...
$productsSkus = array('100246','800649','017261','006403');

//update product categories
for($i=0;$i<count($productsSkus);$i++)
{
$productModel = Mage::getModel('catalog/product');
$productId = $productModel->getIdBySku($productsSkus[$i]);
$product = $productModel->load($productId);
$categoryArr = $product->getCategoryIds();
// Array of category_ids to add.
$categoryArr[] = 842;
$product->setCategoryIds(array($categoryArr));
$product->save();

}
?>
Hope you will enjoy!

Thursday, September 5, 2013

How to get customer name, customer email on success.phtml/order confirmation page in Magento

<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
if($order->getCustomerId() === NULL)
{
$customerName  = $order->getBillingAddress()->getName();
$customerEmail = $order->getBillingAddress()->getEmail();
}
else
{
$customer      = Mage::getModel('customer/customer')->load($order->getCustomerId());
$customerName  = $order->getCustomerName();
$customerEmail = $order->getCustomerEmail();
}
?>

Wednesday, September 4, 2013

How to get total quantity of product sold in Magento

<?php
$id = 100001; // Enter your product ID here
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToFilter('id', $id)
    ->setOrder('ordered_qty', 'DESC')
    ->getFirstItem();
$product = $_productCollection;
echo 'Total Sold'.$product->ordered_qty;
?>

Sunday, September 1, 2013

How to disable Google Checkout button in Magento

Use the following steps to disable google checkout button from cart page as given below:

Login into Admin first then

Steps 1: Go to System->Configuration

Steps 2: Click on "Gopple API" under "Sales Tab" from left side.

Steps 3: Click on "Google Checkout" and select Enable "No".

Steps 4: Click on "Save Config" button at the top.