Thursday 25 April 2013

Magento Most popular products for each category


<?php $get_cat = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();

$category = Mage::getModel('catalog/category')->load($get_cat);
$products = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty() //total number of quantities ordered
    ->addAttributeToSelect('*') //get all attributes
    ->setOrder('ordered_qty', 'desc') //most ordered quantity products first
    ->addCategoryFilter($category);

foreach ($products as $prod){

 if($prod->getIsActive()){
echo $this->htmlEscape($prod->getName());
echo "<br>";
 }

}

?>

Thursday 18 April 2013

Magento Introduction and advantages


Magento
  Magento was first launched on March 31, 2008. It was developed by Varien (now Magento Inc) with help from the programmers within the open source community but is owned solely by Magento Inc.. Magento was built using the Zend Framework.It uses the entity-attribute-value (EAV) database model to store data. It should seprated into three types (Magento Enterprise Edition , Magento Community Edition , Magento Professional Edition),Mainly all magento users used MEE and MCE
Magento Enterprise Vs Community
There are currently two editions of Magento available, Magento Enterprise Edition and Magento Community Edition. Both editions of Magento are valuable, however, they are meant for different audiences. You might have questions about what the two editions are, why both editions need to exist and what the differences between them are. This FAQ will help you get answers to these questions and set you on the right path for eCommerce success.

Magento Enterprise Edition :
MEE is the complete eCommerce solution for businesses that are ready to take full advantage of their online channel. This solution combines an unrivaled feature set with world-class support and virtually infinite flexibility, at a fraction of the price charged by competitive platforms.for MEE Magento provide technical support.

Magento Community Edition :
Development of the MCE continues at a rapid pace through this model, providing a basic and powerful solution for small shops looking for a state-of-the-art eCommerce platform.Magento Community Edition is open source software and can be downloaded for free.
Developers can modify the core code and add features and functionality by installing extensions from the Magento Connect marketplace. MCE to run their stores will want to have access to their own Magento experts, since Magento does not provide technical support for this software.
MCE is a feature-rich, professional open-source eCommerce solution that offers merchants complete flexibility and control over the look, content, and functionality of their online store. Magento’s powerful marketing, search engine optimization and catalog-management tools give merchants the power to create ecommerce sites that are tailored to their unique business needs.
Current Version
Magento Enterprise Edition
Magento Communtity Edition
1. Latest Magento Enterprise is 1.12.0.2
1.Latest Magento Communti 1.7.0.2

Upcoming Version
Magento Enterprise Edition
Magento Communtity Edition
1. Latest Magento Enterprise is 1.13
1.Latest Magento Communti 1.8

Latest Version Advantages :
MEE 1.12.0.2 :
  • HTM5
  • Visitors segment
  • Expandable rule-based product-relations
  • Speedier checkout flow
  • Autogenerated of coupon codes
  • Multiple Wishlist
  • Layered Navigation price Enchnacement
  • Customer Group pricing
  • Add to cart by SKU
  • CMS page hierarachy Enchancements
  • Functional Improvements
  • Backup and Rollback
  • Payment Bridge updates
  • Capthca
Additional Modules :
There are some interesting additional modules in the Enterprise Edition:
  • Private sales, which allows retailers to restrict access to stores and offers to selected customers, and to manage the launch and termination of private sales.
  • Access to the back-end can be controlled at the website or store level, where in the Community Edition you can only restrict access at the function / module level. This is very useful for multi-store Magento installations.
  • The ability to merge and combine content from one store with another, and to use this facility to create a content staging environment. Instead of having 2 instances of Magento (as we do with some clients at present) one for the next catalog, one for the current catalog, you could do all this in one installation, which is a very interesting development, especially for larger retailers. A full audit trail of all admin actions. Very useful.
  • Gift card and store card functionality which allows electronic gift cards to be sold and used on Magento stores.
  • Store credit functions, for example allowing a contact centre to make an ex gratia payment to a shopper in the event of a complaint.
  • Enhanced security in line with PCI recommendations, with things like password expiry for administrators.
MCE 1.7.0.2
  • HTML 5
  • PHP-FPM for PHP management
  • APC for PHP caching
  • Autogenerated of coupon codes
  • Layered Navigation price Enchnacement
  • Customer Group pricing
  • AjaXplorer for file server management
  • Reset API's support
  • European union VAT-ID validation
  • Built on Amazon Linux (CentOS) for security
  • Capthca
  • Backup and Rollback

Improvements MCE

  • Added the functionality for creating nested field sets in the System configuration
  • Implemented the support for the extended and shared configuration fields
  • Added the ability to define dependencies between fields from different field sets

Changes

  • Moved PayPal configuration to the Payment Methods menu
  • Set the default value of the cUrl VERIFYPEER option to TRUE for PayPal and added the ability to change this value
  • Changed the design and position of the configuration field tooltips

Fixes

  • Fixed: Inability of SOAP v2 API use in non WS-I compatible mode in the applications written in languages with strong typing
  • Fixed: In some cases comments history tab on order does not contain information about customer notifications
  • Fixed: Several potential security vulnerabilities





Wednesday 17 April 2013

Import Products Programmatically

 Import Products Programmatically ,Get Products image from external URL , Update if product SKU id exists and redirect to particular page



<?php
$product = $_REQUEST;
include_once("app/Mage.php");
Mage::app();

       $newproduct = Mage::getModel('catalog/product');
       $sku = $product['product'];
       $quant = $product['available'];
       $productId = Mage::getModel('catalog/product')->getCollection();
    $skuid = array();
        foreach ($productId as $check) {
           $i = $i+1;
    $skuid[] = $check->getSku();
        }  
        if (!in_array($sku,$skuid)) {
        $newproduct->setSku($product['product']);
       
        $newproduct->setTypeId('simple');
        $newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
        $newproduct->setStatus(1);
        $newproduct->setWeight($product['weight']);
        $newproduct->setTaxClassId(0);
        $newproduct->setWebsiteIDs(array(1));
        $newproduct->setStoreIDs(array(1));
        $newproduct->setStockData(array(
            'is_in_stock' => 1,
            'qty' =>$quant ,
            'manage_stock' => 1
        ));
      
        $newproduct->setAttributeSetId(4);
        $newproduct->setName($product['product']);
        $newproduct->setCategoryIds(array(2,3)); // array of categories it will relate to
        $newproduct->setDescription($product['productText']);
        $newproduct->setShortDescription($product['productText']);
        $newproduct->setBrand($product['brand']);
        $newproduct->setBrandtext($product['brandText']);
        $newproduct->setList($product['list']);
        $newproduct->setPrice($product['price']);
        $newproduct->setCat($product['category']);
        $newproduct->setCategorytext($product['categoryText']);
        $newproduct->setYear($product['year']);
        $newproduct->setMake($product['make']);
        $newproduct->setModel($product['model']);
        $newproduct->setCore($product['core']);
        $newproduct->setShips($product['ships']);
        $newproduct->setApplication($product['application']);
        $newproduct->setCatalogproduct($product['catalogProduct']);
        $newproduct->setPartnersession($product['partnerSession']);
   
        $from = $product['imageurl'] ;
        $prod = $product['imageurl'];
        $prod1 = explode("/",$prod);
        $prod2 = end($prod1);
        $to = "/home/domains/spd1/media/import/".$prod2 ;
        copy($from,$to);
        $fullImagePath = "/home/domains/spd1/media/import/".$prod2;
        $visibility = array (
           'thumbnail',
           'small_image',
           'image'
        );
        $newproduct->addImageToMediaGallery( $fullImagePath, $visibility, true, false);

    } else {
   
        $newproduct1 = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
        $newproduct1->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
        $newproduct1->setStatus(1);
        $newproduct1->setWeight($product['weight']);
        $newproduct1->setTaxClassId(0);
        $newproduct1->setAttributeSetId(4);
        $newproduct1->setName($product['product']);
        $newproduct1->setCategoryIds(array(2,3)); // array of categories it will relate to
        $newproduct1->setDescription($product['productText']);
        $newproduct1->setShortDescription($product['productText']);
        $newproduct1->setBrand($product['brand']);
        $newproduct1->setBrandtext($product['brandText']);
        $newproduct1->setList($product['list']);
        $newproduct1->setPrice($product['price']);
        $newproduct1->setCat($product['category']);
        $newproduct1->setCategorytext($product['categoryText']);
        $newproduct1->setYear($product['year']);
        $newproduct1->setMake($product['make']);
        $newproduct1->setModel($product['model']);
        $newproduct1->setCore($product['core']);
        $newproduct1->setShips($product['ships']);
        $newproduct1->setApplication($product['application']);
        $newproduct1->setCatalogproduct($product['catalogProduct']);
        $newproduct1->setPartnersession($product['partnerSession']);
   
            try {
                if (is_array($errors = $newproduct1->validate())) {
                    $strErrors = array();
                    foreach($errors as $code=>$error) {
                    $strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
                    }
                    $this->_fault('data_invalid', implode("\n", $strErrors));
                }

                $newproduct1->save();
                } catch (Mage_Core_Exception $e) {
                $this->_fault('data_invalid', $e->getMessage());
                } 
    }

    try {
        if (is_array($errors = $newproduct->validate())) {
            $strErrors = array();
            foreach($errors as $code=>$error) {
                $strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
            }
            $this->_fault('data_invalid', implode("\n", $strErrors));
        }

        $newproduct->save();
    } catch (Mage_Core_Exception $e) {
        $this->_fault('data_invalid', $e->getMessage());
    }
   
   
echo $extra = strtolower($product['product']);
 
header("Location: redirect path");

?>