Magento More View Image Switcher On MouseOver Product Page

Step1. open file on location given below
app/design/frontend/default/default/template/catalog/product/view/media.phtml

Step2. Search the code in media.phtml file
<a href=”#” onclick=”popWin(‘<?php echo $this->getGalleryUrl($_image) ?>’, ‘gallery’, ‘width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes’); return false;”>
<!–nested img tag stays the same–>
</a>

Step 3. Replace searched code with code below.
<a href=”<?php echo $this->helper(‘catalog/image’)->init($this->getProduct(), ‘image’, $_image->getFile()); ?>” title=”<?php echo $_product->getName();?>” onmouseover=”$(‘image’).src = this.href; return false;”>
<!–nested img tag stays the same–>
</a>

Advertisements

Magento Product and Category Related Functions

Magneto Product Collection

$collection = Mage::getModel(‘catalog/product’)->getCollection()->addAttributeToSelect(‘*’);

Get product of particular category

$products = Mage::getModel(‘catalog/category’)->load(category_id); //put your category id here
$productslist = $products->getProductCollection()->addAttributeToSelect(‘*’);

Product details from Product ID.

$productid=1234;
$model = Mage::getModel(‘catalog/product’) //getting product model
$_product = $model->load($productid); //getting product object for particular product id
echo $_product->getShortDescription(); //product’s short description
echo $_product->getDescription(); // product’s long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product’s regular Price
echo $_product->getSpecialPrice(); //product’s special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product’s image url
echo $_product->getSmallImageUrl(); //product’s small image url
echo $_product->getThumbnailUrl(); //product’s thumbnail image url

product collection from the category and then refine it down from there.

$products = Mage::getModel(‘catalog/category’)->load(410)
->getProductCollection()
->addAttributeToSelect(‘*’)
->addAttributeToFilter(‘status’, 1)
->addAttributeToFilter(‘visibility’, 4)
->addAttributeToFilter(‘special_price’, array(‘neq’ => “”))
->addAttributeToFilter(‘discontinued’, array(‘neq’ => 1))
->setOrder(‘price’, ‘ASC’);

Get Current product category id

$_helper = $this->helper(‘catalog/output’);
$_category_detail=Mage::registry(‘current_category’);
echo $_category_detail->getName(); //gives current category name
echo $_category_detail->getId(); //gives current category id

Display all categories in magento

function get_categories(){
$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$arr = array();
if ($ids){
foreach ($ids as $id){
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);
$arr[$id] = $cat->getName();
}
}
return $arr;
}
$arr = get_categories();
$arr = array_flip($arr);

Get Parent Category of current category

echo $cat_idd = $this->getCurrentCategory()->getParentCategory()->getId();

Get the category ID by product id

$productObj = Mage::getModel(‘catalog/product’)->load($product_id);
$categoryIds = $productObj->getCategoryIds();

To find the parent ID of current category

$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();

Get all categories for a product in Magento

$product = Mage::getModel(‘catalog/product’)->load($productId);
$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
$_cat = Mage::getModel(‘catalog/category’)->load($category_id) ;
echo $_cat->getName();
}

Frequently Used Magento Extensions

Magento EasyTabs Community Module
Description: Add tabs to the product page
Download link:
http://connect20.magentocommerce.com/community/magento_easy_tabs

Reduced checkout
Description: Skip Shipping Method or Skip Payment Method
Download link:
http://connect20.magentocommerce.com/community/Clearandfizzy_Reducedcheckout

Layered Navigation SEO
Description: Layered Navigation SEO: ajax, seo urls, price slider, multiple filters for the same attribute.
Download link:
http://connect20.magentocommerce.com/community/Catalin_Seo

Responsive Custom Menu
Description: Extension allows to customize top menu drop downs. Display all sub categories at once.
Download link:
http://connect20.magentocommerce.com/community/wp_custom_menu

Simple Order Export
Description: Exports selected orders to csv
Download link:
magento-community/SLandsbek_SimpleOrderExport

CCAvenue Payment Gateway Free
Description: Easily integrate your Magento store with the CC Avenue payment gateway.
Download link:
http://connect20.magentocommerce.com/community/Junaidbhura_Ccavenue

Manage Category, Customer and Customer Address Attributes
Description: You can easily manage custom attributes for category, cusomer and customer address attributes
Download link:
http://connect20.magentocommerce.com/community/Hwg_Attributemanager

Customer attributes manager
Description: A Customer Attributes Manager extension which can help developers manage attribute easily
Download link:
http://connect20.magentocommerce.com/community/offi_customer_attributes_manager

Optimise Web Mass 301 Redirects
Description: The Optimise Web Redirects extension helps set up bulk 301 redirects by uploading the URL data in a CSV file.
Download link:
http://connect20.magentocommerce.com/community/Optimiseweb_Redirects

Simple Admin Payment
Description: Simple payment method for orders that are created in Magento Admin.
Download link:
http://connect20.magentocommerce.com/community/Lemonline_SimpleAdminPayment

Color Swatches Free
Description: Free Color Swatches Magento Extension, Color Switcher
Download link:
http://connect20.magentocommerce.com/community/intell_colorswatch
http://connect20.magentocommerce.com/community/Gala_Colorswatches

Banner Slider by Magestore
Description: Display unlimited magento banners as a slider on top of Homepage or category. Upload links to detail pages.
Download link:
http://connect20.magentocommerce.com/community/Magestore_BannerSlider

CorlleteLab Imagezoom
Description: Image Zoom for product images. Configurable and Grouped products are also supported.
Download link:
http://connect20.magentocommerce.com/community/CorlleteLab_Imagezoom

Moo_CloudZoom
Description: This extension replaces the image gallery with the cloudZoom widget.
Download link:
http://connect20.magentocommerce.com/community/Moo_CloudZoom

WebRotate 360 Product Viewer with prettyPhoto Lightbox Image Gallery
Description: Integrate advanced 360 product views created with WebRotate 360 Product Viewer.
Download link: http://connect20.magentocommerce.com/community/WebRotate360_Catalog

KM Shippingcarriers
Description: Integrate Aramex, Bluedart and AFL carrier partners and track your shipment from Magento’s admin panel
Download link:
http://connect20.magentocommerce.com/community/KM_Shippingcarriers

Magento Set, Retrieve and Unset Session Variables

To set a Magento session variable:


$Insertid = 'Hello World';
Mage::getSingleton('core/session')->setInsertid($Insertid);

To Retrieve:


$Insertid = '';
$Insertid=Mage::getSingleton('core/session')->getInsertid();

To Unset:


Mage::getSingleton('core/session')->unsInsertid();

Note that Insertid can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.

Magento Frequently used fuctions

Magento Home URL
– Mage::getBaseUrl();

Magento Home Directory
– Mage::getBaseDir();

URL of a file in the skin directory
– $this->getSkinUrl(‘images/myfile.png’); // in a template or Block
– Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere

Format a price value
– Mage::helper(‘core’)->formatPrice($amount);

Get the display value of a (multi-)select product attribute
– echo $product->getAttributeText(‘manufacturer’);

Create an object instance in magento
– Mage::getModel(‘module/class’); // for models
– Mage::helper(‘module/class’); // for helpers
– Mage::app()->getLayout()->createBlock(‘module/class’, ‘name_in_layout’); // for blocks

GET/POST parameters
– Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
– Mage::app()->getRequest()->getParams(); // all parameters

Get the Id of the curent store view
– Mage::app()->getStore()->getId();

Get all Store Views
– Mage::app()->getStores(); // pass true to include the admin store view, too

Get the configurable/grouped/bundled product a simple product belongs to
– $simpleProduct->loadParentProductIds();
– $parentProductIds = $simpleProduct->getParentProductIds();

Get the simple products assigned to a configurable product
$configProduct->getTypeInstance()->getUsedProductCollection($configProduct);

Get an instance of an attribute
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode);

Magento: How to select, insert, update, and delete data?

Here, I will be showing how to select, insert/add, update/edit and delete data in the Magento way.

It’s about implementing the CRUD (Create Read Update Delete) concept. 🙂

Suppose, I have a database table named ‘news‘ with the following fields:-

id : int, auto increment, primary key
title : varchar
content : text
status : 0 or 1

Suppose, I have a module named ‘mynews‘. Here follows the code to select, insert, update, and delete data from the ‘news‘ table.

INSERT DATA

$data contains array of data to be inserted. The key of the array should be the database table’s field name and the value should be the value to be inserted.


$data = array('title'=>'hello there','content'=>'how are you? i am fine over here.','status'=>1);
 $model = Mage::getModel('mynews/mynews')->setData($data);
 try {
$insertId = $model->save()->getId();
echo "Data successfully inserted. Insert ID: ".$insertId;
 }

 catch (Exception $e){
echo $e->getMessage();
 }

SELECT DATA

$item->getData() prints array of data from ‘news’ table.
$item->getTitle() prints the only the title field.
Similarly, to print content, we need to write $item->getContent().


$model = Mage::getModel('mynews/mynews');
 $collection = $model->getCollection();
 foreach($collection as $item){
print_r($item->getData());
print_r($item->getTitle());
 }

UPDATE DATA

$id is the database table row id to be updated.
$data contains array of data to be updated. The key of the array should be the database table’s field name and the value should be the value to be updated.


// $id = $this->getRequest()->getParam('id');
 $id = 2;
 $data = array('title'=>'hello test','content'=>'test how are you?','status'=>0);
 $model = Mage::getModel('mynews/mynews')->load($id)->addData($data);
 try {
$model->setId($id)->save();
echo "Data updated successfully.";
 }

catch (Exception $e){
echo $e->getMessage();
 }

DELETE DATA

$id is the database table row id to be deleted.


// $id = $this->getRequest()->getParam('id');

$id = 3;
 $model = Mage::getModel('mynews/mynews');
 try {
$model->setId($id)->delete();
echo "Data deleted successfully.";
 }

catch (Exception $e){
echo $e->getMessage();
 }

In this way you can perform select, insert, update and delete in your custom module and in any magento code.

Magento get logged in customers name, email

if($customer = Mage::getSingleton(‘customer/session’)->isLoggedIn()) {
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
$customerData = Mage::getModel(‘customer/customer’)->load($customer->getId())->getData();
$email = $customer->getEmail();
$firstname = $customer->getFirstname();
$lastname= $customer->getLastname();
// print_r($customerData);
}